+91-40 – 420 001 24 info@dhrusya.com

WordPress Hacks

Here are few wordpres hacks that are very usefull while developing wordpress plugins and themes.

Hide wordpress adminbar

add_action('init', 'remove_admin_bar');
function remove_admin_bar() {
if ( !current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}

Show user/author posts only in admin

By default wordpress displays all posts for any user logged into wp-admin. The following code restricts the post list by displaying only his posts.

function wps_get_post_list_by_user($clauses) {
if (is_admin()) {
global $user_ID, $wpdb;
// $clauses['join'] = ", wp_posts";

$clauses['where'] .= " AND wp_posts.post_author = ".$user_ID;

};
return $clauses;
};
if ( !current_user_can( 'edit_users' ) ) {
add_filter('posts_clauses', 'wps_get_post_list_by_user');
}

Remove unwanted admin menus

function remove_admin_menu_items() {
$remove_menu_items = array(__('Links'), __('Dashboard'),  __('Media'), __('Links'), __('Appearance'), __('Tools'),  __('Settings'), __('Comments'), );
global $menu;
end ($menu);
while (prev($menu)){
$item = explode(' ',$menu[key($menu)][0]);
if(in_array($item[0] != NULL?$item[0]:"" , $remove_menu_items)){
unset($menu[key($menu)]);}
}
}

if(get_logged_user_role()!="administrator"){
add_action('admin_menu', 'remove_admin_menu_items');
}

Set Post Expert Length

function custom_excerpt_length( $length ) {
	return 100;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

Hide Plugin Update Notifications

just copy and paste that code in the .php file of the plugin

add_filter('site_transient_update_plugins', 'dd_remove_update_nag');
function dd_remove_update_nag($value) {
 unset($value->response[ plugin_basename(__FILE__) ]);
 return $value;
}