Another hide from subsite admin question

In this post https://premium.wpmudev.org/forums/topic/hide-items-from-subsite-admin-in-usersphp#post-222608 I learned that to hide bulk actions from subsite admins in wp-admin/users.php

How do I hide bulk actions from subsite admins in
/wp-admin/admin.php?page=membershipmembers?

  • digitsoft

    Same file....line 2093 (may be difft line if using code from the other thread)...make it look like this:

    <?php
    	if (current_user_can('administrator'))
    	{?>
    
    				<select name="action2">
    					<option selected="selected" value=""><?php _e('Bulk Actions','membership'); ?></option>
    					<option value="toggle"><?php _e('Toggle activation','membership'); ?></option>
    
    					<optgroup label="<?php _e('Subscriptions','membership'); ?>">
    						<option value="bulkaddsub"><?php _e('Add subscription','membership'); ?></option>
    						<option value="bulkmovesub"><?php _e('Move subscription','membership'); ?></option>
    						<option value="bulkdropsub"><?php _e('Drop subscription','membership'); ?></option>
    					</optgroup>
    
    					<optgroup label="<?php _e('Levels','membership'); ?>">
    						<option value="bulkaddlevel"><?php _e('Add level','membership'); ?></option>
    						<option value="bulkmovelevel"><?php _e('Move level','membership'); ?></option>
    						<option value="bulkdroplevel"><?php _e('Drop level','membership'); ?></option>
    					</optgroup>
    
    					<optgroup label="<?php _e('Gateways','membership'); ?>">
    						<option value="bulkmovegateway"><?php _e('Move gateway','membership'); ?></option>
    					</optgroup>
    				</select>
    				<input type="submit" class="button-secondary action" id="doaction2" name="doaction2" value="Apply">
    <?php }?>
  • Atlanta

    Thanks. In classes/membershipadmin.php around line 2092 I added if (current_user_can('administration')) and also tried update_core but the bulk actions are still showing in wp-admin/admin.php?page=membershipmembers. Pasted code in bold below...

    <div class="alignleft actions">
    <?php
    if (current_user_can('update_core'))
    {?>

    <select name="action2">
    <option selected="selected" value=""><?php _e('Bulk Actions','membership'); ?></option>
    <option value="toggle"><?php _e('Toggle activation','membership'); ?></option>

    <optgroup label="<?php _e('Subscriptions','membership'); ?>">
    <option value="bulkaddsub"><?php _e('Add subscription','membership'); ?></option>
    <option value="bulkmovesub"><?php _e('Move subscription','membership'); ?></option>
    <option value="bulkdropsub"><?php _e('Drop subscription','membership'); ?></option>
    </optgroup>

    <optgroup label="<?php _e('Levels','membership'); ?>">
    <option value="bulkaddlevel"><?php _e('Add level','membership'); ?></option>
    <option value="bulkmovelevel"><?php _e('Move level','membership'); ?></option>
    <option value="bulkdroplevel"><?php _e('Drop level','membership'); ?></option>
    </optgroup>

    <optgroup label="<?php _e('Gateways','membership'); ?>">
    <option value="bulkmovegateway"><?php _e('Move gateway','membership'); ?></option>
    </optgroup>
    </select>
    <input type="submit" class="button-secondary action" id="doaction2" name="doaction2" value="Apply">
    <?php }?>
    <select name="sub_op2">

  • digitsoft

    Hmm...let's try this:
    1. Add this to your functions.php file:

    function get_current_user_role() {
            global $wp_roles;
            $current_user = wp_get_current_user();
            $roles = $current_user->roles;
            $role = array_shift($roles);
            return isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role] ) : false;
    }

    2. Change
    if (current_user_can('update_core'))
    to
    if (get_current_user_role = 'Administrator')

    A subsite admin will show as Administrator, so this should work.

    LMK how it goes...

    Rob

  • digitsoft

    Tested and working...

    1. Edit /membership/membershipincludes/classes/membershipadmin.php
    2. Start editing at 1836 to make it look like this (total of 10 new lines):

    <?php
    $myrole = get_current_user_role();
    if ( $myrole <> 'Administrator')
    {
    ?>
    				<select name=&quot;action&quot;>
    					<option selected=&quot;selected&quot; value=&quot;&quot;><?php _e('Bulk Actions','membership'); ?></option>
    					<option value=&quot;toggle&quot;><?php _e('Toggle activation','membership'); ?></option>
    
    					<optgroup label=&quot;<?php _e('Subscriptions','membership'); ?>&quot;>
    						<option value=&quot;bulkaddsub&quot;><?php _e('Add subscription','membership'); ?></option>
    						<option value=&quot;bulkmovesub&quot;><?php _e('Move subscription','membership'); ?></option>
    						<option value=&quot;bulkdropsub&quot;><?php _e('Drop subscription','membership'); ?></option>
    					</optgroup>
    
    					<optgroup label=&quot;<?php _e('Levels','membership'); ?>&quot;>
    						<option value=&quot;bulkaddlevel&quot;><?php _e('Add level','membership'); ?></option>
    						<option value=&quot;bulkmovelevel&quot;><?php _e('Move level','membership'); ?></option>
    						<option value=&quot;bulkdroplevel&quot;><?php _e('Drop level','membership'); ?></option>
    					</optgroup>
    
    					<optgroup label=&quot;<?php _e('Gateways','membership'); ?>&quot;>
    						<option value=&quot;bulkmovegateway&quot;><?php _e('Move gateway','membership'); ?></option>
    					</optgroup>
    				</select>
    				<input type=&quot;submit&quot; class=&quot;button-secondary action&quot; id=&quot;doaction&quot; name=&quot;doaction&quot; value=&quot;<?php _e('Apply','membership'); ?>&quot;>
    
    				<select name=&quot;sub_op&quot;>
    					<option value=&quot;&quot;><?php _e('Filter by subscription','membership'); ?></option>
    					<?php
    						$subs = $this->get_subscriptions();
    						if($subs) {
    							foreach($subs as $key => $sub) {
    								?>
    								<option value=&quot;<?php echo $sub->id; ?>&quot; <?php if(isset($_GET['sub_op']) && $_GET['sub_op'] == $sub->id) echo 'selected=&quot;selected&quot;'; ?>><?php echo esc_html($sub->sub_name); ?></option>
    								<?php
    							}
    						}
    					?>
    				</select>
    				<input type=&quot;submit&quot; class=&quot;button-secondary action&quot; id=&quot;doactionsub&quot; name=&quot;doactionsub&quot; value=&quot;<?php _e('Filter','membership'); ?>&quot;>
    
    				<select name=&quot;level_op&quot;>
    					<option value=&quot;&quot;><?php _e('Filter by level','membership'); ?></option>
    					<?php
    						$levels = $this->get_membership_levels();
    						if($levels) {
    							foreach($levels as $key => $level) {
    								?>
    								<option value=&quot;<?php echo $level->id; ?>&quot; <?php if(isset($_GET['level_op']) && $_GET['level_op'] == $level->id) echo 'selected=&quot;selected&quot;'; ?>><?php echo esc_html($level->level_title); ?></option>
    								<?php
    							}
    						}
    					?>
    				</select>
    				<input type=&quot;submit&quot; class=&quot;button-secondary action&quot; id=&quot;doactionlevel&quot; name=&quot;doactionlevel&quot; value=&quot;<?php _e('Filter','membership'); ?>&quot;>
    
    				<select name=&quot;active_op&quot;>
    					<option value=&quot;&quot;><?php _e('Filter by status','membership'); ?></option>
    					<option value=&quot;yes&quot; <?php if(isset($_GET['active_op']) && $_GET['active_op'] == 'yes') echo 'selected=&quot;selected&quot;'; ?>><?php _e('Active','membership'); ?></option>
    					<option value=&quot;no&quot; <?php if(isset($_GET['active_op']) && $_GET['active_op'] == 'no') echo 'selected=&quot;selected&quot;'; ?>><?php _e('Inactive','membership'); ?></option>
    				</select>
    				<input type=&quot;submit&quot; class=&quot;button-secondary action&quot; id=&quot;doactionactive&quot; name=&quot;doactionactive&quot; value=&quot;<?php _e('Filter','membership'); ?>&quot;>
    
    				</div>
    <?php }?>
    				<div class=&quot;alignright actions&quot;>
    					<!-- <input type=&quot;button&quot; class=&quot;button-secondary addnewlevelbutton&quot; value=&quot;<?php _e('Add New','membership'); ?>&quot; name=&quot;addnewlevel&quot;> -->
    				</div>
    
    				<br class=&quot;clear&quot;>
    				</div>
    				<?php if ( is_wp_error( $wp_user_search->search_errors ) ) : ?>
    					<div class=&quot;error&quot;>
    						<ul>
    						<?php
    							foreach ( $wp_user_search->search_errors->get_error_messages() as $message )
    								echo &quot;<li>$message</li>&quot;;
    						?>
    						</ul>
    					</div>
    				<?php endif; ?>
    
    				<?php if ( $wp_user_search->is_search() ) : ?>
    					<p><a href=&quot;?page=<?php echo $page; ?>&quot;><?php _e('&larr; Back to All Users','membership'); ?></a></p>
    				<?php endif; ?>
    
    				<div class=&quot;clear&quot;></div>
    
    				<?php
    					wp_nonce_field('bulk-members');
    
    if ( $myrole == 'Administrator')
    {
    					$columns = array(	&quot;username&quot; 	=> 	__('Username','membership'),
    										&quot;name&quot; 		=> 	__('Name','membership'),
    										&quot;email&quot; 	=> 	__('E-mail','membership'),
    										&quot;active&quot;	=>	__('Active','membership'),
    										&quot;sub&quot;		=>	__('Subscription','membership'),
    										&quot;level&quot;		=>	__('Membership Level','membership'),
    										&quot;expires&quot;	=>	__('Level Expires', 'membership')
    
    									);
    }else{
    					$columns = array(	&quot;username&quot; 	=> 	__('Username','membership'),
    										&quot;name&quot; 		=> 	__('Name','membership'),
    										&quot;email&quot; 	=> 	__('E-mail','membership'),
    										&quot;active&quot;	=>	__('Active','membership'),
    										&quot;sub&quot;		=>	__('Subscription','membership'),
    										&quot;level&quot;		=>	__('Membership Level','membership'),
    										&quot;expires&quot;	=>	__('Level Expires', 'membership'),
    										&quot;gateway&quot;	=>	__('Gateway', 'membership')
    
    									);
    }

    LMK if you have any other issues...

    Rob

  • digitsoft

    I was wrong...more than 10 lines....here they are broken down:

    All line numbers after 1836 are based on prior insertions.

    Inserted at line 1836:

    <?php
    $myrole = get_current_user_role();
    if ( $myrole <> 'Administrator')
    {
    ?>

    Inserted at line 1902:
    <?php }?>

    Inserted at line 1929:

    if ( $myrole == 'Administrator')
    {
    					$columns = array(	"username" 	=> 	__('Username','membership'),
    										"name" 		=> 	__('Name','membership'),
    										"email" 	=> 	__('E-mail','membership'),
    										"active"	=>	__('Active','membership'),
    										"sub"		=>	__('Subscription','membership'),
    										"level"		=>	__('Membership Level','membership'),
    										"expires"	=>	__('Level Expires', 'membership')
    
    									);
    }else{

    Inserted at line 1951:
    }

  • digitsoft

    Of course this won't work unless you insert this in the functions.php file, but assumed you had done so already.

    function get_current_user_role() {
            global $wp_roles;
            $current_user = wp_get_current_user();
            $roles = $current_user->roles;
            $role = array_shift($roles);
            return isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role] ) : false;
    }