Tuesday, 25 December 2012

Hiding unnecessary menus in wordpress admin


In this post, I describe a technique for hiding unnecessary menus. 



Some time we need to hind unnecessary menus for other clients role just like (administrator, contributor, subscriber, author, editor, etc) then with the help of this function we can hide wordpress menu.
1.    
1   This code include your themes>>functions.php files.

// remove unnecessary menus
function remove_admin_menus () {
                global $menu;
                                $restrict = explode(',', 'contributor');// you can pass user role (administrator, contributor, subscriber, author, editor, etc)
                $restrict_user = explode(',', 'Posts,Comments,Media,Profile,Appearance,Plugins,Users, Tools,Settings');// you can pass menus name whose you want to hide.
               
                $f = create_function('$v,$i', 'return __($v);');
                array_walk($restrict, $f);
                if (!current_user_can('activate_plugins')) {
                                array_walk($restrict_user, $f);
                                $restrict = array_merge($restrict, $restrict_user);
                }
                // remove menus
                end($menu);
                while (prev($menu)) {
                                $k = key($menu);
                                $v = explode(' ', $menu[$k][0]);
                                if(in_array(is_null($v[0]) ? '' : $v[0] , $restrict)) unset($menu[$k]);
                }
}
add_action('admin_menu', 'remove_admin_menus');

Thursday, 13 December 2012

How to remove last character of a string(mysql Query fields)?




SELECT Concat( mid( fieldname, 1, length(fieldname) -1 )
 , REPLACE( mid(fieldname, length(fieldname) ) , ',', "" ) )
 as fieldname FROM tablename
 
OR

Select id, REPLACE(fieldname,',','') from tablename 
where fieldname REGEXP '(.*),' limit 5;

update last character from string mysql

UPDATE tablename SET fieldname = Concat( mid(fieldname,
 1, length(fieldname) -1 ) , REPLACE( mid(fieldname, 
length(fieldname) ) , ',', "" ) )