-
-
Save govindak/882626f4d935c7c38138 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'user_register', 'myplugin_registration_save', 10, 1 ); | |
function myplugin_registration_save( $user_id ) { | |
$current_admin_user = wp_get_current_user(); | |
if ( isset( $_POST['first_name'] ) ){ | |
$user = new WP_User( $user_id ); | |
$user_roles = $user->roles; | |
$user_role = array_shift($user_roles); | |
if($user_role!="administrator"){ | |
update_user_meta($user_id, 'asso_admin', $current_admin_user->ID); | |
}else{ | |
update_user_meta($user_id, 'asso_admin', $user_id); | |
} | |
} | |
} | |
add_action('pre_user_query','adminuser_pre_user_query'); | |
function adminuser_pre_user_query($user_search) { | |
if(is_admin()){ | |
$user = wp_get_current_user(); | |
if($user->ID!=1){ | |
global $wpdb; | |
$user_search->query_from .= "JOIN {$wpdb->usermeta} um ON um.user_id = {$wpdb->users}.ID AND um.meta_key = 'asso_admin'"; | |
$user_search->query_where = 'WHERE um.meta_value=' . $user->ID; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment