display user roles in comment form
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 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
please try this if ( have_posts() ) : while ( have_posts() ) : the_post(); if ( get_post_status (get_the_id()) == ‘private’ ) { if ( current_user_can( ‘administrator’ ) ) { the_title(); the_content(); } else if ( current_user_can( ‘subscriber’ ) ) { the_title(); the_content(); } else { echo ‘this post is private’; } } else { the_title(); … Read more
Your code isn’t working because WordPress deprecated user levels in version 3.0 (June 2010). What you want to do is create a plugin that upon activation, creates a new role for the owner of the site that is a clone of the administrator role, but cannot edit plugin or theme files. Those capabilities are edit_plugins … Read more
The capability required to delete posts is delete_posts. If you want them to be able to delete their own published posts, the capability is delete_published_posts. The capability required to view the administration panel is read. Subscribers have this capability natively, so unless you have removed it, subscribers can access the backend. I would write a … Read more
You can pass the user’s role directly to wp_insert_user(). First, you can try to add your custom role to the WP_Roles object, then pass the custom role to the user properties: // Add custom roles only once to avoid unnecessary database calls. // It is usually done during plugin activation. register_activation_hook( __FILE__, ‘cyb_add_roles’ ); function … Read more
The edit_theme_options capability controls access to the widgets page but also to the menus page. You can then remove the menus submenu from appearance for a specific role, and if someone tries to get there by url, redirect it : /** * Remove the “Menus” submenu from Appearance */ function remove_menus() { if (in_array(‘administrator’, wp_get_current_user()->roles)) … Read more
To remove from the admin menu, you could use remove_menu_page(): add_action( ‘admin_menu’, function ( ) { if (is_super_admin()) return; remove_menu_page(); // or remove_submenu_page( … },99); If for some reason the page still exists, it’s just missing it’s menu link, you could check the get_current_screen() to see if the page is being viewed, and prevent access: … Read more
Check or Alter user capabilities on call of current_user_can. Check current_user_can fucntion and has_cap fitler for further info.