Hide items from subsite admin in users.php

How do I prevent these items from displaying on users.php for subsite admins?

1. Change role
2. View email address
3. Number of posts.

I am avoiding using a role editor plugin, don't understand code but can delete if you tell me which ones I can safely remove!
thanks!

  • digitsoft
    • The Crimson Coder

    Add these to the bottom of the theme's functions.php to remove the Posts and Email columns:

    add_action('manage_users_columns','remove_user_posts_column');
    function remove_user_posts_column($column_headers) {
        unset($column_headers['posts']);
        return $column_headers;
    }
    
    add_action('manage_users_columns','remove_user_email_column');
    function remove_user_email_column($column_headers) {
        unset($column_headers['email']);
        return $column_headers;
    }

    I'll look at the bulk actions and let you know...

  • digitsoft
    • The Crimson Coder

    I did this on a single site...so you'd probably want to include this change for MU around the code above:

    if (!is_super_admin($user_id))
    {
    }

    So it would be:

    if (!is_super_admin($user_id))
    {
    add_action('manage_users_columns','remove_user_posts_column');
    function remove_user_posts_column($column_headers) {
        unset($column_headers['posts']);
        return $column_headers;
    }
    
    add_action('manage_users_columns','remove_user_email_column');
    function remove_user_email_column($column_headers) {
        unset($column_headers['email']);
        return $column_headers;
    }
    }
  • PC
    • WPMU DEV Initiate

    @Atlanta : Greetings,

    That is a really good suggestion as given by digitsoft. I tested that and it seems to be doing the task.

    However, I would just like to let you know, that if you access any of the subsites or even your main site, dashboard with your Super Admin, then also, these options would not be available. Please check if that is really what you want !

    You will, then only be able to see the email addresses if you are @ Network Dashboard >> Users

    PS : I would request you take a backup of your existing install before you try that. This way we will be safe from any unforeseen errors and can restore if one occurs.

    I am looking into the Bulk Action menu and will get back soon.

    Cheers
    PC

  • PC
    • WPMU DEV Initiate

    Oh Great,

    Thanks digitsoft on you help on this issue :slight_smile:

    @Atlanta : That will surely help you a part of the problem. I already tested the code provided by digitsoft and it seems good :slight_smile:

    @Digitsoft : A few cookies on you way !

    Cheers
    PC

  • digitsoft
    • The Crimson Coder

    Here's how to remove the bulk role change:
    1. Edit /wp-admin/includes/class-wp-users-list-table.php
    2. Put this at line 141:

    if (!is_super_admin($user_id))
    {

    3. Put this at line 154:
    }

    This area should look like this:

    if (!is_super_admin($user_id))
    {
    
    ?>
    	<div class="alignleft actions">
    		<label class="screen-reader-text" for="new_role"><?php _e( 'Change role to&hellip;' ) ?></label>
    		<select name="new_role" id="new_role">
    			<option value=''><?php _e( 'Change role to&hellip;' ) ?></option>
    			<?php wp_dropdown_roles(); ?>
    		</select>
    		<?php submit_button( __( 'Change' ), 'secondary', 'changeit', false ); ?>
    	</div>
    <?php
    }
  • Atlanta
    • Syntax Hero

    Thanks.
    I added

    if (!is_super_admin($user_id))
    {
    add_action('manage_users_columns','remove_user_posts_column');
    function remove_user_posts_column($column_headers) {
    unset($column_headers['posts']);
    return $column_headers;
    }

    add_action('manage_users_columns','remove_user_email_column');
    function remove_user_email_column($column_headers) {
    unset($column_headers['email']);
    return $column_headers;
    }
    }

    to functions.php for gridmarket and it didn't work when I was logged in as a subsite admin so I then tried it in framemarket and it didn't work either.

  • digitsoft
    • The Crimson Coder

    Finally....bulk actions gone.

    1. Edit the file /wp-admin/includes/class-wp-list-table.php
    2. Add this to line 277:

    if (!is_super_admin($user_id))
    {

    3. Add this to line 309:
    }

    Whew...all done...

    @PC - my post re:admin beat yours :stuck_out_tongue:

  • Atlanta
    • Syntax Hero

    Thanks digisoft, sent you some points:slight_smile:
    Thanks for the heads up PC.

    Bulk actions. Edit the file /wp-admin/includes/class-wp-list-table.php
    2. Add this to line 277:
    if (!is_super_admin($user_id))
    {
    3. Add this to line 309:
    }

    Question- can you show me the code with the surrounding content for line 277 since the line number might have changed with the other edits

    Will this get rid of the footer bulk actions also? Which I want but didn't clarify before.

    P.S
    to remove bulk role from subsite I did
    if (is_super_admin($user_id))
    {
    ie without the exclamation.
    Thanks again.

  • digitsoft
    • The Crimson Coder

    Thanks for the points all!

    Here's what that piece should look like:

    function bulk_actions() {
    if (!is_super_admin($user_id))
    {
    		$screen = get_current_screen();
    
    		if ( is_null( $this->_actions ) ) {
    			$no_new_actions = $this->_actions = $this->get_bulk_actions();
    			// This filter can currently only be used to remove actions.
    			$this->_actions = apply_filters( 'bulk_actions-' . $screen->id, $this->_actions );
    			$this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
    			$two = '';
    		} else {
    			$two = '2';
    		}
    
    		if ( empty( $this->_actions ) )
    			return;
    
    		echo "<select name='action$two'>\n";
    		echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions' ) . "</option>\n";
    
    		foreach ( $this->_actions as $name => $title ) {
    			$class = 'edit' == $name ? ' class="hide-if-no-js"' : '';
    
    			echo "\t<option value='$name'$class>$title</option>\n";
    		}
    
    		echo "</select>\n";
    
    		submit_button( __( 'Apply' ), 'button-secondary action', false, false, array( 'id' => "doaction$two" ) );
    		echo "\n";
    	}
    }

    It will get rid of the footer as well since it's the same function...kind of an all or nothing solution.

  • aecnu
    • WP Unicorn

    Greetings Atlanta,

    We have not heard back from you as to the status of this issue.

    If you are still having an issue please let us know so that we may try to get you fixed up as soon as possible by choosing to check mark this ticket as unresolved below and posting any new errors or symptoms you are noticing.

    This action will also bring your ticket up front back in plain view again within the ticket system.

    Thank you for being a WPMU Dev member!

    Cheers, Joe

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.