- fixed fields privacy, editable and visibility attributes;

- fixed Verified Users license slug;
This commit is contained in:
nikitasinelnikov
2019-11-18 17:01:40 +02:00
parent 856cb8492a
commit 774ac88c74
4 changed files with 138 additions and 84 deletions
+52 -45
View File
@@ -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
*
+1 -1
View File
@@ -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(
+28 -3
View File
@@ -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
*