Hide Ajax chat link

<?php

function bigm_chat_switch(){
global $bp;
$the_component_name = $bp->current_component;
$the_action_name = $bp->current_action;
if($the_component_name != 'groups' && bp_displayed_user_id() != get_current_user_id()){
?>
<style>
<!--
#user-chat {display:none;}
-->
</style>
<?php
}
if($the_action_name == 'my-groups'){
?>
<style>
<!--
#user-chat {display:none;}
-->
</style>
<?php
}
}
add_action('bp_after_footer','bigm_chat_switch');
?>

Get User Roles In WordPress

$user = get_userdata( $user->ID );
$capabilities = $user->{$wpdb->prefix . 'capabilities'};

if ( !isset( $wp_roles ) )
$wp_roles = new WP_Roles();

foreach ( $wp_roles->role_names as $role => $name ) {

if ( array_key_exists( $role, $capabilities ) )
echo $role;
}

daysBetweenDates

<?php

/**
* Calculates the diference in days between two dates.
*
* @param string $start_date Start date (format yyyy-mm-dd)
* @param string $end_date End date (format yyyy-mm-dd)
* @param boolean $include_end_date Include end date in calculation (1 day is added)
*
* @return integer Number of days.
* */
function daysBetweenDates($start_date, $end_date, $include_end_date = false) {

// Timestamp for start date
list($s_year, $s_month, $s_day) = explode("-", $start_date);
$start_date_timestamp = mktime(0, 0, 0, $s_month, $s_day, $s_year);

// Timestamp for end date
list($e_year, $e_month, $e_day) = explode("-", $end_date);
$end_date_timestamp = mktime(0, 0, 0, $e_month, $e_day, $e_year);

// Diference between dates
$diff = ($end_date_timestamp - $start_date_timestamp);
$days = floor($diff / (60 * 60 * 24));

if ($include_end_date)
$days++;

return $days;
}

?>

Swf embed shortcut function

<?php

//Here is a link to all params: http://kb2.adobe.com/cps/127/tn_12701.html
function dev_embed_swf($args = '') {
$defaults = array(
'url' => 'not set',
'width' => '550',
'height' => '440',
'wmode' => 'opaque',
'bgcolor' => '#000000',
'play' => 'true',
'loop' => 'false'
);
$r = wp_parse_args($args,$defaults);
extract($r);
?>
<div id="<?php echo str_replace('.','_',basename($url)) ?>" class="dev_embed_swf">
<object type="application/x-shockwave-flash" data="<?php echo $url ?>" width="<?php echo $width ?>" height="<?php echo $height ?>">
<param name="quality" value="high" />
<param name="wmode" value="<?php echo $wmode ?>" />
<param name="bgcolor" value="<?php echo $bgcolor ?>" />
<param name="play" value="<?php echo $play ?>" />
<param name="loop" value="<?php echo $loop ?>" />
<param name="swfversion" value="6.0.65.0" />
<param name="expressinstall" value="/Scripts/expressInstall.swf" />
<param name="movie" value="<?php echo $url ?>" />
</object>
</div>
<?php
}
?>

Function argument arrays

<?php

//The function for your functions.php or plugin

function test_function($args = '') {
$defaults = array(
'arg1' => 'Default Value 1',
'arg2' => 'Default Value 2',
'arg3' => 'Default Value 3',
);

$r = wp_parse_args($args,$defaults);
extract($r);

echo "arg1 = $arg1<br>";
echo "arg2 = $arg2<br>";
echo "arg3 = $arg3<br>";
}

//Call the function using two techniques:

//1 - Using an array

$args = array(
'arg1' => 'Array Value 1',
'arg2' => 'Array Value 2',
'arg3' => 'Array Value 3',
);
test_function($args);

//2 - Using a query string

test_function('arg1=Query Value 1&arg2=Query Value 1&arg3=Query Value 3');

Change meta on all posts

<?php query_posts('showposts=-1'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<?php

$custom_field_name = 'Sort Order';
$desired_field_value = '100';

add_post_meta($post->ID,$custom_field_name,$desired_field_value,true);
the_title();
echo ' - ' . get_post_meta($post->ID,$custom_field_name,true);
echo'<br>';

?>
<?php endwhile; endif; ?>

Default meta - Custom field

<?php

//Set Default Meta Value
function set_default_meta($post_ID){
$current_field_value = get_post_meta($post_ID,'Sort Order',true);
$default_meta = '100';

if ($current_field_value == '' && !wp_is_post_revision($post_ID)){
add_post_meta($post_ID,'Sort Order',$default_meta,true);
}
return $post_ID;
}

add_action('wp_insert_post','set_default_meta');

?>

Style admin bar dropdown

#wp-admin-bar ul.main-nav li:hover,#wp-admin-bar ul.main-nav ul li {background-color:#666!important;}
#wp-admin-bar ul li ul { border:1px solid #666!important;}