Tag Info

Hot answers tagged

20

function change_role_name() { global $wp_roles; if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles(); //You can list all currently available roles like this... //$roles = $wp_roles->get_names(); //print_r($roles); //You can replace "administrator" with any other role "editor", "author", "contributor" or "subscriber"... ...


19

It's actually pretty easy. You need to filter into map_meta_caps and stop editors from creating/editing admins, and remove the administrator role from the 'editable roles' array. This class, as a plugin or in your theme's functions.php file would do it: class JPB_User_Caps { // Add our filters function JPB_User_Caps(){ add_filter( 'editable_roles', ...


18

Roles are stored in the global variable $wp_roles. The ideal function is get_editable_roles() from /wp-admin/includes/user.php function get_editable_roles() { global $wp_roles; $all_roles = $wp_roles->roles; $editable_roles = apply_filters('editable_roles', $all_roles); return $editable_roles; } The "editable" part is because it ...


13

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', ...


12

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 ...


12

It didn't say in the API docs on the Yoast SEO plugin site what the ID was and I don't have a copy of Yoast at installed at disposal, but according to yoas-plugin-dir/admin/class-metabox.php line 144, the meta_box registered is; add_meta_box( 'wpseo_meta', ...etc ); ... Which is hooked onto add_meta_boxes hook on line 32 of the same file, add_action( ...


9

Here's a mod to MikeSchinkel's answer that checks if the current user has a role of administrator and if not it only selects users that are subscribers. add_action('pre_user_query','yoursite_pre_user_query'); function yoursite_pre_user_query($user_search) { $user = wp_get_current_user(); if ( $user->roles[0] != 'administrator' ) { ...


9

You code seems to be correct. Try the following instead. $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => true, 'hierarchical' => false, 'menu_position' => null, 'supports' => array('title'), ...


8

Hi @Carlos: Try adding the following to your theme's functions.php file, or in a .php file within a plugin that you might be writing (which works for WordPress 3.1.x): add_action('pre_user_query','yoursite_pre_user_query'); function yoursite_pre_user_query($user_search) { $user = wp_get_current_user(); if ($user->ID!=1) { // Is not administrator, ...


8

When assigning capabilities to 'capabilities' argument of register_taxonomy() you need to assign the capability and not the role! so use capabilities that only a specific role has eg: 'capabilities' => array ( 'manage_terms' => 'manage_options', //by default only admin 'edit_terms' => 'manage_options', ...


8

Looks like a CPT with custom capability_type won't show up by default even as super admin. Even manually adding the permissions for the desired user role (licensing-admin in my case) didn't make it happen - I had to manually add the capabilities for the administrator as well, then everything fell into place. Stuck this code in my plugin activation hook and ...


8

After a quick chat with Magicroundabout who pointed out a useful resource from Justin Tadlock, it turns out that capabilities for custom post types don't actually exist unless you use add_cap to the role, for example for the following custom post type: add_action( 'init', 'register_cpt_gallery' ); function register_cpt_gallery() { $labels = array( ...


7

You cannot assign capabilities to unknown users. If you want to make a post visible for everyone, create a separate URL for these posts and add a control element to the post editor to enable the preview on selected posts only. When such an URL is called, check if a preview is allowed for the post and if the post hasn’t been published already. Also make sure ...


7

You want the admin_menu hook, rather than admin_init. Also, you shouldn't use anonymous functions. Instead, use: function wpse51004_add_menu_page() { add_menu_page('Some Page', 'Some Page', 'manage_options', 'some-slug', 'wpse51004_some_page_callback'); }; add_action('admin_menu', 'wpse51004_add_menu_page'); function wpse51004_some_page_callback() { ...


7

Hi @NetConstructor: I think this is what you need. Note that I didn't include the full setup of your 'website_owner' role, just the addition of a new capability called 'manage_administrators'. Also, I only attempted to remove the "Delete" link from any users that don't have the 'manage_administrators' capability (which you'll need to add to the ...


6

The register_post_type has a capabilities (or simple version: capability_type) that you can use to specify a separate capability to create and edit posts of this type. If you set this, you can create a new role that has the capability to edit these custom posts, but not regular posts.


6

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 ) ) { ...


6

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 ); or you can run this once in your functions: /* Roles & Capabilities */ ...


6

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 ...


5

Yes, just filter 'user_has_cap'. You get an array with the current capabilities that you can change without touching the database. Sample Code add_filter( 'user_has_cap', 'wpse_53230_catch_cap', 10, 3 ); /** * See WP_User::has_cap() in wp-includes/capabilities.php * * @param array $allcaps Existing capabilities for the user * @param string $caps ...


5

Remove what you add First, please make sure that everything you add on activation also gets removed on uninstall. I got a short tutorial including example code for you. Test with a small plugin: I really don't know much about MU, but as far as I can tell, the roles object is global across all blogs. Just try this little plugin and see what you can get: ...


5

Although this isn't well documented, "Super Admin" is not a role (in that it is not an actual role object). It's more like a special "status". A list of users who are Super Admins (also called "network admins" or "site admins") are stored in a database site-option record called 'site_admins'. Generally, adding a capability to the Administrator role is ...


5

For a plugin I'm currently working on, I wanted to grant/restrict access to the plugin settings (i.e., the according admin menu pages) on a per role base. Therefore, I had to add a new plugin-specific capability to the user roles. Unfortunately, kaiser's answer seems to be not working anymore, so I spent some time trying to figure out how to allow for the ...


5

The plugin Members is your solution, clean code for read, change and create roles and capabilities; easy and fast. No custom tables and normaly WordPress standard.


5

You could check the $current_user variable to determine the role. I believe it should be realiable after init(maybe even on init) for a logged in user, a guest visitor obviously won't have any data associated with him or her yet(so it'll be empty/unset). You can also call up get_currentuserinfo() to populate the $current_user var, but i've personally never ...


5

Yes, you can run WordPress with your own domain if you purchase hosting for it. WordPress has system of Roles (which can be further enhanced via plugins), you can let users register and allow to perform actions accordign to their role. Essentially yes. You copy WordPress files to server and initiate brief installation procedure. First account will be ...


5

Try this: function get_role_names() { global $wp_roles; if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles(); return $wp_roles->get_names(); } PS heh, missed that explanation and reply, too fast me :)


5

Me, like @fischi think that filter 'user_has_cap' is the best choiche for the pourpose, however, I think that is better to the work, regardless the $_GET post or action: WordPress check the meta cabability on a per-post basis, using an additional argument. In few words, when filtering 'user_has_cap' for a meta capability (see ...


4

This is actually not hard. To add a new capability, call WP_Roles->add_cap(). You have to do this just once, because it will be stored in the database. So we use a plugin activation hook. Note to other readers: All of the following code is plugin territory. register_activation_hook( __FILE__, 'epp_add_cap' ); /** * Add new capability to "editor" role. ...


4

You can remove it using the remove_meta_box function. if ( ! current_user_can( 'edit_pages' ) ) { add_action( 'add_meta_boxes', 'my_remove_wp_seo_meta_box', 100000 ); } function my_remove_wp_seo_meta_box() { remove_meta_box( 'wpseo_meta', 'post', 'normal' ); } Notice the 100000 in the add_action, this makes sure that this is done after the WP SEO ...



Only top voted, non community-wiki answers of a minimum length are eligible