WordPress.org

Ready to get started?Download WordPress

Forums

subadmin subsite-user edit hack/fix (2 posts)

  1. mortydot
    Member
    Posted 2 years ago #

    Hi all,

    I'm working on a hack/(my opinion)fix for user editing rights for subsite-admin's. All working with wordpress multisite should have noticed that only a super-admin can edit users.

    In my case I would like that a subsite-admin is also edit to edit his own subsite-members. Therefore I found/created this code for a plugin:

    function mc_admin_users_caps( $caps, $cap, $user_id, $args ){
    	foreach( $caps as $key => $capability ){
    
    		if( $capability != 'do_not_allow' )
    			continue;
    
    		switch( $cap ) {
    			case 'edit_user':
    			case 'edit_users':
    				$caps[$key] = 'edit_users';
    				break;
    			case 'delete_user':
    			case 'delete_users':
    				$caps[$key] = 'delete_users';
    				break;
    			case 'create_users':
    				$caps[$key] = $cap;
    				break;
    		}
    	}
    	return $caps;
    }
    add_filter( 'map_meta_cap', 'mc_admin_users_caps', 10, 4 );
    add_filter( 'enable_edit_any_user_configuration', '__return_true'); // '__return_true' is a WordPress API function in wp-includes/functions.php

    This makes it possible for a subsite admin to edit his users.
    But I'm missing the check if the 'editable'subsite-user is also a member of the subsite the subsite-admin is logged into!

    Anyone any suggestions how to check if the editable user is member of current subsite?

  2. All working with wordpress multisite should have noticed that only a super-admin can edit users.

    This is because users are network wide, and site-admins being able to edit network things is not permitted.

    Not a bug.

    Check http://codex.wordpress.org/WPMU_Functions/is_user_member_of_blog for if the editable user is member of current subsite

Topic Closed

This topic has been closed to new replies.

About this Topic