Programmatically changing role information; editing role name and deleting

There’s a whole host of functions specifically for this purpose; http://codex.wordpress.org/Function_Reference#User_and_Author_Functions Of particular interest (but not limited to) are, add_cap add_role get_role map_meta_cap remove_cap remove_role As well as numerous other user related functions that will allow you to verify/validate their authority based upon your use-case scenario and so on. Looking in wp-includes/capabilities.php you we can … Read more

Remove admin AND editor from the “change role to” menu in user listing

Try using below code to remove administrator and editor option from drop down. Use editable_roles filter function wdm_user_role_dropdown($all_roles) { global $pagenow; if( current_user_can(‘editor’) && $pagenow == ‘user-edit.php’ ) { // if current user is editor AND current page is edit user page unset($all_roles[‘administrator’]); unset($all_roles[‘editor’]); } return $all_roles; } add_filter(‘editable_roles’,’wdm_user_role_dropdown’);

How to filter the role selector?

The UI select element On user-edit.php, you see the drop-down in the UI. The drop down <select> wrapper is hard coded. Then the admin interface does a nifty thing 1) according to the inline comment: // Get the highest/primary role for this user. In fact it is getting the first role, that was assigned to … Read more

Get user role by using user_id in buddypress

Try this function: function get_user_role($user_id){ global $wpdb; $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 ) ) { return $role; } } return false; } I’ve not included … Read more

Temporarily disable user role login and replace with message

With a some digging and learning, I managed to combine various help and create these 2 functions… // MAINTAINANCE MODE function site_maintenance() { if ( current_user_can(‘media’) || current_user_can(‘genpo’) ) { $logout_url = wp_login_url().’?mode=maintainance’; wp_logout(); wp_redirect( $logout_url, 302 ); } } add_action(‘get_header’, ‘site_maintenance’); // CUSTOM LOGIN MESSAGES function my_login_message() { if( $_GET[‘mode’] == ‘maintainance’ ){ $message=”<p … Read more

Allow editors access to added plugins

Please add the following code. function activate_plugin_name() { $role = get_role( ‘editor’ ); $role->add_cap( ‘manage_options’ ); // capability } // Register our activation hook register_activation_hook( __FILE__, ‘activate_plugin_name’ ); function deactivate_plugin_name() { $role = get_role( ‘editor’ ); $role->remove_cap( ‘manage_options’ ); // capability } // Register our de-activation hook register_deactivation_hook( __FILE__, ‘deactivate_plugin_name’ );` Refer my tutorial for … Read more

How to update role capabilities

add_role() will not do anything if the role already exists, so it can’t be used to modify capabilities. To modify capabilities use the add_cap() and remove_cap() method of the WP_Role object. You can get a WP_Role for your role using get_role(): $role = get_role( ‘event-planner’ ); $role->add_cap( ‘edit_others_events’ ); Here’s the thing though, roles are … Read more

Remove ability to access certain admin menus

I figured it out in the end and this is the code I used: function restrict_menus() { $author = wp_get_current_user(); if( isset( $author->roles[0] ) ) { $current_role = $author->roles[0]; } else { $current_role=”no_role”; } if( ‘contributor’ == $current_role ) { $screen = get_current_screen(); $base = $screen->id; if( ‘edit-post’ == $base || ‘upload’ == $base || … Read more

Custom CSS In Admin Only For Certain Roles

Upon request I will write an answer using a function from a suggested answer for the similar question: How to target with css, admin elements according to user role level?. This function will output classes to the body element for all roles of the current user in the form role-XXXXX function wpa66834_role_admin_body_class( $classes ) { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)