Add Custom User Capabilities Before or After the Custom User Role has Been Added?

There’s a reason why add_role() has the $capabilities as 3rd parameter. First some insights on what happens, when you use the function. It calls WP_Roles->add_role() – the class method The method then does a check if the role already exists. If yes, it aborts. The next step is, that it adds the role to WP_Roles->roles[] … Read more

How to change the email notification recipient (user) for new comments?

There’s a great article explaining how to hook into 2 filters for this at https://web.archive.org/web/20200216075253/http://www.sourcexpress.com/customize-wordpress-comment-notification-emails/ To send your notifications to a particular user and not the site admin, try this for a user with ID 123: function se_comment_moderation_recipients( $emails, $comment_id ) { $comment = get_comment( $comment_id ); $post = get_post( $comment->comment_post_ID ); $user = get_user_by( … Read more

Disallowing Users of a Custom Role from Deleting or Adding Administrators?

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 … Read more

How can I hide a category from Contributors in the edit/add new post screen?

Working Example in Oct 2020, Working answer, I went to different answers none of them works now in new WordPress. function hide_categories_for_specific_user( $exclusions, $args ){ if ( ((defined( ‘REST_REQUEST’ ) && REST_REQUEST) or $GLOBALS[‘pagenow’] === ‘edit.php’ ) && !current_user_can( ‘manage_options’ ) ) { // IDs of terms to be excluded $exclude_array = array(“12″,”16″,”17”); // CHANGE … Read more

Restrict admin access to certain pages for certain users

This code seems to work well for me (in functions.php): $user_id = get_current_user_id(); if ($user_id == 2) { add_filter( ‘parse_query’, ‘exclude_pages_from_admin’ ); } function exclude_pages_from_admin($query) { global $pagenow,$post_type; if (is_admin() && $pagenow==’edit.php’ && $post_type ==’page’) { $query->query_vars[‘post__not_in’] = array(‘123′,’234′,’345’); } }

Allow roles below admin to add subscribers only

This first step to making this happen is add the capability to create_users to a given role. You do this be calling get_role, then using the add_cap method. This only needs to be done once. Here’s an example that does it on plugin activation. <?php register_activation_hook( __FILE__, ‘wpse42003_activation’ ); function wpse42003_activation() { foreach( array( ‘editor’, … Read more

Is it possible to add new user Roles?

Yes. WordPress has robust built-in Roles and Capabilities system desgined to do exactly what you are looking for. To add a new role, use the add_role() function in your theme’s functions.php or a plug-in like so: $role = add_role( ‘event_manager’, ‘Event Manager’, array( ‘read’ => true, // True allows that capability ) ); if ( … Read more

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