From 3919b62c175706b23ed02893d1e33f2a7c689b9a Mon Sep 17 00:00:00 2001 From: nikitasinelnikov Date: Tue, 20 Aug 2019 16:11:01 +0300 Subject: [PATCH] - fixed issues with the fields without metakeys; - fixed integration issues for the fields without metakeys; --- includes/admin/core/class-admin-builder.php | 32 +-------- includes/core/class-builtin.php | 73 ++++++++++++--------- includes/core/class-fields.php | 3 +- 3 files changed, 46 insertions(+), 62 deletions(-) diff --git a/includes/admin/core/class-admin-builder.php b/includes/admin/core/class-admin-builder.php index a021d4c8..6ee81ecb 100644 --- a/includes/admin/core/class-admin-builder.php +++ b/includes/admin/core/class-admin-builder.php @@ -115,42 +115,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 - * - */ - $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}"; } diff --git a/includes/core/class-builtin.php b/includes/core/class-builtin.php index 99ae060c..b0a4bdcd 100644 --- a/includes/core/class-builtin.php +++ b/includes/core/class-builtin.php @@ -1215,6 +1215,45 @@ if ( ! class_exists( 'um\core\Builtin' ) ) { } + /** + * Get all fields without metakeys + * + * @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 + * + */ + return apply_filters( 'um_fields_without_metakey', $fields_without_metakey ); + } + + /** * May be used to show a dropdown, or source for user meta * @@ -1225,38 +1264,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 - * - */ - $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'); diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 2eb5cf55..4a2b70ba 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -3744,7 +3744,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 == '' ) {