diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 4deaee47..42e6f21d 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -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 * diff --git a/includes/core/class-plugin-updater.php b/includes/core/class-plugin-updater.php index 78cc33ed..e90f1193 100644 --- a/includes/core/class-plugin-updater.php +++ b/includes/core/class-plugin-updater.php @@ -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( diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php index 83f110a4..8a4505f6 100644 --- a/includes/core/um-actions-profile.php +++ b/includes/core/um-actions-profile.php @@ -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 * diff --git a/includes/um-short-functions.php b/includes/um-short-functions.php index 0d50cfc8..c38a9f7a 100644 --- a/includes/um-short-functions.php +++ b/includes/um-short-functions.php @@ -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 ); }