current_user_can(‘administrator’) not working in custom login
the current user may not be set at this step then try this : if (user_can($user, ‘administrator’)) { wp_redirect($admin_url); }
the current user may not be set at this step then try this : if (user_can($user, ‘administrator’)) { wp_redirect($admin_url); }
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
Remove a top level admin menu: function custom_menu_page_removing() { remove_menu_page( $menu_slug ); } add_action( ‘admin_menu’, ‘custom_menu_page_removing’ ); To remove only certain menu items include only those you want to hide within the function. To remove menus for only certain users you may want to utilize current_user_can(). You can take a look at https://codex.wordpress.org/Function_Reference/remove_menu_page
Ok, so this isn’t possible to do by default. As I already had a hook for wpmu_activate_blog() I just created another with a lower priority which will be fired after. This function also has the 2 parameters I need. So upon activation of the account I simply remove Admin role and set a new role … Read more
This worked for me: Make sure the row in option-table in the database for wordpress-site have the correct option_name for the serialised roles-data. For instance; if the database-table is wp_options, the column option_name in the role-row should be wp_user_roles. if the database-table is wp_20_options, the column option_name in the role-row should be wp_20_user_roles. Don’t ask … 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
If by “made an entry” you mean “has published at least 1 post”, then following will do it (with the proviso given below): $args = array ( ‘role’ => ‘spectator’, ) ; $spectators = new WP_User_Query ($args) ; $users_with_recent_posts = array () ; foreach ($spectators->get_results () as $user) { $args = array ( // if … Read more
The function you want is get_userdata(). Since you need to do this outside the loop, the process is a little less straight-forward. The first thing you need to do is set up a variable called $curauth which is an object that you create by accessing the database by using the $_GET[] superglobal. $curauth = ( … Read more
You haven’t posted any code so I won’t be able to precisely post an answer for you, but this it what you can do. Find the page that is rendering the profiles, open it and add this piece of code in it: <?php $user_info = get_userdata($id); $role = $user_info->roles; if ($role ==’corporates’ && !is_user_logged_in()) { … 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