current_user_can() returning true for capability when the user and role do not have the capability
current_user_can() returning true for capability when the user and role do not have the capability
current_user_can() returning true for capability when the user and role do not have the capability
How to give access to the particular page in wordpress for specific username/email NOT roles [closed]
I believe you’d need to modify user roles on each site individually (if I’m understanding your question correctly). There’s a great plugin I use frequently called WPFront User Role Editor that allows you to check/uncheck user capabilities like you mentioned. The free version should be fine for what you’re trying to do. I personally use … Read more
I found the solution to my problem. It had to do with my function that removes the manager role. I commented it out, and it works. My bad. Here’s the working code: if ( ! ( role_exists( ‘manager’ ) ) ) { function new_role_manager() { global $wp_roles; if ( ! isset( $wp_roles ) ) { … Read more
This is based on Bosco’s comment. You can do this instead of line 3 in the above code: wp_roles()->is_role( ‘editor’ ); That grabs a WP_Roles object (what the code you had tries to do by getting a global variable) and calls the same is_role() function.
As far as I know, WordPress only stores original authors of the posts. If you want to also save the publisher’s ID, you need to do a bit of custom coding, or use some 3rd party plugin. Essentially what you need to do is to store the user ID whenever the post status is being … Read more
It looks like your $user variable contents are not an instance of a WP_User class. You’ve got an error of stdClass, but you need the WP_User. Check what class the $user is the instance. If you use the get_users() function, you should note one feature of this function described in the documentation: Return value is … Read more
Increase by one the user counter on specific role
Woocommerce is considered off-topic here but as a general answer, it is considered best practice to check against capabilities instead of roles In WP, this is done like that: add_action(‘init’, ‘wpse_capability_check’); // hooked on ‘init’ but depends on your actual code logic function wpse_capability_check(){ // you should check on a capability that only validated user … Read more
What you want is add_role() The Codex provides sample code: $result = add_role( ‘basic_contributor’, __( ‘Basic Contributor’ ), array( ‘read’ => true, // true allows this capability ‘edit_posts’ => true, ‘delete_posts’ => false, // Use false to explicitly deny ) ); if ( null !== $result ) { echo ‘Yay! New role created!’; } else … Read more