How to delete user roles?

$wp_roles = new WP_Roles(); // create new role object $wp_roles->remove_role(‘name_of_role’); If you need to check the name_of_role use $wp_roles->get_names(); you will get an array of name_of_role => Nicename of Role Alternatively, you could use the global object $wp_roles global $wp_roles;

What is the difference between “create_users” and “add_users” capabilities?

I explored WordPress to find difference between it and in schema.php file i found the following function only where in WordPress add_users capability is used. /** * Create and modify WordPress roles for WordPress 3.0. * * @since 3.0.0 */ function populate_roles_300() { $role =& get_role( ‘administrator’ ); if ( !empty( $role ) ) { … Read more

How are roles stored in the database?

The core functions: is_super_admin(), grant_super_admin(), revoke_super_admin() fetch the super admins data from the wp_sitemeta table with: $super_admins = get_site_option( ‘site_admins’, array( ‘admin’ ) ); It’s stored as a serialized array of user logins, for each site, like: a:1:{i:0;s:6:”louiev”;} It’s possible to override it with the global $site_admins array. On the other hand, the general user … Read more

How to add author role as a custom field to custom post type in wordpress?

You can hook into save_post_{$post->post_type} which fires after the post has been saved in database. function wpse405375_save_author_role_as_meta( $post_ID, $post, $update ) { //Get the User object from author id. $author = get_user_by( ‘ID’, $post->post_author ); //Get author roles $roles = $author->roles; //Store the role/roles in post meta /* This one will store all the roles … Read more

pre_get_posts Remove posts based on meta value with ‘post__not_in’

Try this version: // Get all posts with the access level of ‘Member’ function members_get_member_posts() { $post_ids = wp_cache_get( ‘wpse61487_members_posts’ ); if ( false === $post_ids ) { $post_ids = array(); $args=array( ‘post_type’ => ‘any’, ‘meta_key’ => ‘_members_access_role’, ‘meta_value’ => ‘member’, ‘post_status’ => array(‘publish’,’private’) ); $protected_posts = get_posts($args); if($protected_posts) { $post_ids = wp_list_pluck( $protected_posts, ‘ID’ … Read more

WordPress Super Admin

I would recommend creating a Custom User Role, using the add_role() function, such as a “Site Admin” or “Sub-Admin” (or whatever you want to call it). Then, you can assign specific user capabilities to that custom role, thereby giving users exactly the capabilities you want them to have, without giving them the capabilities you don’t … Read more