Capability to edit own posts and not others

The capabilities that you are trying to restrict are delete_others_posts edit_others_posts Apart from Super Admin and Administrator, the only Role that have these permission is Editor. So, removing these capabilities from Editor should accomplish this. /** * Remove capabilities from editors. * * Call the function when your plugin/theme is activated. */ function wpcodex_set_capabilities() { … Read more

Redirect After Delete User in Backend

You could also do this, function mod_redirect_subscriber_delete($user_id) { $user = get_user_by(‘id’, $user_id); $role = $user->roles[0]; if ($role == ‘subscriber’) { add_action(“deleted_user”, function(){ wp_redirect( admin_url(‘/index.php’) ); exit; }); } } add_action(“delete_user”, “mod_redirect_subscriber_delete”); Anonymous functions (closures), available in PHP 5.3+. Benefits: No need to remove the initial hook on delete_user No need to re-run wp_delete_user() You still … Read more

Prevent from deleting any user role but subscriber

If you mean the delete button on the user list at /wp-admin/users.php, then that button is created by the WP_Users_List_Table class around (currently) line 256. If you look a little further down– a few lines– you will see a filter called user_row_actions. You can use that to hide the ‘delete’ link. add_filter( ‘user_row_actions’, function($actions, $user_object) … Read more

How to let the Contributor role preview unpublished posts?

Unfortunately, WordPress doesn’t use a separate capability for previewing posts. A user needs the ability to edit a post in order to preview it. As seen in the WP_Query::get_posts() method: // User must have edit permissions on the draft to preview. if ( ! current_user_can($edit_cap, $this->posts[0]->ID) ) { $this->posts = array(); } What you could … Read more

How can I change a user role upon visiting a page?

EDIT I updated the function to check for role for which we want to make changes for, if the current user role is not within our roles_to_change array then the function exits. Note that I haven’t tested for bugs, so if you find any, just report them here. @Malisa’s answer is a good approach. However, … Read more

Disable text tab on WordPress text-editor

For disabling the text tab for all users except administrators, you can add the following: function my_editor_settings($settings) { if ( ! current_user_can(‘administrator’) ) { $settings[‘quicktags’] = false; return $settings; } else { $settings[‘quicktags’] = true; return $settings; } } add_filter(‘wp_editor_settings’, ‘my_editor_settings’);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)