mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
- fixed fields privacy, editable and visibility attributes;
- fixed Verified Users license slug;
This commit is contained in:
@@ -1181,7 +1181,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
if ( in_array( $type, array( 'select', 'multiselect' ) ) && ! empty( $data['custom_dropdown_options_source'] ) ) {
|
||||
|
||||
if ( function_exists( $data['custom_dropdown_options_source'] ) ) {
|
||||
$arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
|
||||
if ( isset( $data['parent_dropdown_relationship'] ) ) {
|
||||
$arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
|
||||
} else {
|
||||
$arr_options = call_user_func( $data['custom_dropdown_options_source'] );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1877,13 +1881,57 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// forbidden in edit mode? 'edit_forbidden' - it's field attribute predefined in the field data in code
|
||||
if ( isset( $data['edit_forbidden'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// required option? 'required_opt' - it's field attribute predefined in the field data in code
|
||||
if ( isset( $data['required_opt'] ) ) {
|
||||
$opt = $data['required_opt'];
|
||||
if ( UM()->options()->get( $opt[0] ) != $opt[1] ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// required user permission 'required_perm' - it's field attribute predefined in the field data in code
|
||||
if ( isset( $data['required_perm'] ) ) {
|
||||
if ( ! UM()->roles()->um_user_can( $data['required_perm'] ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// fields that need to be disabled in edit mode (profile) (email, username, etc.)
|
||||
$arr_restricted_fields = $this->get_restricted_fields_for_edit( $_um_profile_id );
|
||||
if ( in_array( $key, $arr_restricted_fields ) && $this->editing == true && $this->set_mode == 'profile' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( $visibility == 'view' && $this->set_mode != 'register' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ( $visibility == 'view' && $this->set_mode == 'register' ) ||
|
||||
( isset( $data['editable'] ) && $data['editable'] == 0 && $this->set_mode == 'profile' )
|
||||
) {
|
||||
if ( ! um_can_view_field( $data ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! um_can_edit_field( $data ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
um_fetch_user( $_um_profile_id );
|
||||
|
||||
// do not show passwords
|
||||
if ( isset( UM()->user()->preview ) && UM()->user()->preview ) {
|
||||
if ( $data['type'] == 'password' ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Stop return empty values build field attributes:
|
||||
|
||||
if ( $visibility == 'view' && $this->set_mode == 'register' ) {
|
||||
|
||||
um_fetch_user( get_current_user_id() );
|
||||
if ( ! um_user( 'can_edit_everyone' ) ) {
|
||||
@@ -1905,49 +1953,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
$autocomplete = 'off';
|
||||
}
|
||||
|
||||
um_fetch_user( get_current_user_id() );
|
||||
if ( ! um_can_view_field( $data ) ) {
|
||||
return;
|
||||
}
|
||||
if ( ! um_can_edit_field( $data ) ) {
|
||||
return;
|
||||
}
|
||||
um_fetch_user( $_um_profile_id );
|
||||
|
||||
// fields that need to be disabled in edit mode (profile)
|
||||
$arr_restricted_fields = $this->get_restricted_fields_for_edit( $_um_profile_id );
|
||||
if ( in_array( $key, $arr_restricted_fields ) && $this->editing == true && $this->set_mode == 'profile' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// forbidden in edit mode?
|
||||
if ( isset( $data['edit_forbidden'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// required option
|
||||
if ( isset( $data['required_opt'] ) ) {
|
||||
$opt = $data['required_opt'];
|
||||
if ( UM()->options()->get( $opt[0] ) != $opt[1] ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// required user permission
|
||||
if ( isset( $data['required_perm'] ) ) {
|
||||
if ( ! um_user( $data['required_perm'] ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// do not show passwords
|
||||
if ( isset( UM()->user()->preview ) && UM()->user()->preview ) {
|
||||
if ( $data['type'] == 'password' ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
|
||||
@@ -105,7 +105,7 @@ if ( ! class_exists( 'um\core\Plugin_Updater' ) ) {
|
||||
'title' => 'User Tags',
|
||||
),
|
||||
'um-verified-users/um-verified-users.php' => array(
|
||||
'key' => 'verified_users',
|
||||
'key' => 'verified',
|
||||
'title' => 'Verified Users',
|
||||
),
|
||||
'um-woocommerce/um-woocommerce.php' => array(
|
||||
|
||||
@@ -236,7 +236,29 @@ function um_user_edit_profile( $args ) {
|
||||
|
||||
foreach ( $fields as $key => $array ) {
|
||||
|
||||
if ( ! um_can_edit_field( $array ) && isset( $array['editable'] ) && ! $array['editable'] ) {
|
||||
if ( ! isset( $array['type'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( isset( $array['edit_forbidden'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// required option? 'required_opt' - it's field attribute predefined in the field data in code
|
||||
if ( isset( $array['required_opt'] ) ) {
|
||||
$opt = $array['required_opt'];
|
||||
if ( UM()->options()->get( $opt[0] ) != $opt[1] ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// fields that need to be disabled in edit mode (profile) (email, username, etc.)
|
||||
$arr_restricted_fields = UM()->fields()->get_restricted_fields_for_edit( $user_id );
|
||||
if ( in_array( $key, $arr_restricted_fields ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! um_can_edit_field( $array ) || ! um_can_view_field( $array ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -314,10 +336,10 @@ function um_user_edit_profile( $args ) {
|
||||
|
||||
if ( isset( $array['type'] ) && in_array( $array['type'], array( 'image', 'file' ) ) ) {
|
||||
|
||||
if ( /*um_is_file_owner( UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . '/' . $args['submitted'][ $key ], um_user( 'ID' ) ) ||*/ um_is_temp_file( $args['submitted'][ $key ] ) || $args['submitted'][ $key ] == 'empty_file' ) {
|
||||
if ( um_is_temp_file( $args['submitted'][ $key ] ) || $args['submitted'][ $key ] == 'empty_file' ) {
|
||||
$files[ $key ] = $args['submitted'][ $key ];
|
||||
} elseif( um_is_file_owner( UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . '/' . $args['submitted'][ $key ], um_user( 'ID' ) ) ) {
|
||||
/*$files[ $key ] = 'empty_file';*/
|
||||
|
||||
} else {
|
||||
$files[ $key ] = 'empty_file';
|
||||
}
|
||||
@@ -1307,6 +1329,9 @@ function um_submit_form_profile( $args ) {
|
||||
return;
|
||||
}
|
||||
|
||||
UM()->fields()->set_mode = 'profile';
|
||||
UM()->fields()->editing = true;
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
|
||||
@@ -1347,6 +1347,7 @@ function um_is_on_edit_profile() {
|
||||
* @return bool
|
||||
*/
|
||||
function um_can_view_field( $data ) {
|
||||
$can_view = true;
|
||||
|
||||
if ( ! isset( UM()->fields()->set_mode ) ) {
|
||||
UM()->fields()->set_mode = '';
|
||||
@@ -1354,35 +1355,60 @@ function um_can_view_field( $data ) {
|
||||
|
||||
if ( isset( $data['public'] ) && UM()->fields()->set_mode != 'register' ) {
|
||||
|
||||
if ( ! is_user_logged_in() && $data['public'] != '1' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( is_user_logged_in() ) {
|
||||
$previous_user = um_user( 'ID' );
|
||||
um_fetch_user( get_current_user_id() );
|
||||
|
||||
$current_user_roles = um_user( 'roles' );
|
||||
um_fetch_user( $previous_user );
|
||||
}
|
||||
|
||||
if ( $data['public'] == '-3' && ! um_is_user_himself() && ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, $data['roles'] ) ) <= 0 ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! um_is_user_himself() && $data['public'] == '-1' && ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $data['public'] == '-2' && $data['roles'] ) {
|
||||
if ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, $data['roles'] ) ) <= 0 ) {
|
||||
return false;
|
||||
switch ( $data['public'] ) {
|
||||
case '1':
|
||||
$can_view = true;
|
||||
break;
|
||||
case '2':
|
||||
if ( ! is_user_logged_in() ) {
|
||||
$can_view = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '-1':
|
||||
if ( ! is_user_logged_in() ) {
|
||||
$can_view = false;
|
||||
} else {
|
||||
if ( ! um_is_user_himself() && ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
|
||||
$can_view = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '-2':
|
||||
if ( ! is_user_logged_in() ) {
|
||||
$can_view = false;
|
||||
} else {
|
||||
if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) && $data['roles'] ) {
|
||||
if ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, $data['roles'] ) ) <= 0 ) {
|
||||
$can_view = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '-3':
|
||||
if ( ! is_user_logged_in() ) {
|
||||
$can_view = false;
|
||||
} else {
|
||||
if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) && ! um_is_user_himself() && ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, $data['roles'] ) ) <= 0 ) ) {
|
||||
$can_view = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$can_view = apply_filters( 'um_can_view_field_custom', $can_view, $data );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return apply_filters( 'um_can_view_field', true, $data );
|
||||
return apply_filters( 'um_can_view_field', $can_view, $data );
|
||||
}
|
||||
|
||||
|
||||
@@ -1451,29 +1477,25 @@ function um_is_user_himself() {
|
||||
* @return bool
|
||||
*/
|
||||
function um_can_edit_field( $data ) {
|
||||
if (isset( UM()->fields()->editing ) && UM()->fields()->editing == true &&
|
||||
isset( UM()->fields()->set_mode ) && UM()->fields()->set_mode == 'profile'
|
||||
) {
|
||||
$can_edit = true;
|
||||
|
||||
if (is_user_logged_in() && isset( $data['editable'] ) && $data['editable'] == 0) {
|
||||
|
||||
if (isset( $data['public'] ) && $data['public'] == "-2") {
|
||||
return true;
|
||||
if ( ! empty( UM()->fields()->editing ) && isset( UM()->fields()->set_mode ) && UM()->fields()->set_mode == 'profile' ) {
|
||||
if ( ! is_user_logged_in() ) {
|
||||
$can_edit = false;
|
||||
} else {
|
||||
if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
|
||||
if ( isset( $data['editable'] ) && $data['editable'] == 0 ) {
|
||||
$can_edit = false;
|
||||
} else {
|
||||
if ( ! um_is_user_himself() ) {
|
||||
$can_edit = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (um_user( 'can_edit_everyone' )) return true;
|
||||
if (um_is_user_himself() && !um_user( 'can_edit_everyone' )) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!um_is_user_himself() && !UM()->roles()->um_user_can( 'can_edit_everyone' ))
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
return apply_filters( 'um_can_edit_field', $can_edit, $data );
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user