VC WordPress Theming

I’ve been developing with WordPress for about 2.5 yrs and this morning I really wanted to write something about all the work that I do, but am realizing that I just don’t know what to say with out writing a freaking book on the DevTime of WordPress. Not to mention there are so many people out there who have already laid down the law on what WordPress is.

So to curb my need to publish I though I would share a WP function that I have found to be a huge time saver, and something WP uses a lot. As you’ll see below it’s not much to speak of and it’s fairly basic in the scheme of things, but it will save a lot of time when comparing incoming variables with default variables.

wp_parse_args()

You can find this in wp-includes/functions.php -> line 2887 wp3.0 beta1


/**
* Merge user defined arguments into defaults array.
*
* This function is used throughout WordPress to allow for both string or array
* to be merged into another array.
*
* @since 2.2.0
*
* @param string|array $args Value to merge with $defaults
* @param array $defaults Array that serves as the defaults.
* @return array Merged user defined values with defaults.
*/
function wp_parse_args( $args, $defaults = '' ) {
if ( is_object( $args ) )
$r = get_object_vars( $args );
elseif ( is_array( $args ) )
$r =& $args;
else
wp_parse_str( $args, $r );

if ( is_array( $defaults ) )
return array_merge( $defaults, $r );
return $r;
}

Here is an example being used in the form function of a widget class, which is a great place to set defaults variables.


function form( $instance ) {

$widget_options = get_option('_my_widget_options');

//Defaults
$defaults = array(
'title_display' => 'Text',
'text_title' => '',
'image_title' => '',
'link' => '',
'post_cat' => $widget_options['post_cat'],
'post_count' => $widget_options['post_count'],
'word_count' => $widget_options['word_count'],
'read_more' => $widget_options['read_more'],
'strip_tags' => $widget_options['strip_tags'],
'show_thumbnail' => '',
'show_video' => '',
'css_class' => ''
);

$r = wp_parse_args( $instance, $defaults );
extract( $r, EXTR_SKIP );

echo 'do cool stuff here...';
}

So yeah, really exciting stuff right? Maybe not, but hey if you’re into php & WordPress you should check this out for sure. It’s been around for while so there is really no excuse.

My Recent Work

I’ve been on the keyboard for the last 3.5 months and it’s been quite a crazy time. So far 2010 has been more busy then I ever expected. My recent work has been expanding my theme by leaps and bounds. It’s odd that every site I build kills all the previous ones. (it’s almost time to update my site, I just wish I had some time :)

There is a lot to go over so I’ll just list off the latest projects. (Most of these are Skörinc, but one or two came from BuzzPlant)

“R” is for Randy & “S” is for Sarah

Sarah and I have been chipping away at the wedding planning!!! We even tried to have a Wedding Shower, but sure enough the day we set for the shower Nashville decided to let the clouds snow on it more than it has in over decade :) (stupid clouds)

We are still on the hunt for a good Jazz Band, and we are still on the hunt for some warm weather too… If anyone here in Music City has any suggestions let us know :)

[clear]
R is for Randy S is for Sarah