Restart the Mac VPN Service via Command Line

If your VPN connection is ever disrupted and you cannot reconnect, don’t restart your computer. Open up a shell window and use the following commands to stop/start the native VPN service.

sudo launchctl stop com.apple.racoon
sudo launchctl start com.apple.racoon 

WordPress enforces CamelCase

As of WordPress 3.0, you cannot type WordPress incorrectly in your titles or content. A patch was introduced to filter out any bad formatting of the WordPress name and replace it with the proper CamelCase format. Notice the following screenshot of my content area which includes several mis-formattings of WordPress that are formatted automatically.

So, patch author, Matt Mullenweg, wants to set the record straight that WordPress is spelled with a capital P. I guess the motivation of this is for brand integrity, however, this has caused quite a ruckus among the orthodox GPL folks. We won’t go into that on this post. If you wish to continue misspelling WordPress, you can add this to your functions file.

remove_filter('the_content', 'capital_P_dangit', 12);
remove_filter('the_title', 'capital_P_dangit', 12);
remove_filter('comment_text', 'capital_P_dangit', 12);

PHP – Passing data between classes

Static class properties are the most efficient way to pass information from one class to another. Typically, one would place a variable in the global scope for other functions and classes to use. However, this is not a good practice as setting GLOBALS equates to a downgrade in performance. Using static properties allows you to store/retrieve data without instantiating a class object.

class IntermediaryData{
    public static $global = null;

    public function set($data){	
        return self::$global = $data;
    }
	
    public function get(){
        return self::$global;
    }
}

Use this in your classes to set and retrieve data:

IntermediaryData::get();
IntermediaryData::set($data);

A good use case for this functionality is passing a rolling list of ids to exclude from queries from widget to widget within a dynamic WordPress sidebar.

Find a widget’s current sidebar context

I recently was programming a widget for WordPress that needed to communicate with another widget if it was at a lower priority in the same sidebar. I came up with these nifty little functions to find the current context and sibling widgets of the current widget. You can add this to your functions.php.

function get_current_sidebar($widget_id) {

    $active_sidebars = wp_get_sidebars_widgets();
    $current_sidebar = false;
    
    foreach($active_sidebars as $key => $sidebar)
        if(array_search($widget_id, $sidebar))
            $current_sidebar = $key;    
    
    return $current_sidebar;
}

function get_current_sidebar_widgets($sidebar_id){

    $active_sidebars = wp_get_sidebars_widgets();
    $current_sidebar_widgets = $active_sidebars[$sidebar_id];

    return $current_sidebar_widgets;
}

Add this method to your widget object:

protected function has_widget_siblings(){

    $widget_id = $this->id_base.'-'.$this->number;
    $current_sidebar = get_current_sidebar($widget_id);
    $current_sidebar_widgets = get_current_sidebar_widgets($current_sidebar);
    
    $current_widget_identified = false;
    $current_widget_siblings = false;
    
    foreach($current_sidebar_widgets as $key => $widget){
        if(preg_match("/{$widget_id}/", $widget)){
            $current_widget_identified = true;
        }
        elseif(preg_match("/{$this->id_base}/", $widget)){
            if($current_widget_identified)
                $current_widget_siblings = true;
                return $current_widget_siblings;
        }
    }
}

Read my post about passing data between classes to have your widget communicate with a sibling widget.

Bodacious File & Directory Utility for Web Projects

I found this great little app called Structurer Pro on Code Canyon and I use it all the time. It helps me quickly create deep file structures in batches. I can also save these batches as templates for use with other projects. It’s not rocket science, and it’s certainly not complex, but it’s powerfully useful.

For a small investment of $7.00 you can increase your productivity ten-fold when building the architecture of your next project.

Get your own copy of Structurer Pro

If you’re using a PC, check out this product – Blueprinter

The beginning of all understanding is classification



Understanding a problem is the foundation of programming. Classification is the logical, yet, overlooked starting point of most projects. Many times, I find that my inefficiency and lack of productivity stems from a low morale or fatigue. This is typically birthed by a deficiency of direction and understanding of how to accomplish a task.

When I find myself in a vacuum of zero productivity, I typically break down problems and tasks in an outline program. I focus on creating small, realistic tasks in a logical progression that won’t overwhelm my psyche. I recently discovered WorkFlowy. It’s a simple way to systematize thoughts, ideas, contingencies, projected anomalies, scenarios, etc. in a searchable, navigable outline form.

When you starting seeing your coworkers as binary entities, just do something to get back to firing on all cylinders. A good place to start is classify and reclassify, then classify again until you get it right. If classification is the beginning of understanding, iteration of classification is certainly a close second.

Author: Hayden White

WordPress – Search only posts or pages

One annoyance I have with WordPress default searching is that it searches everything and gives no context to the search results. At times you may want to search specifically for pages in a corporate site and other times in the context of a blog, search specifically for posts.

It’s simple to accomplish this by adding a hidden input field in your form tag.

<?php if(is_page()):?>
    <input type="hidden" name="post_type" value="page" />
<?php elseif(is_archive()):?>
    <input type="hidden" name="post_type" value="post" />
<?php endif;?>

You can also use radio buttons to allow your users to decide what results are returned:

<form method="get" action="<?php echo home_url();?>">
    <input type="text" name="s" />
    <label>Search Pages</label>
    <input type="radio" name="post_type" value="page" />
    <label>Search Posts</label>
    <input type="radio" name="post_type" value="post" />
    <button type="submit">Submit</button>
</form>

This works dandy. See my post on Stack Exchange about this topic.

Re-order WordPress Admin Sub-menu Items

If you’re wanting to push your custom sub-menu link to the top of the list within a WordPress menu, you can use this code to ensure that you’re always the alpha sub-menu item.

function custom_menu_order(){
    global $submenu;
	  
    $find_page = 'themes.php';
    $find_sub = 'Widgets';
    
    foreach($submenu as $page => $items):
        if($page == $find_page):
            foreach($items as $id => $meta):
                if($meta[0] == $find_sub):
                    $submenu[$find_page][0] = $meta;
                    unset ($submenu[$find_page][$id]);
                    ksort($submenu[$find_page]);
                endif;
            endforeach;
        endif;
    endforeach;
}
add_action('_admin_menu', 'custom_menu_order');

View the SE thread where I originally posted this.