diff --git a/assets/js/um-scripts.js b/assets/js/um-scripts.js index 6761cd6a..4a24e4ae 100644 --- a/assets/js/um-scripts.js +++ b/assets/js/um-scripts.js @@ -79,7 +79,7 @@ function um_init_datetimepicker() { function init_tipsy() { - if( typeof(jQuery.fn.tipsy) === "function" ){ + if ( typeof( jQuery.fn.tipsy ) === "function" ) { jQuery('.um-tip-n').tipsy({gravity: 'n', opacity: 1, live: 'a.live', offset: 3 }); jQuery('.um-tip-w').tipsy({gravity: 'w', opacity: 1, live: 'a.live', offset: 3 }); jQuery('.um-tip-e').tipsy({gravity: 'e', opacity: 1, live: 'a.live', offset: 3 }); diff --git a/includes/admin/core/class-admin-builder.php b/includes/admin/core/class-admin-builder.php index 313972fd..2831816f 100644 --- a/includes/admin/core/class-admin-builder.php +++ b/includes/admin/core/class-admin-builder.php @@ -898,7 +898,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Builder' ) ) { continue; } ?> - data-silent_action="um_admin_add_field_from_list" data-arg1="" data-arg2=""> () + data-silent_action="um_admin_add_field_from_list" data-arg1="" data-arg2="" title=""> () js_url . 'um-admin-role-wrapper.js', array( 'jquery' ), ultimatemember_version, true ); - $localize_roles_data = get_option( 'um_roles' ); + $localize_roles_data = get_option( 'um_roles', array() ); wp_localize_script( 'um_admin_role_wrapper', 'um_roles', (array) $localize_roles_data ); wp_enqueue_script( 'um_admin_role_wrapper' ); } @@ -441,7 +441,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_set_script_translations( 'um_block_js', 'ultimate-member' ); $restrict_options = array(); - $roles = UM()->roles()->get_roles( false, array( 'administrator' ) ); + $roles = UM()->roles()->get_roles( false ); if ( ! empty( $roles ) ) { foreach ( $roles as $role_key => $title ) { $restrict_options[] = array( diff --git a/includes/admin/core/class-admin-metabox.php b/includes/admin/core/class-admin-metabox.php index 8773ee3b..037f0ed3 100644 --- a/includes/admin/core/class-admin-metabox.php +++ b/includes/admin/core/class-admin-metabox.php @@ -40,6 +40,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) { function __construct() { $this->in_edit = false; $this->edit_mode_value = null; + $this->edit_array = []; add_action( 'admin_head', array( &$this, 'admin_head' ), 9); add_action( 'admin_footer', array( &$this, 'load_modal_content' ), 9); @@ -404,7 +405,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) { 'type' => 'multi_checkbox', 'label' => __( 'Select which roles can access this content', 'ultimate-member' ), 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), - 'options' => UM()->roles()->get_roles( false, array( 'administrator' ) ), + 'options' => UM()->roles()->get_roles( false ), 'columns' => 3, 'conditional' => array( '_um_accessible', '=', '2' ) ), @@ -558,7 +559,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) { 'label' => __( 'Select which roles can access this content', 'ultimate-member' ), 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), 'value' => $_um_access_roles_value, - 'options' => UM()->roles()->get_roles( false, array( 'administrator' ) ), + 'options' => UM()->roles()->get_roles( false ), 'columns' => 3, 'conditional' => array( '_um_accessible', '=', '2' ) ), @@ -1233,7 +1234,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) { if ( $this->in_edit == true ) { // we're editing a field $real_attr = substr( $attribute, 1 ); - $this->edit_mode_value = (isset( $this->edit_array[ $real_attr ] ) ) ? $this->edit_array[ $real_attr ] : null; + $this->edit_mode_value = isset( $this->edit_array[ $real_attr ] ) ? $this->edit_array[ $real_attr ] : null; } switch ( $attribute ) { diff --git a/includes/admin/core/list-tables/roles-list-table.php b/includes/admin/core/list-tables/roles-list-table.php index 00b25ff2..31e94f5e 100644 --- a/includes/admin/core/list-tables/roles-list-table.php +++ b/includes/admin/core/list-tables/roles-list-table.php @@ -27,7 +27,7 @@ if ( isset( $_GET['action'] ) ) { um_js_redirect( $redirect ); } - $um_roles = get_option( 'um_roles' ); + $um_roles = get_option( 'um_roles', array() ); $um_custom_roles = array(); foreach ( $role_keys as $k => $role_key ) { @@ -426,7 +426,7 @@ $ListTable->set_sortable_columns( array( $users_count = count_users(); $roles = array(); -$role_keys = get_option( 'um_roles' ); +$role_keys = get_option( 'um_roles', array() ); if ( $role_keys ) { foreach ( $role_keys as $role_key ) { diff --git a/includes/admin/templates/access/restrict_content.php b/includes/admin/templates/access/restrict_content.php index 170e8eb9..ce0d62c1 100644 --- a/includes/admin/templates/access/restrict_content.php +++ b/includes/admin/templates/access/restrict_content.php @@ -73,7 +73,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; 'label' => __( 'Select which roles can access this content', 'ultimate-member' ), 'tooltip' => __( 'Activate content restriction for this post', 'ultimate-member' ), 'value' => $_um_access_roles_value, - 'options' => UM()->roles()->get_roles( false, array( 'administrator' ) ), + 'options' => UM()->roles()->get_roles( false ), 'columns' => 3, 'conditional' => array( '_um_accessible', '=', '2' ) ), diff --git a/includes/admin/templates/role/role-edit.php b/includes/admin/templates/role/role-edit.php index ced3cbd0..497b2bd8 100644 --- a/includes/admin/templates/role/role-edit.php +++ b/includes/admin/templates/role/role-edit.php @@ -117,7 +117,7 @@ if ( ! empty( $_POST['role'] ) ) { if ( '' == $error ) { if ( 'add' == sanitize_key( $_GET['tab'] ) ) { - $roles = get_option( 'um_roles' ); + $roles = get_option( 'um_roles', array() ); $roles[] = $id; update_option( 'um_roles', $roles ); diff --git a/includes/core/class-builtin.php b/includes/core/class-builtin.php index ed11148d..7f279366 100644 --- a/includes/core/class-builtin.php +++ b/includes/core/class-builtin.php @@ -633,7 +633,7 @@ if ( ! class_exists( 'um\core\Builtin' ) ) { function set_predefined_fields() { global $wp_roles; - $role_keys = get_option( 'um_roles' ); + $role_keys = get_option( 'um_roles', array() ); if ( ! empty( $role_keys ) && is_array( $role_keys ) ) { $role_keys = array_map( function( $item ) { return 'um_' . $item; diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 33ed449a..c9df9984 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -568,7 +568,13 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $label = apply_filters( 'um_edit_label_all_fields', $label, $data ); } - $output .= ''; + $fields_without_metakey = UM()->builtin()->get_fields_without_metakey(); + $for_attr = ''; + if ( ! in_array( $data['type'], $fields_without_metakey ) ) { + $for_attr = ' for="' . esc_attr( $key . UM()->form()->form_suffix ) . '"'; + } + + $output .= '' . __( $label, 'ultimate-member' ) . ''; if ( ! empty( $data['help'] ) && $this->viewing == false && ! strstr( $key, 'confirm_user_pass' ) ) { @@ -978,7 +984,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { if ( strstr( $key, 'role_' ) || $key == 'role' ) { $field_value = strtolower( UM()->roles()->get_editable_priority_user_role( um_user( 'ID' ) ) ); - $role_keys = get_option( 'um_roles' ); + $role_keys = get_option( 'um_roles', array() ); if ( ! empty( $role_keys ) ) { if ( in_array( $field_value, $role_keys ) ) { @@ -1125,7 +1131,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { if ( strstr( $key, 'role_' ) || $key == 'role' ) { $um_user_value = strtolower( UM()->roles()->get_editable_priority_user_role( um_user( 'ID' ) ) ); - $role_keys = get_option( 'um_roles' ); + $role_keys = get_option( 'um_roles', array() ); if ( ! empty( $role_keys ) ) { if ( in_array( $um_user_value, $role_keys ) ) { @@ -1443,7 +1449,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $array['conditional'] = null; } - $array['classes'] .= ' um-field-' . esc_attr( $key ); + $fields_without_metakey = UM()->builtin()->get_fields_without_metakey(); + + if ( ! in_array( $array['type'], $fields_without_metakey ) ) { + $array['classes'] .= ' um-field-' . esc_attr( $key ); + } $array['classes'] .= ' um-field-' . esc_attr( $array['type'] ); $array['classes'] .= ' um-field-type_' . esc_attr( $array['type'] ); @@ -4059,9 +4069,10 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $_field_value = $this->field_value( $key, $default, $data ); - if ( ! isset( $_field_value ) || $_field_value == '' ) { + if ( ! in_array( $type, $fields_without_metakey ) && ( ! isset( $_field_value ) || $_field_value == '' ) ) { $output = ''; } else { + $output .= '
get_atts( $key, $classes, $conditional, $data ) . '>'; if ( isset( $data['label'] ) || ! empty( $data['icon'] ) ) { @@ -4126,11 +4137,20 @@ if ( ! class_exists( 'um\core\Fields' ) ) { */ $res = apply_filters( "um_view_field_value_{$type}", $res, $data ); - $output .= '
'; - $output .= '
' . $res . '
'; - $output .= '
'; + $id_attr = ''; + if ( ! in_array( $type, $fields_without_metakey ) ) { + $id_attr = ' id="' . esc_attr( $key . UM()->form()->form_suffix ) . '"'; + } - $output .= '
'; + if ( empty( $res ) ) { + $output = ''; + } else { + $output .= '
'; + $output .= '
' . $res . '
'; + $output .= '
'; + + $output .= ''; + } } break; @@ -4665,6 +4685,13 @@ if ( ! class_exists( 'um\core\Fields' ) ) { ) ); + $fields_without_metakey = UM()->builtin()->get_fields_without_metakey(); + + if ( in_array( $data['type'], $fields_without_metakey ) ) { + unset( $field_atts['id'] ); + unset( $field_atts['data-key'] ); + } + if ( ! empty( $field_style ) && is_array( $field_style ) ) { $arr_inline_style = ''; diff --git a/includes/core/class-profile.php b/includes/core/class-profile.php index 84d6e205..1cffe05c 100644 --- a/includes/core/class-profile.php +++ b/includes/core/class-profile.php @@ -385,6 +385,8 @@ if ( ! class_exists( 'um\core\Profile' ) ) { function show_meta( $array ) { $output = ''; + $fields_without_metakey = UM()->builtin()->get_fields_without_metakey(); + if ( ! empty( $array ) ) { foreach ( $array as $key ) { if ( $key ) { @@ -396,8 +398,9 @@ if ( ! class_exists( 'um\core\Profile' ) ) { $data['in_profile_meta'] = true; $value = um_filtered_value( $key, $data ); - if ( ! $value ) + if ( ! $value && ! in_array( $data['type'], $fields_without_metakey ) ) { continue; + } if ( ! UM()->options()->get( 'profile_show_metaicon' ) ) { $icon = ''; diff --git a/includes/core/class-roles-capabilities.php b/includes/core/class-roles-capabilities.php index 60102c26..233e7cec 100644 --- a/includes/core/class-roles-capabilities.php +++ b/includes/core/class-roles-capabilities.php @@ -32,7 +32,7 @@ if ( ! class_exists( 'um\core\Roles_Capabilities' ) ) { function um_on_roles_update( $option, $old_value, $value ) { global $wp_roles; - if ( isset( $wp_roles->role_key ) && $option == $wp_roles->role_key ) { + if ( is_object( $wp_roles ) && isset( $wp_roles->role_key ) && $option == $wp_roles->role_key ) { foreach ( $value as $role_key => $role_data ) { $role_keys = get_option( 'um_roles', array() ); $role_keys = array_map( function( $item ) { @@ -126,10 +126,11 @@ if ( ! class_exists( 'um\core\Roles_Capabilities' ) ) { */ function is_role_custom( $role ) { // User has roles so look for a UM Role one - $role_keys = get_option( 'um_roles' ); + $role_keys = get_option( 'um_roles', array() ); - if ( empty( $role_keys ) ) + if ( empty( $role_keys ) ) { return false; + } $role_keys = array_map( function( $item ) { return 'um_' . $item; @@ -385,7 +386,7 @@ if ( ! class_exists( 'um\core\Roles_Capabilities' ) ) { return false; // User has roles so look for a UM Role one - $um_roles_keys = get_option( 'um_roles' ); + $um_roles_keys = get_option( 'um_roles', array() ); if ( ! empty( $um_roles_keys ) ) { $um_roles_keys = array_map( function( $item ) { @@ -453,7 +454,7 @@ if ( ! class_exists( 'um\core\Roles_Capabilities' ) ) { return false; // User has roles so look for a UM Role one - $um_roles_keys = get_option( 'um_roles' ); + $um_roles_keys = get_option( 'um_roles', array() ); if ( ! empty( $um_roles_keys ) ) { $um_roles_keys = array_map( function( $item ) { @@ -495,15 +496,17 @@ if ( ! class_exists( 'um\core\Roles_Capabilities' ) ) { */ function get_um_user_role( $user_id ) { // User has roles so look for a UM Role one - $um_roles_keys = get_option( 'um_roles' ); + $um_roles_keys = get_option( 'um_roles', array() ); - if ( empty( $um_roles_keys ) ) + if ( empty( $um_roles_keys ) ) { return false; + } $user = get_userdata( $user_id ); - if ( empty( $user->roles ) ) + if ( empty( $user->roles ) ) { return false; + } $um_roles_keys = array_map( function( $item ) { return 'um_' . $item; @@ -511,8 +514,9 @@ if ( ! class_exists( 'um\core\Roles_Capabilities' ) ) { $user_um_roles_array = array_intersect( $um_roles_keys, array_values( $user->roles ) ); - if ( empty( $user_um_roles_array ) ) + if ( empty( $user_um_roles_array ) ) { return false; + } return array_shift( $user_um_roles_array ); } diff --git a/includes/core/class-user.php b/includes/core/class-user.php index 08b31861..dc35f97d 100644 --- a/includes/core/class-user.php +++ b/includes/core/class-user.php @@ -729,7 +729,7 @@ if ( ! class_exists( 'um\core\User' ) ) { public function secondary_role_field( $content, $userdata ) { $roles = array(); - $role_keys = get_option( 'um_roles' ); + $role_keys = get_option( 'um_roles', array() ); if ( $role_keys ) { foreach ( $role_keys as $role_key ) { $role_meta = get_option( "um_role_{$role_key}_meta" ); @@ -1858,12 +1858,12 @@ if ( ! class_exists( 'um\core\User' ) ) { //if isset roles argument validate role to properly for security reasons if ( isset( $args['role'] ) ) { global $wp_roles; - $um_roles = get_option( 'um_roles' ); + $um_roles = get_option( 'um_roles', array() ); if ( ! empty( $um_roles ) ) { $role_keys = array_map( function( $item ) { return 'um_' . $item; - }, get_option( 'um_roles' ) ); + }, $um_roles ); } else { $role_keys = array(); } diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php index 54e9354b..ef85d941 100644 --- a/includes/core/um-actions-form.php +++ b/includes/core/um-actions-form.php @@ -536,13 +536,21 @@ function um_submit_form_errors_hook_( $args ) { if ( isset( $array['min_chars'] ) && $array['min_chars'] > 0 ) { if ( $args[ $key ] && strlen( utf8_decode( $args[ $key ] ) ) < $array['min_chars'] ) { - UM()->form()->add_error( $key, sprintf( __( 'Your %s must contain at least %s characters', 'ultimate-member' ), $array['label'], $array['min_chars'] ) ); + if ( empty( $array['label'] ) ) { + UM()->form()->add_error( $key, sprintf( __( 'This field must contain at least %s characters', 'ultimate-member' ), $array['min_chars'] ) ); + } else { + UM()->form()->add_error( $key, sprintf( __( 'Your %s must contain at least %s characters', 'ultimate-member' ), $array['label'], $array['min_chars'] ) ); + } } } if ( isset( $array['max_chars'] ) && $array['max_chars'] > 0 ) { if ( $args[ $key ] && strlen( utf8_decode( $args[ $key ] ) ) > $array['max_chars'] ) { - UM()->form()->add_error( $key, sprintf( __( 'Your %s must contain less than %s characters', 'ultimate-member' ), $array['label'], $array['max_chars'] ) ); + if ( empty( $array['label'] ) ) { + UM()->form()->add_error( $key, sprintf( __( 'This field must contain less than %s characters', 'ultimate-member' ), $array['max_chars'] ) ); + } else { + UM()->form()->add_error( $key, sprintf( __( 'Your %s must contain less than %s characters', 'ultimate-member' ), $array['label'], $array['max_chars'] ) ); + } } } diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php index 67826f1b..b5efa328 100644 --- a/includes/core/um-actions-profile.php +++ b/includes/core/um-actions-profile.php @@ -380,7 +380,7 @@ function um_user_edit_profile( $args ) { global $wp_roles; $role_keys = array_map( function( $item ) { return 'um_' . $item; - }, get_option( 'um_roles' ) ); + }, get_option( 'um_roles', array() ) ); $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); if ( ! in_array( $args['submitted']['role'], $exclude_roles ) ) { @@ -400,7 +400,7 @@ function um_user_edit_profile( $args ) { global $wp_roles; $role_keys = array_map( function( $item ) { return 'um_' . $item; - }, get_option( 'um_roles' ) ); + }, get_option( 'um_roles', array() ) ); $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); if ( ! in_array( $args['submitted']['role'], $exclude_roles ) ) { @@ -536,7 +536,7 @@ function um_user_edit_profile( $args ) { * } * ?> */ - do_action( 'um_user_after_updating_profile', $to_update, $user_id ); + do_action( 'um_user_after_updating_profile', $to_update, $user_id, $args ); /** * UM hook @@ -598,7 +598,7 @@ function um_restore_default_roles( $user_id, $args, $to_update ) { $role_keys = array_map( function( $item ) { return 'um_' . $item; - }, get_option( 'um_roles' ) ); + }, get_option( 'um_roles', array() ) ); $leave_roles = array_diff( $args['roles_before_upgrade'], array_merge( $role_keys, array( 'subscriber' ) ) ); diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php index 7ef63bd5..930e4aef 100644 --- a/includes/core/um-actions-register.php +++ b/includes/core/um-actions-register.php @@ -64,8 +64,14 @@ function um_after_insert_user( $user_id, $args ) { UM()->user()->set_registration_details( $args['submitted'], $args ); } + $status = um_user( 'status' ); + if ( empty( $status ) ) { + um_fetch_user( $user_id ); + $status = um_user( 'status' ); + } + /* save user status */ - UM()->user()->set_status( um_user( 'status' ) ); + UM()->user()->set_status( $status ); /* create user uploads directory */ UM()->uploader()->get_upload_user_base_dir( $user_id, true ); @@ -400,12 +406,12 @@ function um_submit_form_register( $args ) { //get user role from field Role dropdown or radio if ( isset( $args['role'] ) ) { global $wp_roles; - $um_roles = get_option( 'um_roles' ); + $um_roles = get_option( 'um_roles', array() ); if ( ! empty( $um_roles ) ) { $role_keys = array_map( function( $item ) { return 'um_' . $item; - }, get_option( 'um_roles' ) ); + }, $um_roles ); } else { $role_keys = array(); } diff --git a/readme.txt b/readme.txt index bf3c7ace..bd90e9ab 100644 --- a/readme.txt +++ b/readme.txt @@ -155,6 +155,17 @@ The plugin works with popular caching plugins by automatically excluding Ultimat * To learn more about version 2.1 please see this [docs](https://docs.ultimatemember.com/article/1512-upgrade-2-1-0) * UM2.1+ is a significant update to the Member Directories' code base from 2.0.x. Please make sure you take a full-site backup with restore point before updating the plugin += 2.1.14: December 21, 2020 = + +* Enhancements: + - Added a tooltip with meta key name for fields in a form settings + - Added `Administrator` user role to a restriction setting (to make the content visible only for `Administrator` role) + +* Bugfixes: + - Added third parameter $args to the action hook for Profile Tab redirections `um_user_after_updating_profile` + - Fixed issues with fields without metakeys when trying to display them by the hook + - Fixed PHP notices/warnings + = 2.1.13: December 8, 2020 = * Enhancements: diff --git a/ultimate-member.php b/ultimate-member.php index 488c3515..1919ede0 100644 --- a/ultimate-member.php +++ b/ultimate-member.php @@ -3,7 +3,7 @@ Plugin Name: Ultimate Member Plugin URI: http://ultimatemember.com/ Description: The easiest way to create powerful online communities and beautiful user profiles with WordPress -Version: 2.1.13 +Version: 2.1.14-rc.1 Author: Ultimate Member Author URI: http://ultimatemember.com/ Text Domain: ultimate-member diff --git a/uninstall.php b/uninstall.php index 0a48b647..b87c6086 100644 --- a/uninstall.php +++ b/uninstall.php @@ -69,7 +69,7 @@ if ( ! empty( $delete_options ) ) { } //remove user role meta - $role_keys = get_option( 'um_roles' ); + $role_keys = get_option( 'um_roles', array() ); if ( $role_keys ) { foreach ( $role_keys as $role_key ) { delete_option( 'um_role_' . $role_key . '_meta' );