mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
- fixed user update logic;
- checked and optimized um_role() function; - small changes and fixes for 2.0;
This commit is contained in:
@@ -278,11 +278,6 @@ if ( ! class_exists( 'Admin_Enqueue' ) ) {
|
||||
wp_register_style( 'um_admin_misc', $this->css_url . 'um-admin-misc.css' );
|
||||
wp_enqueue_style( 'um_admin_misc' );
|
||||
|
||||
if ( get_post_type() != 'shop_order' ) {
|
||||
wp_register_style( 'um_admin_select2', $this->css_url . 'um-admin-select2.css' );
|
||||
wp_enqueue_style( 'um_admin_select2' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2562,14 +2562,6 @@ if ( ! class_exists( 'Fields' ) ) {
|
||||
$res = apply_filters("um_view_field", $res, $data, $type );
|
||||
$res = apply_filters("um_view_field_value_{$type}", $res, $data );
|
||||
|
||||
|
||||
/* if ( $key == 'role_radio' || $key == 'role_select' ) {
|
||||
$role_meta = UM()->roles()->role_data( um_user( 'role' ) );
|
||||
if ( ! empty( $role_meta['is_custom'] ) ) {
|
||||
$res = 'UM ' . $res;
|
||||
}
|
||||
}*/
|
||||
|
||||
$output .= '<div class="um-field-area">';
|
||||
$output .= '<div class="um-field-value">' . $res . '</div>';
|
||||
$output .= '</div>';
|
||||
|
||||
@@ -437,7 +437,7 @@ if ( ! class_exists( 'REST_API' ) ) {
|
||||
break;
|
||||
|
||||
case 'role':
|
||||
$response['role'] = um_user('role');
|
||||
$response['role'] = um_user( 'role' );
|
||||
break;
|
||||
|
||||
case 'email':
|
||||
|
||||
@@ -63,6 +63,27 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if role is custom
|
||||
*
|
||||
* @param $role
|
||||
* @return bool
|
||||
*/
|
||||
function is_role_custom( $role ) {
|
||||
// User has roles so look for a UM Role one
|
||||
$role_keys = get_option( 'um_roles' );
|
||||
|
||||
if ( empty( $role_keys ) )
|
||||
return false;
|
||||
|
||||
$role_keys = array_map( function( $item ) {
|
||||
return 'um_' . $item;
|
||||
}, $role_keys );
|
||||
|
||||
return in_array( $role, $role_keys );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a user's main role
|
||||
*
|
||||
@@ -78,7 +99,6 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
|
||||
|
||||
// User exists
|
||||
if ( ! empty( $user ) ) {
|
||||
|
||||
// Get users old UM role
|
||||
$role = $this->um_get_user_role( $user_id );
|
||||
|
||||
@@ -89,7 +109,7 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
|
||||
// Users role is different than the new role
|
||||
|
||||
// Remove the old UM role
|
||||
if ( ! empty( $role ) )
|
||||
if ( ! empty( $role ) && $this->is_role_custom( $role ) )
|
||||
$user->remove_role( $role );
|
||||
|
||||
// Add the new role
|
||||
@@ -126,30 +146,28 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
|
||||
* @param int $user_id
|
||||
* @return bool|mixed
|
||||
*/
|
||||
function um_get_user_role( $user_id = 0 ) {
|
||||
function um_get_user_role( $user_id ) {
|
||||
$user = get_userdata( $user_id );
|
||||
$role = false;
|
||||
|
||||
if ( empty( $user->roles ) )
|
||||
return false;
|
||||
|
||||
// User has roles so look for a UM Role one
|
||||
if ( ! empty( $user->roles ) ) {
|
||||
$role_keys = get_option( 'um_roles' );
|
||||
$role_keys = get_option( 'um_roles' );
|
||||
|
||||
if ( empty( $role_keys ) )
|
||||
return array_shift( $user->roles );
|
||||
if ( empty( $role_keys ) )
|
||||
return array_shift( $user->roles );
|
||||
|
||||
$role_keys = array_map( function( $item ) {
|
||||
return 'um_' . $item;
|
||||
}, $role_keys );
|
||||
$role_keys = array_map( function( $item ) {
|
||||
return 'um_' . $item;
|
||||
}, $role_keys );
|
||||
|
||||
$roles = array_intersect( array_values( $user->roles ), $role_keys );
|
||||
if ( ! empty( $roles ) ) {
|
||||
$role = array_shift( $roles );
|
||||
} else {
|
||||
return array_shift( $user->roles );
|
||||
}
|
||||
$roles = array_intersect( array_values( $user->roles ), $role_keys );
|
||||
if ( ! empty( $roles ) ) {
|
||||
return array_shift( $roles );
|
||||
} else {
|
||||
return array_shift( $user->roles );
|
||||
}
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -556,7 +556,7 @@ if ( ! class_exists( 'Shortcodes' ) ) {
|
||||
|
||||
|
||||
|
||||
$current_user_role = um_user('role');
|
||||
$current_user_role = um_user( 'role' );
|
||||
|
||||
if( isset( $a['not'] ) && ! empty( $a['not'] ) && isset( $a['roles'] ) && ! empty( $a['roles'] ) ){
|
||||
return do_shortcode( $content );
|
||||
|
||||
@@ -62,10 +62,9 @@ if ( ! class_exists( 'User' ) ) {
|
||||
add_action( 'profile_update', array( &$this, 'profile_update' ), 10, 2 ); // user_id and old_user_data
|
||||
add_action( 'edit_user_profile_update', array( &$this, 'profile_update' ), 10, 1 );
|
||||
|
||||
|
||||
add_action( 'user_register', array( &$this, 'user_register_via_admin' ), 10, 1 );
|
||||
|
||||
add_action( 'user_register', array( &$this, 'set_gravatar' ), 11, 1 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -231,13 +230,13 @@ if ( ! class_exists( 'User' ) ) {
|
||||
|
||||
function profile_update( $user_id ) {
|
||||
// Bail if no user ID was passed
|
||||
|
||||
if ( empty( $user_id ) )
|
||||
return;
|
||||
|
||||
if ( ! empty( $_POST['um-role'] ) ) {
|
||||
if ( ! user_can( $user_id, $_POST['um-role'] ) )
|
||||
if ( ! user_can( $user_id, $_POST['um-role'] ) ) {
|
||||
UM()->roles()->set_role( $user_id, $_POST['um-role'] );
|
||||
}
|
||||
}
|
||||
|
||||
$this->remove_cache( $user_id );
|
||||
@@ -482,7 +481,8 @@ if ( ! class_exists( 'User' ) ) {
|
||||
|
||||
// add permissions
|
||||
$user_role = UM()->roles()->um_get_user_role( $this->id );
|
||||
$this->profile['role'] = ( strpos( $user_role, 'um_' ) === 0 ) ? str_replace( 'um_', '', $user_role ) : $user_role;
|
||||
//$this->profile['role'] = ( strpos( $user_role, 'um_' ) === 0 ) ? str_replace( 'um_', '', $user_role ) : $user_role;
|
||||
$this->profile['role'] = $user_role;
|
||||
|
||||
$role_meta = UM()->roles()->role_data( $user_role );
|
||||
$role_meta = apply_filters( 'um_user_permissions_filter', $role_meta, $this->id );
|
||||
|
||||
@@ -178,7 +178,7 @@
|
||||
$access_roles = unserialize( $access_roles );
|
||||
$access_roles = array_filter($access_roles);
|
||||
|
||||
if ( !empty( $access_roles ) && !in_array( um_user('role'), $access_roles ) ) {
|
||||
if ( ! empty( $access_roles ) && ! in_array( um_user( 'role' ), $access_roles ) ) {
|
||||
if ( empty( $access_redirect ) ) {
|
||||
if ( is_user_logged_in() ) {
|
||||
$access_redirect = site_url();
|
||||
@@ -307,8 +307,8 @@
|
||||
$access_roles = unserialize( $access_roles );
|
||||
$access_roles = array_filter($access_roles);
|
||||
|
||||
if ( !empty( $access_roles ) && !in_array( um_user('role'), $access_roles ) ) {
|
||||
if ( !$access_redirect ) {
|
||||
if ( ! empty( $access_roles ) && ! in_array( um_user( 'role' ), $access_roles ) ) {
|
||||
if ( ! $access_redirect ) {
|
||||
if ( is_user_logged_in() ) {
|
||||
$access_redirect = site_url();
|
||||
} else {
|
||||
|
||||
@@ -135,12 +135,12 @@
|
||||
}
|
||||
|
||||
|
||||
if( isset( $fields ) && ! empty( $fields ) ){
|
||||
foreach( $fields as $key => $array ) {
|
||||
if ( ! empty( $fields ) ) {
|
||||
foreach ( $fields as $key => $array ) {
|
||||
|
||||
if( isset( $array['public'] ) && -2 == $array['public'] && isset( $array['roles'] ) && ! empty( $array['roles'] ) && is_user_logged_in() ){
|
||||
if ( isset( $array['public'] ) && -2 == $array['public'] && ! empty( $array['roles'] ) && is_user_logged_in() ) {
|
||||
|
||||
if( ! in_array( um_user('role') , $array['roles'] ) ){
|
||||
if( ! in_array( um_user( 'role' ) , $array['roles'] ) ){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,8 +189,7 @@
|
||||
exit( wp_redirect( $args['redirect_to'] ) );
|
||||
}
|
||||
|
||||
$role = um_user( 'role' );
|
||||
$role_data = UM()->roles()->role_data( $role );
|
||||
$role_data = UM()->roles()->role_data( um_user( 'role' ) );
|
||||
|
||||
// Role redirect
|
||||
if ( empty( $role_data['after_login'] ) )
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
if ( $args['search'] == 1 && is_array( $search_filters ) ) { // search on
|
||||
|
||||
if ( isset( $args['roles_can_search'] ) && !empty( $args['roles_can_search'] ) && !in_array( um_user('role'), $args['roles_can_search'] ) ){
|
||||
if ( isset( $args['roles_can_search'] ) && ! empty( $args['roles_can_search'] ) && ! in_array( um_user( 'role' ), $args['roles_can_search'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@
|
||||
add_action('um_when_role_is_set', 'um_remove_prev_synced_wp_role');
|
||||
function um_remove_prev_synced_wp_role( $user_id ) {
|
||||
um_fetch_user( $user_id );
|
||||
$role = um_user('role');
|
||||
$meta = UM()->roles()->role_data( $role );
|
||||
$meta = UM()->roles()->role_data( um_user( 'role' ) );
|
||||
if ( isset( $meta['synced_role'] ) && $meta['synced_role'] ) {
|
||||
$wp_user_object = new WP_User( $user_id );
|
||||
$wp_user_object->remove_role( $meta['synced_role'] );
|
||||
|
||||
@@ -67,9 +67,7 @@
|
||||
|
||||
if ( UM()->roles()->um_user_can( 'can_view_all' ) && UM()->roles()->um_user_can( 'can_view_roles' ) ) {
|
||||
|
||||
$role = um_user( 'role' );
|
||||
|
||||
$permissions = UM()->roles()->role_data( $role );
|
||||
$permissions = UM()->roles()->role_data( um_user( 'role' ) );
|
||||
|
||||
if ( ! empty( $permissions['can_view_roles'] ) )
|
||||
$roles = maybe_unserialize( $permissions['can_view_roles'] );
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
case 2:
|
||||
if ( is_user_logged_in() && ! empty( $roles ) ) {
|
||||
$visible = in_array( um_user('role'), (array)$roles ) ? true : false;
|
||||
$visible = in_array( um_user( 'role' ), (array)$roles ) ? true : false;
|
||||
} else {
|
||||
$visible = is_user_logged_in() ? true : false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user