Merge branch 'master' of https://github.com/ultimatemember/ultimatemember into beta/2.1.0

This commit is contained in:
nikitasinelnikov
2019-08-28 17:09:45 +03:00
78 changed files with 1607 additions and 705 deletions
@@ -18,7 +18,7 @@
UmRegisterBlockType('um-block/um-forms', {
title: i18n.__( 'UM Form' , 'ultimate-member' ),
description: i18n.__( 'Chose display form', 'ultimate-member' ),
description: i18n.__( 'Choose display form', 'ultimate-member' ),
icon: 'forms',
category: 'um-blocks',
attributes: {
@@ -147,7 +147,7 @@
UmRegisterBlockType( 'um-block/um-member-directories', {
title: i18n.__( 'UM Member Directories', 'ultimate-member'),
description: i18n.__( 'Chose display form', 'ultimate-member' ),
description: i18n.__( 'Choose display form', 'ultimate-member' ),
icon: 'groups',
category: 'um-blocks',
attributes: {
@@ -1,6 +1,11 @@
jQuery( document ).ready( function() {
jQuery( '#role' ).change( function() {
if ( typeof um_roles == 'object' ) {
um_roles = Object.keys( um_roles ).map(function( key ) { return um_roles[ key ]; });
}
if ( jQuery.inArray( jQuery(this).val().substr(3), um_roles ) !== -1 ) {
jQuery( '#um_role_selector_wrapper' ).hide();
jQuery( '#um-role' ).val('');
@@ -10,6 +15,10 @@ jQuery( document ).ready( function() {
}).trigger('change');
jQuery( '#adduser-role' ).change( function() {
if ( typeof um_roles == 'object' ) {
um_roles = Object.keys( um_roles ).map(function( key ) { return um_roles[ key ]; });
}
if ( jQuery.inArray( jQuery(this).val().substr(3), um_roles ) !== -1 ) {
jQuery( '#um_role_existing_selector_wrapper' ).hide();
jQuery( '#um-role' ).val('');
+8 -29
View File
@@ -54,6 +54,11 @@ if ( ! class_exists( 'um\admin\core\Admin_Builder' ) ) {
$validate = $field_attr['validate'];
foreach ( $validate as $post_input => $arr ) {
$skip = apply_filters( 'um_admin_builder_skip_field_validation', false, $post_input, $array );
if ( $skip ) {
continue;
}
$mode = $arr['mode'];
switch ( $mode ) {
@@ -115,42 +120,16 @@ if ( ! class_exists( 'um\admin\core\Admin_Builder' ) ) {
*/
extract( $array );
/**
* UM hook
*
* @type filter
* @title um_fields_without_metakey
* @description Field Types without meta key
* @input_vars
* [{"var":"$types","type":"array","desc":"Field Types"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_fields_without_metakey', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_fields_without_metakey', 'my_fields_without_metakey', 10, 1 );
* function my_fields_without_metakey( $types ) {
* // your code here
* return $types;
* }
* ?>
*/
$fields_without_metakey = apply_filters( 'um_fields_without_metakey', array(
'block',
'shortcode',
'spacing',
'divider',
'group'
) );
$fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
$fields = UM()->query()->get_attr('custom_fields', $form_id);
$fields = UM()->query()->get_attr( 'custom_fields', $form_id );
$count = 1;
if ( ! empty( $fields ) ) {
$count = count( $fields ) + 1;
}
// set unique meta key
if ( in_array( $field_type, $fields_without_metakey ) || ! isset( $array['post']['_metakey'] ) ) {
if ( in_array( $field_type, $fields_without_metakey ) && ! isset( $array['post']['_metakey'] ) ) {
$array['post']['_metakey'] = "um_{$field_type}_{$form_id}_{$count}";
}
+2 -2
View File
@@ -164,8 +164,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) {
*/
function load_role_wrapper() {
wp_register_script( 'um_admin_role_wrapper', $this->js_url . 'um-admin-role-wrapper.js', array( 'jquery' ), ultimatemember_version, true );
$localize_roles_data = get_option( 'um_roles' );
wp_localize_script( 'um_admin_role_wrapper', 'um_roles', $localize_roles_data );
$localize_roles_data = get_option( 'um_roles' );
wp_localize_script( 'um_admin_role_wrapper', 'um_roles', (array) $localize_roles_data );
wp_enqueue_script( 'um_admin_role_wrapper' );
}
+43 -32
View File
@@ -1215,6 +1215,47 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
}
/**
* Get all fields without metakeys
*
* @since 2.0.56
*
* @return array
*/
function get_fields_without_metakey() {
$fields_without_metakey = array(
'block',
'shortcode',
'spacing',
'divider',
'group'
);
/**
* UM hook
*
* @type filter
* @title um_fields_without_metakey
* @description Field Types without meta key
* @input_vars
* [{"var":"$types","type":"array","desc":"Field Types"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_fields_without_metakey', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_fields_without_metakey', 'my_fields_without_metakey', 10, 1 );
* function my_fields_without_metakey( $types ) {
* // your code here
* return $types;
* }
* ?>
*/
return apply_filters( 'um_fields_without_metakey', $fields_without_metakey );
}
/**
* May be used to show a dropdown, or source for user meta
*
@@ -1225,38 +1266,8 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
*/
function all_user_fields( $exclude_types = null, $show_all = false ) {
$fields_without_metakey = array(
'block',
'shortcode',
'spacing',
'divider',
'group'
);
$fields_without_metakey = apply_filters( 'um_fields_without_metakey', $fields_without_metakey );
remove_filter( 'um_fields_without_metakey', 'um_user_tags_requires_no_metakey' );
/**
* UM hook
*
* @type filter
* @title um_fields_without_metakey
* @description Extend Fields without metakey
* @input_vars
* [{"var":"$fields","type":"array","desc":"Fields without metakey"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_fields_without_metakey', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_fields_without_metakey', 'my_fields_without_metakey', 10, 1 );
* function my_fields_without_metakey( $fields ) {
* // your code here
* return $fields;
* }
* ?>
*/
$fields_without_metakey = apply_filters( 'um_fields_without_metakey', $fields_without_metakey );
$fields_without_metakey = $this->get_fields_without_metakey();
$fields_without_metakey = apply_filters( 'um_all_user_fields_without_metakey', $fields_without_metakey );
if ( ! $show_all ) {
$this->fields_dropdown = array('image','file','password','rating');
+8 -3
View File
@@ -2603,6 +2603,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$output .= '<div class="um-field-icon"><i class="' . esc_attr( $icon ) . '"></i></div>';
}
$options = array();
$has_parent_option = false;
$disabled_by_parent_option = '';
$atts_ajax = '';
@@ -2735,10 +2736,13 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$options = UM()->builtin()->get ( $filter );
}
if ( ! isset( $options ) ) {
// 'country'
if ( $key === 'country' && empty( $options ) ) {
$options = UM()->builtin()->get( 'countries' );
}
$options = apply_filters( 'um_selectbox_options', $options, $key );
if ( isset( $options ) ) {
/**
* UM hook
@@ -2800,7 +2804,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
* [{"var":"$options_pair","type":"null","desc":"Enable pairs"},
* {"var":"$data","type":"array","desc":"Field Data"}]
*/
$options_pair = apply_filters( "um_select_options_pair", null, $data );
$options_pair = apply_filters( 'um_select_options_pair', null, $data );
// switch options pair for custom options from a callback function
if ( ! empty( $data['custom_dropdown_options_source'] ) ) {
@@ -3744,7 +3748,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
}
//hide if empty
if ( ! in_array( $type, array( 'block', 'shortcode', 'spacing', 'divider', 'group' ) ) ) {
$fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
if ( ! in_array( $type, $fields_without_metakey ) ) {
$_field_value = $this->field_value( $key, $default, $data );
if ( ! isset( $_field_value ) || $_field_value == '' ) {
+2 -1
View File
@@ -286,6 +286,7 @@ if ( ! class_exists( 'um\core\Files' ) ) {
wp_send_json_error( esc_js( __( 'Invalid coordinates', 'ultimate-member' ) ) );
}
$user_id = empty( $_REQUEST['user_id'] ) ? get_current_user_id() : $_REQUEST['user_id'];
$image_path = um_is_file_owner( $src, $user_id, true );
if ( ! $image_path ) {
wp_send_json_error( esc_js( __( 'Invalid file ownership', 'ultimate-member' ) ) );
@@ -312,7 +313,7 @@ if ( ! class_exists( 'um\core\Files' ) ) {
$id = $_POST['key'];
$timestamp = $_POST['timestamp'];
$nonce = $_POST['_wpnonce'];
$user_id = $_POST['user_id'];
$user_id = empty( $_POST['user_id'] ) ? get_current_user_id() : $_POST['user_id'];
UM()->fields()->set_id = $_POST['set_id'];
UM()->fields()->set_mode = $_POST['set_mode'];
+13 -8
View File
@@ -26,22 +26,26 @@ if ( ! class_exists( 'um\core\Form' ) ) {
var $form_id;
/**
* @var null
*/
var $post_form = null;
/**
* Form constructor.
*/
function __construct() {
$this->post_form = null;
$this->form_suffix = null;
$this->errors = null;
$this->processing = null;
add_action('template_redirect', array(&$this, 'form_init'), 2);
add_action( 'template_redirect', array( &$this, 'form_init' ), 2 );
add_action('init', array(&$this, 'field_declare'), 10);
add_action( 'init', array( &$this, 'field_declare' ), 10 );
}
@@ -218,8 +222,9 @@ if ( ! class_exists( 'um\core\Form' ) ) {
* @return boolean
*/
function has_error( $key ) {
if ( isset( $this->errors[$key] ) )
if ( isset( $this->errors[ $key ] ) ) {
return true;
}
return false;
}
@@ -227,7 +232,7 @@ if ( ! class_exists( 'um\core\Form' ) ) {
/**
* Declare all fields
*/
function field_declare(){
function field_declare() {
if ( isset( UM()->builtin()->custom_fields ) ) {
$this->all_fields = UM()->builtin()->custom_fields;
} else {
@@ -237,11 +242,11 @@ if ( ! class_exists( 'um\core\Form' ) ) {
/**
* Validate form
* Validate form on submit
*/
function form_init() {
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
$http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
$http_post = ( 'POST' == $_SERVER['REQUEST_METHOD'] );
} else {
$http_post = 'POST';
}
+1 -1
View File
@@ -435,7 +435,7 @@ if ( ! class_exists( 'um\core\Mail' ) ) {
add_filter( 'um_template_tags_replaces_hook', array( UM()->mail(), 'add_replace_placeholder' ), 10, 1 );
$subject = apply_filters( 'um_email_send_subject', UM()->options()->get( $template . '_sub' ), $template );
$this->subject = um_convert_tags( $subject , $args );
$this->subject = wp_unslash( um_convert_tags( $subject , $args ) );
$this->message = $this->prepare_template( $template, $args );
+7 -5
View File
@@ -395,17 +395,18 @@ if ( ! class_exists( 'um\core\Query' ) ) {
/**
* Capture selected value
*
* @param $key
* @param null $array_key
* @param null $fallback
* @param string $key
* @param string|null $array_key
* @param bool $fallback
* @return int|mixed|null|string
*/
function get_meta_value( $key, $array_key = null, $fallback = false ) {
$post_id = get_the_ID();
$try = get_post_meta( $post_id, $key, true );
//old version if ( ! empty( $try ) )
if ( $try != '' )
//old-old version if ( ! empty( $try ) )
//old version if ( $try !== false )
if ( $try != '' ) {
if ( is_array( $try ) && in_array( $array_key, $try ) ) {
return $array_key;
} else if ( is_array( $try ) ) {
@@ -413,6 +414,7 @@ if ( ! class_exists( 'um\core\Query' ) ) {
} else {
return $try;
}
}
if ( $fallback == 'na' ) {
$fallback = 0;
+11 -11
View File
@@ -366,7 +366,7 @@ function um_submit_form_errors_hook_( $args ) {
$um_profile_photo = um_profile('profile_photo');
if ( get_post_meta( $form_id, '_um_profile_photo_required', true ) && ( empty( $args['profile_photo'] ) && empty( $um_profile_photo ) ) ) {
UM()->form()->add_error('profile_photo', sprintf(__('%s is required.','ultimate-member'), 'Profile Photo' ) );
UM()->form()->add_error('profile_photo', __( 'Profile Photo is required.', 'ultimate-member' ) );
}
if ( ! empty( $fields ) ) {
@@ -413,7 +413,7 @@ function um_submit_form_errors_hook_( $args ) {
}
if ( isset( $array['type'] ) && $array['type'] == 'checkbox' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) ) {
UM()->form()->add_error($key, sprintf(__('%s is required.','ultimate-member'), $array['title'] ) );
UM()->form()->add_error($key, sprintf( __( '%s is required.', 'ultimate-member' ), $array['title'] ) );
}
if ( isset( $array['type'] ) && $array['type'] == 'radio' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) && !in_array($key, array('role_radio','role_select') ) ) {
@@ -453,17 +453,17 @@ function um_submit_form_errors_hook_( $args ) {
*/
do_action( 'um_add_error_on_form_submit_validation', $array, $key, $args );
if ( isset( $args[ $key ] ) ) {
if ( isset( $array['required'] ) && $array['required'] == 1 ) {
if ( ! isset( $args[$key] ) || $args[$key] == '' || $args[$key] == 'empty_file') {
if( empty( $array['label'] ) ) {
UM()->form()->add_error($key, __('This field is required','ultimate-member') );
} else {
UM()->form()->add_error($key, sprintf( __('%s is required','ultimate-member'), $array['label'] ) );
}
if ( ! empty( $array['required'] ) ) {
if ( ! isset( $args[ $key ] ) || $args[ $key ] == '' || $args[ $key ] == 'empty_file' ) {
if ( empty( $array['label'] ) ) {
UM()->form()->add_error( $key, __( 'This field is required', 'ultimate-member' ) );
} else {
UM()->form()->add_error( $key, sprintf( __( '%s is required', 'ultimate-member' ), $array['label'] ) );
}
}
}
if ( isset( $args[ $key ] ) ) {
if ( isset( $array['max_words'] ) && $array['max_words'] > 0 ) {
if ( str_word_count( $args[$key], 0, "éèàôù" ) > $array['max_words'] ) {
+5 -4
View File
@@ -458,19 +458,20 @@ function um_user_edit_profile( $args ) {
* @title um_user_after_updating_profile
* @description After upgrade user's profile
* @input_vars
* [{"var":"$submitted","type":"array","desc":"Form data"}]
* [{"var":"$submitted","type":"array","desc":"Form data"},
* {"var":"$user_id","type":"int","desc":"User Id"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_user_after_updating_profile', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_user_after_updating_profile', 'my_user_after_updating_profile'', 10, 1 );
* function my_user_after_updating_profile( $submitted ) {
* add_action( 'um_user_after_updating_profile', 'my_user_after_updating_profile'', 10, 2 );
* function my_user_after_updating_profile( $submitted, $user_id ) {
* // your code here
* }
* ?>
*/
do_action( 'um_user_after_updating_profile', $to_update );
do_action( 'um_user_after_updating_profile', $to_update, $user_id );
/**
* UM hook