Capabilities don’t add
This line in your wpo_add_caps() function is incorrect: $admin->add_cap( ‘administrator’, $admin_cap ); It should simply read: $admin->add_cap( $admin_cap ); Source: WP_Role::add_cap().
This line in your wpo_add_caps() function is incorrect: $admin->add_cap( ‘administrator’, $admin_cap ); It should simply read: $admin->add_cap( $admin_cap ); Source: WP_Role::add_cap().
That’s the correct way to get what you need. Though I’m not sure why WordPress returns an array of roles since ( to my knowledge ) you can only have 1 role at a time. Roles being an array you can modify by just retrieving the role index 0: $blogusers = get_users(); // Array of … Read more
Don’t remove the capability – this will make all editors unable to edit all posts. Instead, use a filter to conditionally determine if the post can be edited: function wpse_187738_map_meta_cap( $caps, $cap, $user_ID, $args ) { if ( $cap === ‘edit_post’ && $args && ! current_user_can( ‘manage_options’ ) /** Only proceed for non-administrators */ ) … Read more
How about remove_meta_box( $id, $page, $context );? https://codex.wordpress.org/Function_Reference/remove_meta_box This will remove the Publish meta box which contains the save button… function disable_save() { if( !current_user_can( ‘edit_post’ ) ) { // Or whatever check you need to make remove_meta_box( ‘submitdiv’, ‘your-chosen-post-type’, ‘side’ ); } } // disable_save add_action( ‘admin_menu’, ‘disable_save’ );
Close, your date comparison is slightly off – user_registered will be a MySQL datetime, so your string comparison will never evaluate true. Instead, convert it to just the date: $registered = mysql2date( ‘Y-m-d’, $user->user_registered ); Now we’re talking: if ( ‘2015-10-01′ === $registered ) { // chocks away } Update: Here’s a complete snippet that … Read more
You could make a widget that updates the role: Widget has a drop down select input Select input submits a Ajax call to backend Backend Ajax call processor updades the user meta Pass the User ID along with the role ID Update user meta with update_user_meta( $user_id, $meta_key, $meta_value, $prev_value )
Try to use get_posts() $current_user = get_current_user_id(); $args = array( ‘post_type’ => ‘post’, ‘author’ => $current_user, ‘post_status’ => ‘publish’, ); $all_posts = get_posts( $args );
This will print User Role global $current_user; $user_role = $current_user->roles[0]; echo $user_role; Use above code, where ever you want to display user role.
This question is a bit too broad for a Q&A model, but I tend to think that everything you need is already built in. Except that you will want your clients to login, something you can have them do on the front end. You could even make a custom role which will allow you to … Read more
Look at the remove_cap method from WP_User class- /** * Remove capability from user. * * @since 2.0.0 * @access public * * @param string $cap Capability name. */ public function remove_cap( $cap ) { if ( ! isset( $this->caps[ $cap ] ) ) { return; } unset( $this->caps[ $cap ] ); update_user_meta( $this->ID, $this->cap_key, … Read more