- fixed default avatar URL for sites at subfolder;

- user registration optimization (removed edit profile handlers on user registration);
- fixed "can edit" checkbox at Forms add field modal window;
This commit is contained in:
nikitozzzzzzz
2017-08-31 15:05:27 +03:00
parent 1f5bf3dafc
commit 026b783a24
9 changed files with 106 additions and 205 deletions
+1 -1
View File
@@ -1896,7 +1896,7 @@ if ( ! class_exists( 'Admin_Metabox' ) ) {
<div class="um-admin-tri">
<p><label for="_editable">Can user edit this field? <?php UM()->tooltip( __( 'This option allows you to set whether or not the user can edit the information in this field.', 'ultimate-member' ) ); ?></label>
<input type="checkbox" name="_editable" id="_editable" value="1" <?php checked( isset( $this->edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> />
<input type="checkbox" name="_editable" id="_editable" value="1" <?php checked( null === $this->edit_mode_value || $this->edit_mode_value ) ?> />
</p>
</div>
+4 -4
View File
@@ -990,11 +990,11 @@ if ( ! empty( $um_roles ) ) {
$all_users = get_users( $args );
//update roles for users
foreach ( $all_users as $k => $user ) {
$user_roleID = get_user_meta( $user->ID, 'role', true );
$role_slug = get_user_meta( $user->ID, 'role', true );
if ( ! empty( $user_roleID ) ) {
$userdata = get_userdata( $user->ID );
$userdata->add_role( 'um_' . $user_roleID );
if ( ! empty( $role_slug ) ) {
$user_object = get_userdata( $user->ID );
$user_object->add_role( 'um_' . $role_slug );
}
}
}
+1
View File
@@ -8,6 +8,7 @@ if ( ! class_exists( 'Form' ) ) {
class Form {
public $form_suffix;
var $form_id;
function __construct() {
+3 -62
View File
@@ -72,7 +72,7 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
* @uses apply_filters() Calls 'um_set_user_role' with the role and user id
* @return string
*/
function set_um_user_role( $user_id = 0, $new_role = '' ) {
function set_role( $user_id, $new_role = '' ) {
// Validate user id
$user = get_userdata( $user_id );
@@ -103,9 +103,9 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
UM()->user()->profile['role'] = $new_role;
do_action('um_member_role_upgrade', $role, UM()->user()->profile['role'] );
do_action( 'um_member_role_upgrade', $role, UM()->user()->profile['role'] );
UM()->user()->update_usermeta_info('role');
UM()->user()->update_usermeta_info( 'role' );
do_action('um_after_user_role_is_changed');
@@ -281,64 +281,5 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
return true;
return false;
}
/*
/**
* @param $cap
* @param bool $value
* @param string $struct
* @return bool
*
function current_user_can( $cap, $value = true, $struct = 'string' ) {
if ( ! is_user_logged_in() )
return false;
$user_id = get_current_user_id();
return $this->user_can( $user_id, $cap, $value, $struct );
}
/**
* @param $user_id
* @param $cap
* @param bool $value
* @param string $struct
* @return bool
*
function user_can( $user_id, $cap, $value = true, $struct = 'string' ) {
$role = $this->um_get_user_role( $user_id );
$role_meta = $this->role_data( $role );
$role_meta = apply_filters( 'um_user_permissions_filter', $role_meta, $user_id );
/* $um_roles = get_option( 'um_roles' );
$um_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $um_roles );
$user_meta = get_userdata( $user_id );
$user_roles = $user_meta->roles;
$user_um_role = array_intersect( $um_roles, $user_roles );
if ( ! count( $user_um_role ) )
return false;
$user_um_role = $user_um_role[0];
$role_meta = get_option( "um_role_" . substr( $user_um_role, 3 ) . "_meta" );*
if ( empty( $role_meta[$cap] ) )
return false;
if ( $struct == 'array' ) {
if ( is_array( $role_meta[$cap] ) && ! in_array( $value, $role_meta[$cap] ) )
return false;
} else {
if ( $role_meta[$cap] != $value )
return false;
}
return true;
}*/
}
}
+23 -9
View File
@@ -64,6 +64,8 @@ if ( ! class_exists( 'User' ) ) {
add_action( 'user_register', array( &$this, 'user_register_via_admin' ), 10, 1 );
add_action( 'user_register', array( &$this, 'set_gravatar' ), 11, 1 );
}
@@ -212,11 +214,16 @@ if ( ! class_exists( 'User' ) ) {
if ( empty( $user_id ) )
return;
if ( is_admin() ) {
//if there custom 2 role not empty
if ( ! empty( $_POST['um-role'] ) ) {
$user = get_userdata( $user_id );
$user->add_role( $_POST['um-role'] );
UM()->user()->profile['role'] = $_POST['um-role'];
UM()->user()->update_usermeta_info( 'role' );
}
do_action( 'um_after_new_user_register', $user_id, $_POST );
do_action( 'um_user_register', $user_id, $_POST );
}
}
@@ -230,7 +237,7 @@ if ( ! class_exists( 'User' ) ) {
if ( ! empty( $_POST['um-role'] ) ) {
if ( ! user_can( $user_id, $_POST['um-role'] ) )
UM()->roles()->set_um_user_role( $user_id, $_POST['um-role'] );
UM()->roles()->set_role( $user_id, $_POST['um-role'] );
}
$this->remove_cache( $user_id );
@@ -311,7 +318,7 @@ if ( ! class_exists( 'User' ) ) {
*** @Remove cached queue from Users backend
***/
function remove_cached_queue() {
delete_option('um_cached_users_queue');
delete_option( 'um_cached_users_queue' );
}
/***
@@ -1029,6 +1036,7 @@ if ( ! class_exists( 'User' ) ) {
}
/***
*** @update profile
***/
@@ -1187,6 +1195,8 @@ if ( ! class_exists( 'User' ) ) {
return $user_id;
}
}
/**
* @function user_exists_by_email_as_username()
*
@@ -1224,19 +1234,23 @@ if ( ! class_exists( 'User' ) ) {
return $user_id;
}
/**
* Set gravatar hash id
*
* @param $user_id
* @return string
*/
function set_gravatar( $user_id ){
function set_gravatar( $user_id ) {
um_fetch_user( $user_id );
$email_address = um_user('user_email');
$email_address = um_user( 'user_email' );
$hash_email_address = '';
if( $email_address ){
if ( $email_address ) {
$hash_email_address = md5( $email_address );
$this->profile['synced_gravatar_hashed_id'] = $hash_email_address;
$this->update_usermeta_info('synced_gravatar_hashed_id');
$this->update_usermeta_info( 'synced_gravatar_hashed_id' );
}
return $hash_email_address;
+5 -5
View File
@@ -556,13 +556,13 @@
/***
*** @form processing
***/
add_action('um_submit_form_profile', 'um_submit_form_profile', 10);
function um_submit_form_profile($args){
add_action( 'um_submit_form_profile', 'um_submit_form_profile', 10 );
function um_submit_form_profile( $args ) {
if ( !isset( UM()->form()->errors) ) do_action('um_user_edit_profile', $args);
do_action('um_user_profile_extra_hook', $args );
if ( isset( UM()->form()->errors ) )
return false;
do_action( 'um_user_edit_profile', $args );
}
/***
+54 -113
View File
@@ -28,62 +28,41 @@
um_fetch_user( $user_id );
UM()->user()->pending();
}
/**
* After adding a new user
* After insert a new user
* run at frontend and backend
*
* @param $user_id
* @param $args
*/
add_action( 'um_after_new_user_register', 'um_after_new_user_register', 10, 2 );
function um_after_new_user_register( $user_id, $args ) {
global $pagenow;
function um_after_insert_user( $user_id, $args ) {
//clear Users cached queue
UM()->user()->remove_cached_queue();
um_fetch_user( $user_id );
if ( ! isset( $args['role'] ) )
$args['role'] = get_option( 'default_role', true );
if ( $pagenow != 'user-new.php' && ! array_key_exists( $args['role'], UM()->roles()->get_roles( false, array( 'admin' ) ) ) )
$args['role'] = get_option( 'default_role', true );
if ( ! user_can( $user_id, $args['role'] ) )
UM()->roles()->set_um_user_role( $user_id, $args['role'] );
if ( ! empty( $args['submitted'] ) )
if ( ! empty( $args['submitted'] ) ) {
um_fetch_user( $user_id );
UM()->user()->set_registration_details( $args['submitted'] );
}
//UM()->user()->set_last_login();
UM()->user()->remove_cached_queue();
do_action( 'um_post_registration_save', $user_id, $args );
//send notification about registration
do_action( 'um_post_registration_listener', $user_id, $args );
do_action( 'um_post_registration', $user_id, $args );
do_action( 'um_registration_set_extra_data', $user_id, $args );
//redirects handlers at 100 priority, you can add some info before redirects
//after complete UM user registration
do_action( 'um_registration_complete', $user_id, $args );
}
/**
* Update user's profile after registration
*/
add_action( 'um_post_registration_save', 'um_post_registration_save', 10, 2 );
function um_post_registration_save( $user_id, $args ) {
unset( $args['user_id'] );
$args['_user_id'] = $user_id;
$args['is_signup'] = 1;
do_action( 'um_user_edit_profile', $args );
}
add_action( 'um_user_register', 'um_after_insert_user', 10, 2 );
/**
* Post-registration admin listener
*/
add_action('um_post_registration_listener', 'um_post_registration_listener', 10, 2);
function um_post_registration_listener( $user_id, $args ) {
/**
* Send notification about registration
*
* @param $user_id
* @param $args
*/
function um_send_registration_notification( $user_id, $args ) {
um_fetch_user( $user_id );
if ( um_user( 'status' ) != 'pending' ) {
@@ -91,40 +70,19 @@
} else {
UM()->mail()->send( um_admin_email(), 'notification_review', array( 'admin' => true ) );
}
}
add_action( 'um_registration_complete', 'um_send_registration_notification', 10, 2 );
/**
* Post-registration procedure
*/
add_action('um_post_registration', 'um_post_registration', 10, 2);
function um_post_registration( $user_id, $args ) {
unset( $args['user_id'] );
extract( $args );
/**
* Check user status and redirect it after registration
*
* @param $user_id
* @param $args
*/
function um_check_user_status( $user_id, $args ) {
$status = um_user( 'status' );
/*
* maybe in future
* if ( ! is_admin() ) {
um_fetch_user( $user_id );
$user_roles = UM()->roles()->um_get_user_role( $user_id );
var_dump( $user_roles );
$role_meta = UM()->roles()->role_data( $user_roles );
var_dump( $role_meta );
if ( $role_meta['_um_status'] == 'approved' ) {
UM()->user()->approve();
} elseif ( $role_meta['_um_status'] == 'checkmail' ) {
UM()->user()->email_pending();
} elseif ( $role_meta['_um_status'] == 'pending' ) {
UM()->user()->pending();
}
$status = um_user( 'status' );
}*/
do_action( "um_post_registration_{$status}_hook", $user_id, $args );
if ( ! is_admin() ) {
@@ -164,7 +122,7 @@
$url = UM()->permalinks()->get_current_url();
$url = add_query_arg( 'message', esc_attr( $status ), $url );
$url = add_query_arg( 'um_role', esc_attr( um_user( 'role' ) ), $url );
$url = add_query_arg( 'um_form_id', esc_attr( $form_id ), $url );
$url = add_query_arg( 'um_form_id', esc_attr( $args['form_id'] ), $url );
exit( wp_redirect( $url ) );
}
@@ -174,18 +132,24 @@
}
}
add_action( 'um_registration_complete', 'um_check_user_status', 100, 2 );
/**
* New user registration
* Registration form submit handler
*
* @param $args
* @return bool|int|WP_Error
*/
add_action( 'um_user_registration', 'um_user_registration', 10 );
function um_user_registration( $args ) {
unset( $args['user_id'] );
function um_submit_form_register( $args ) {
if ( isset( UM()->form()->errors ) )
return false;
$args = apply_filters( 'um_add_user_frontend_submitted', $args );
extract( $args );
if ( isset( $username ) && ! isset( $args['user_login'] ) ) {
if ( isset( $username ) && ! isset( $user_login ) ) {
$user_login = $username;
}
@@ -227,29 +191,22 @@
$user_password = UM()->validation()->generate( 8 );
}
if ( ! isset( $user_email ) ) {
$site_url = @$_SERVER['SERVER_NAME'];
$user_email = 'nobody' . $unique_userID . '@' . $site_url;
$user_email = apply_filters( "um_user_register_submitted__email", $user_email );
$user_email = apply_filters( 'um_user_register_submitted__email', $user_email );
}
$creds['user_login'] = $user_login;
$creds['user_password'] = $user_password;
$creds['user_email'] = trim( $user_email );
$credentials = array(
'user_login' => $user_login,
'user_password' => $user_password,
'user_email' => trim( $user_email ),
);
$args = apply_filters('um_add_user_frontend_submitted', $args );
$args['submitted'] = array_merge( $args['submitted'], $creds );
$args = array_merge( $args, $creds );
unset( $args['user_id'] );
do_action( 'um_before_new_user_register', $args );
$args['submitted'] = array_merge( $args['submitted'], $credentials );
$args = array_merge( $args, $credentials );
$user_role = UM()->form()->assigned_role( UM()->form()->form_id );
/* if ( empty( $default_role ) )
$default_role = get_option( 'default_role' );*/
$userdata = array(
'user_login' => $user_login,
@@ -259,20 +216,12 @@
);
$user_id = wp_insert_user( $userdata );
do_action( 'um_after_new_user_register', $user_id, $args );
do_action( 'um_user_register', $user_id, $args );
return $user_id;
}
/**
* Form Processing
*/
add_action( 'um_submit_form_register', 'um_submit_form_register', 10 );
function um_submit_form_register( $args ) {
if ( ! isset( UM()->form()->errors ) )
do_action( 'um_user_registration', $args );
}
/**
* Register user with predefined role in options
@@ -346,12 +295,4 @@
function um_add_register_fields($args){
echo UM()->fields()->display( 'register', $args );
}
/**
* Set user gravatar with user_email
*/
add_action('user_register','um_user_register_generate_gravatar');
function um_user_register_generate_gravatar( $user_id ){
UM()->user()->set_gravatar( $user_id );
}
}
-2
View File
@@ -98,8 +98,6 @@
*** @checks if user can access the backend
***/
function um_block_wpadmin_by_user_role() {
/*var_dump( is_admin() && ! defined('DOING_AJAX') && um_user( 'ID' ) && ! um_user( 'can_access_wpadmin' ) && ! is_super_admin( um_user('ID') ) );
exit;*/
if ( is_admin() && ! defined('DOING_AJAX') && um_user( 'ID' ) && ! um_user( 'can_access_wpadmin' ) && ! is_super_admin( um_user('ID') ) ) {
um_redirect_home();
}
+15 -9
View File
@@ -1360,10 +1360,13 @@
return $uri;
}
/***
*** @default avatar
***/
function um_get_default_avatar_uri( $user_id = '' ) {
/**
* Default avatar URL
*
* @return string
*/
function um_get_default_avatar_uri() {
$uri = um_get_option( 'default_avatar' );
$uri = ! empty( $uri['url'] ) ? $uri['url'] : '';
if ( ! $uri ) {
@@ -1372,15 +1375,18 @@
//http <-> https compatibility default avatar option of SSL was changed
$url_array = parse_url( $uri );
$setting_url = $url_array['scheme'] . '://' . $url_array['host'];
if ( $setting_url != site_url() )
$uri = str_replace( $setting_url, site_url(), $uri );
}
if ( is_ssl() && $url_array['scheme'] == 'http' ) {
$uri = str_replace( 'http://', 'https://', $uri );
} elseif ( ! is_ssl() && $url_array['scheme'] == 'https' ) {
$uri = str_replace( 'https://', 'http://', $uri );
}
}
return $uri;
}
/***
*** @get user avatar url
***/
@@ -1616,7 +1622,7 @@
} elseif( um_user('synced_profile_photo') ){
$avatar_uri = um_user('synced_profile_photo');
} else {
$avatar_uri = um_get_default_avatar_uri( um_user('ID') );
$avatar_uri = um_get_default_avatar_uri();
}
$avatar_uri = apply_filters('um_user_avatar_url_filter', $avatar_uri, um_user('ID') );