Hooking into WordPress Business Directory

Standard

Today I was working on a site that uses the WordPress Business Directory Plugin (WPBDP). I needed to link a phone number field for mobile devices but couldn’t find anything useful in the plugin’s documentation… so I did what I always do and dug through the plugin source.

I found several useful WP hooks, and was able to write a quick function to do what I wanted. The code below goes into a theme’s functions.php file or a simple plugin.

add_filter('wpbdp_form_field_html_value', 'alter_wpbdp_form_field_html_value', 10, 3);
function alter_wpbdp_form_field_html_value($value, $post_id, $class)
{
    // add tel: to phone numbers
    if($class->get_id() == 6) // the ID of the field to modify
    {
        $value = '<a href="tel:'.preg_replace('/[^0-9]/', '', $value).'">'.$value.'</a>';
    }

    return $value;
}

This assumes that the ID of the phone field is 6. The field’s ID can be found by editing the field and looking for the ID in the URL.

Screen Shot 2014-12-08 at 3.43.50 PM

PowerShell Script to Swap Halo’s Map Folder

Standard

Recently, Bungie patched Halo: Combat Evolved because it used GameSpy to generate the multiplayer server list, and GameSpy is shutting down.

I was inspired to re-install Halo and set up the old mods I used to play. My favorite was called “Snipers Dream Team Mod,” a mod in which snipers shoot tank shells… along with some other goodies.

Back when I played, enabling/disabling mods was fairly crude: you had to have a copy of every map that you would manually swap between.

I wanted to automate the process of swapping the map folders, so wrote the following PowerShell script. Coincidentally, it’s also my first ever script. I’m sure there are better ways to do it.

The script assumes that you have your default maps folder named “Maps” and your folder with SDTM mods named “Maps-SDTM.”

$root = "C:\Program Files (x86)\Microsoft Games\Halo"

# if sdtm is prefixed, install them
if(Test-Path("$root\Maps-SDTM"))
{
    Move-Item "$root\Maps" "$root\Maps-Default"
    Move-Item "$root\Maps-SDTM" "$root\Maps"
    [System.Windows.Forms.MessageBox]::Show("SDTM Maps Activated")
}
# otherwise install the default
else
{
    Move-Item "$root\Maps" "$root\Maps-SDTM"
    Move-Item "$root\Maps-Default" "$root\Maps"
    [System.Windows.Forms.MessageBox]::Show("Default Maps Activated")
}