How can I get a list of users by their role?

There may be some different way to do that, but most proper way to do that is following. <?php $args = array( ‘role’ => ‘Your desired role goes here.’, ‘orderby’ => ‘user_nicename’, ‘order’ => ‘ASC’ ); $users = get_users( $args ); echo ‘<ul>’; foreach ( $users as $user ) { echo ‘<li>’ . esc_html( $user->display_name … Read more

Why are my roles not visible in a Multi-site/Network?

Determine your Multisite Blog ID. I will use 99 as an example Go into the database Go to this table: wp_##_options (wp_99_options) — you will have a table for each blog Find the record where option_name = wp_user_roles Change the text wp_user_roles to wp_##_user_roles (“wp_99_user_roles”) The table you are editing will have option_id, blog_id, option_name, … Read more

Select subscriber as author of post in admin panel?

This is a simple hack I wrote in a similar situation. It will display all the Subscribers in the Author dropdown on edit/add post/page, from where you can select any one you want. I think it should work for you… add_filter(‘wp_dropdown_users’, ‘MySwitchUser’); function MySwitchUser($output) { //global $post is available here, hence you can check for … Read more

How to add a Capability to a User Role?

You can use WP_Role class, // get the the role object $role_object = get_role( $role_name ); // add $cap capability to this role object $role_object->add_cap( $capability_name ); // remove $cap capability from this role object $role_object->remove_cap( $capability_name ); So to address your original question about how to enable Admins to enter SCRIPT and IFRAME tags … Read more

How to allow an user role to create a new user under a role which lower than his level only?

Firstly, you need to add the following capabilities to the Doctor and Receptionist role: list_users edit_users create_users delete_users Now we can get to work with controlling which users they can create/edite/delete. Let’s start with a “helper” function that will return which roles a user is allowed to edit: /** * Helper function get getting roles … Read more

How can I allow the Editor Role to change Theme Settings?

you can add capabilities to the editor role using the role object and add_cap from you functions.php <?php // get the the role object $editor = get_role(‘editor’); // add $cap capability to this role object $editor->add_cap(‘edit_theme_options’); ?> you can also remove capabilities: $editor->remove_cap(‘delete_posts’); just take a look at the list of capabilities and what each … Read more

Possible to hide Custom Post Type UI/Menu from specific User Roles?

To hide a post type menu item from non-admin users: function wpse28782_remove_menu_items() { if( !current_user_can( ‘administrator’ ) ): remove_menu_page( ‘edit.php?post_type=your_post_type’ ); endif; } add_action( ‘admin_menu’, ‘wpse28782_remove_menu_items’ ); your_post_type should be the name of your actual post type. EDIT- other menu pages you can remove: remove_menu_page(‘edit.php’); // Posts remove_menu_page(‘upload.php’); // Media remove_menu_page(‘link-manager.php’); // Links remove_menu_page(‘edit-comments.php’); // … Read more

How to create a clone role in wordpress

Try this… This should work. <?php add_action(‘init’, ‘cloneRole’); function cloneRole() { global $wp_roles; if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles(); $adm = $wp_roles->get_role(‘administrator’); //Adding a ‘new_role’ with all admin caps $wp_roles->add_role(‘new_role’, ‘My Custom Role’, $adm->capabilities); } ?> Check it.