diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 34a3677a..60d4d79a 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -4355,52 +4355,35 @@ if ( ! class_exists( 'um\core\Fields' ) ) { * @return string|null * @throws \Exception */ - function view_field( $key, $data, $rule = false ) { + public function view_field( $key, $data, $rule = false ) { $output = ''; // get whole field data if ( is_array( $data ) ) { $data = $this->get_field( $key ); - - if ( is_array( $data ) ) { - /** - * @var $visibility - * @var $type - * @var $default - * @var $classes - * @var $conditional - * @var $content - * @var $divider_text - * @var $spacing - * @var $borderwidth - * @var $borderstyle - * @var $bordercolor - * @var $label - */ - extract( $data ); - } } //hide if empty type if ( ! isset( $data['type'] ) ) { return ''; } + $type = $data['type']; - if ( isset( $data['in_group'] ) && $data['in_group'] != '' && $rule != 'group' ) { + if ( isset( $data['in_group'] ) && '' !== $data['in_group'] && 'group' !== $rule ) { return ''; } //invisible on profile page - if ( $visibility == 'edit' || $type == 'password' ) { + if ( 'edit' === $data['visibility'] || 'password' === $type ) { return ''; } //hide if empty $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 ( ! in_array( $type, $fields_without_metakey, true ) ) { + $_field_value = $this->field_value( $key, $data['classes'], $data ); - if ( ! isset( $_field_value ) || $_field_value == '' ) { + if ( ! isset( $_field_value ) || '' === $_field_value ) { return ''; } } @@ -4410,7 +4393,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } // disable these fields in profile view only - if ( in_array( $key, array( 'user_password' ) ) && $this->set_mode == 'profile' ) { + if ( in_array( $key, array( 'user_password' ), true ) && 'profile' === $this->set_mode ) { return ''; } @@ -4418,23 +4401,21 @@ if ( ! class_exists( 'um\core\Fields' ) ) { return ''; } - if ( isset( $data['classes'] ) ) { - $classes = explode( " ", $data['classes'] ); + $classes = explode( ' ', $data['classes'] ); } switch ( $type ) { /* Default */ default: + $_field_value = $this->field_value( $key, $data['default'], $data ); - $_field_value = $this->field_value( $key, $default, $data ); - - if ( ! in_array( $type, $fields_without_metakey ) && ( ! isset( $_field_value ) || $_field_value == '' ) ) { + if ( ! in_array( $type, $fields_without_metakey, true ) && ( ! isset( $_field_value ) || '' === $_field_value ) ) { $output = ''; } else { - $output .= '
get_atts( $key, $classes, $conditional, $data ) . '>'; + $output .= '
get_atts( $key, $classes, $data['conditional'], $data ) . '>'; if ( isset( $data['label'] ) || ! empty( $data['icon'] ) ) { @@ -4445,7 +4426,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $output .= $this->field_label( $data['label'], $key, $data ); } - $res = $this->field_value( $key, $default, $data ); + $res = $this->field_value( $key, $data['default'], $data ); if ( ! empty( $res ) ) { $res = stripslashes( $res ); @@ -4462,53 +4443,48 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $data['is_view_field'] = true; /** - * UM hook + * Filters change field HTML on view mode * - * @type filter - * @title um_view_field - * @description Change field HTML on view mode - * @input_vars - * [{"var":"$output","type":"string","desc":"Field HTML"}, - * {"var":"$data","type":"string","desc":"Field Data"}, - * {"var":"$type","type":"string","desc":"Field Type"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_view_field', 'function_name', 10, 3 ); - * @example - * Change field HTML on view mode. + * function my_view_field( $output, $data, $type ) { * // your code here * return $output; * } - * ?> + * add_filter( 'um_view_field', 'my_view_field', 10, 3 ); */ $res = apply_filters( 'um_view_field', $res, $data, $type ); + /** - * UM hook + * Filters field HTML on view mode by field type * - * @type filter - * @title um_view_field_value_{$type} - * @description Change field HTML on view mode by field type - * @input_vars - * [{"var":"$output","type":"string","desc":"Field HTML"}, - * {"var":"$data","type":"string","desc":"Field Data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_view_field_value_{$type}', 'function_name', 10, 2 ); - * @example - * Change field HTML on view mode by field type. + * function my_view_field( $output, $data ) { * // your code here * return $output; * } - * ?> + * add_filter( 'um_view_field_value_{$type}', 'my_view_field', 10, 2 ); */ $res = apply_filters( "um_view_field_value_{$type}", $res, $data ); $id_attr = ''; - if ( ! in_array( $type, $fields_without_metakey ) ) { + if ( ! in_array( $type, $fields_without_metakey, true ) ) { $id_attr = ' id="' . esc_attr( $key . UM()->form()->form_suffix ) . '"'; } @@ -4525,58 +4501,58 @@ if ( ! class_exists( 'um\core\Fields' ) ) { break; - /* HTML */ + /* HTML */ case 'block': - $output .= '
get_atts( $key, $classes, $conditional, $data ) . '>' . $content . '
'; + $output .= '
get_atts( $key, $classes, $data['conditional'], $data ) . '>' . $data['content'] . '
'; break; - /* Shortcode */ + /* Shortcode */ case 'shortcode': - - $content = str_replace( '{profile_id}', um_profile_id(), $content ); - if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) { + $content = str_replace( '{profile_id}', um_profile_id(), $data['content'] ); + if ( version_compare( get_bloginfo( 'version' ), '5.4', '<' ) ) { $content = do_shortcode( $content ); } else { $content = apply_shortcodes( $content ); } - $output .= '
get_atts( $key, $classes, $conditional, $data ) . '>' . $content . '
'; + $output .= '
get_atts( $key, $classes, $data['conditional'], $data ) . '>' . $content . '
'; break; - /* Gap/Space */ + /* Gap/Space */ case 'spacing': - $output .= '
get_atts( $key, $classes, $conditional, $data, array( 'height' => $spacing ) ) . '>
'; + $output .= '
get_atts( $key, $classes, $data['conditional'], $data, array( 'height' => $data['spacing'] ) ) . '>
'; break; - /* A line divider */ + /* A line divider */ case 'divider': - $output .= '
get_atts( $key, $classes, $conditional, $data, array( 'border-bottom' => $borderwidth . 'px ' . $borderstyle . ' ' . $bordercolor ) ) . '>'; - if ( $divider_text ) { - $output .= '
' . $divider_text . '
'; + $output .= '
get_atts( $key, $classes, $data['conditional'], $data, array( 'border-bottom' => $data['borderwidth'] . 'px ' . $data['borderstyle'] . ' ' . $data['bordercolor'] ) ) . '>'; + if ( $data['divider_text'] ) { + $output .= '
' . $data['divider_text'] . '
'; } $output .= '
'; break; - /* Rating */ + /* Rating */ case 'rating': - - $output .= '
get_atts( $key, $classes, $conditional, $data ) . '>'; + $output .= '
get_atts( $key, $classes, $data['conditional'], $data ) . '>'; if ( isset( $data['label'] ) || ! empty( $data['icon'] ) ) { - $output .= $this->field_label( $label, $key, $data ); + $output .= $this->field_label( $data['label'], $key, $data ); } - ob_start(); ?> + ob_start(); + ?>
-
+
- '; break; @@ -4586,47 +4562,42 @@ if ( ! class_exists( 'um\core\Fields' ) ) { // Custom filter for field output if ( isset( $this->set_mode ) ) { /** - * UM hook + * Filters field HTML by field $key * - * @type filter - * @title um_{$key}_form_show_field - * @description Change field HTML by field $key - * @input_vars - * [{"var":"$output","type":"string","desc":"Field HTML"}, - * {"var":"$mode","type":"string","desc":"Form Mode"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_{$key}_form_show_field', 'function_name', 10, 2 ); - * @example - * Change field HTML by field $key. * function my_form_show_field( $output, $mode ) { * // your code here * return $output; * } - * ?> + * add_filter( 'um_{$key}_form_show_field', 'my_form_show_field', 10, 2 ); */ $output = apply_filters( "um_{$key}_form_show_field", $output, $this->set_mode ); + /** - * UM hook + * Filters field HTML by field $type * - * @type filter - * @title um_{$type}_form_show_field - * @description Change field HTML by field $type - * @input_vars - * [{"var":"$output","type":"string","desc":"Field HTML"}, - * {"var":"$mode","type":"string","desc":"Form Mode"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_{$type}_form_show_field', 'function_name', 10, 2 ); - * @example - * Change field HTML by field $type. * function my_form_show_field( $output, $mode ) { * // your code here * return $output; * } - * ?> + * add_filter( 'um_{$type}_form_show_field', 'my_form_show_field', 10, 2 ); */ $output = apply_filters( "um_{$type}_form_show_field", $output, $this->set_mode ); }