setup_actions();
}
/**
* Setup the admin hooks, actions and filters
*
* @return void
*/
function setup_actions() {
// Bail if in network admin
if ( is_network_admin() ) {
return;
}
// User profile edit/display actions
add_action( 'edit_user_profile', array($this, 'profile' ) );
add_action( 'show_user_profile', array( $this, 'profile' ) );
add_action( 'profile_update', array( $this, 'profile_update' ), 10, 2 );
}
function profile($profile_user){
if ( ! current_user_can( 'edit_user', $profile_user->ID ) || !current_user_can( 'manage_options') ) {
return;
} ?>
capbility_form( $profile_user );
do_action( 'wppm_user_profile', $profile_user );
wp_nonce_field( 'wppm_nonce', 'wppm_profile_nonce' );
}
protected function capbility_form( $user ) {
global $wppmfunction, $wpdb;
if ( user_can( $user->ID, 'manage_options' ) ) {
return;
}
if ( $user->ID == get_current_user_id() ) {
return;
}
$meta_value = get_user_meta( $user->ID, 'wppm_capability', true );
?>
update_user_capability( $user_id, $cap_key );
do_action( 'wppm_update_profile', $user_id, $prev_data );
}
function update_user_capability( $user_id, $cap_key ) {
global $wppmfunction,$wpdb;
if ( empty( $cap_key ) ) {
update_user_meta( $user_id, 'wppm_capability', '' );
$this->remove_capability( $user_id );
return;
}
update_user_meta( $user_id, 'wppm_capability', $cap_key );
$this->remove_capability( $user_id,$cap_key );
$this->add_capability( $user_id, $cap_key );
}
function remove_capability( $user_id ) {
global $wppmfunction,$wpdb;
$user = get_user_by( 'id', $user_id );
foreach ( $wppmfunction->wppm_user_role() as $meta_key => $label ) {
$user->remove_cap( $meta_key );
}
}
function add_capability( $user_id, $cap_key ) {
global $wppmfunction,$wpdb;
$user = get_user_by( 'id', $user_id );
$user_cap_slug = $wppmfunction->wppm_user_role();
foreach($user_cap_slug as $key=>$val){
if($cap_key== $key){
$user->add_cap($key );
}
}
$user->add_cap( $cap_key );
}
}
endif;
new WPPM_profile_update();