diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php
index 14d87738..efd7884c 100644
--- a/includes/core/class-fields.php
+++ b/includes/core/class-fields.php
@@ -596,150 +596,150 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
/**
* Checks if field has a server-side error
*
- * @param string $key
+ * @param string $key
*
- * @return boolean
+ * @return bool
*/
- function is_error( $key ) {
+ public function is_error( $key ) {
return UM()->form()->has_error( $key );
}
/**
* Checks if field has a notice
*
- * @param string $key
+ * @param string $key
*
- * @return boolean
+ * @return bool
*/
- function is_notice( $key ) {
+ public function is_notice( $key ) {
return UM()->form()->has_notice( $key );
}
-
/**
* Returns field error
*
- * @param string $key
+ * @param string $key
*
* @return string
*/
- function show_error( $key ) {
+ public function show_error( $key ) {
return UM()->form()->errors[ $key ];
}
/**
* Returns field notices
*
- * @param string $key
+ * @param string $key
*
* @return string
*/
- function show_notice( $key ) {
+ public function show_notice( $key ) {
return UM()->form()->notices[ $key ];
}
-
/**
- * Display field label
+ * Display field label.
*
- * @param string $label
- * @param string $key
- * @param array $data
+ * @param string $label Field label.
+ * @param string $key Field key.
+ * @param array $data Field data.
*
- * @return string
+ * @return string
*/
- function field_label( $label, $key, $data ) {
- $output = null;
+ public function field_label( $label, $key, $data ) {
+ $output = null;
$output .= '
';
- if ( isset( $data['icon'] ) && $data['icon'] != '' && isset( $this->field_icons ) && $this->field_icons != 'off' && ( $this->field_icons == 'label' || true === $this->viewing ) ) {
+ if ( ! empty( $data['icon'] ) && isset( $this->field_icons ) && 'off' !== $this->field_icons && ( 'label' === $this->field_icons || true === $this->viewing ) ) {
$output .= '
';
}
if ( true === $this->viewing ) {
/**
- * UM hook
+ * Filters Ultimate Member field label on the Profile form: View mode.
+ * Note: $key it's field metakey.
*
- * @type filter
- * @title um_view_label_{$key}
- * @description Change field label on view by field $key
- * @input_vars
- * [{"var":"$label","type":"string","desc":"Field Label"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_view_label_{$key}', 'function_name', 10, 1 );
- * @example
- * Change first name field label on the Profile form: view mode.
+ * function my_change_first_name_label( $label, $data ) {
+ * $label = 'My label';
* return $label;
* }
- * ?>
+ * add_filter( 'um_view_label_first_name', 'my_change_first_name_label', 10, 2 );
*/
- $label = apply_filters( "um_view_label_{$key}", $label );
+ $label = apply_filters( "um_view_label_{$key}", $label, $data );
} else {
/**
- * UM hook
+ * Filters Ultimate Member field label on the Profile form: Edit mode.
+ * Note: $key it's field metakey.
*
- * @type filter
- * @title um_edit_label_{$key}
- * @description Change field label on edit by field $key
- * @input_vars
- * [{"var":"$label","type":"string","desc":"Field Label"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_edit_label_{$key}', 'function_name', 10, 1 );
- * @example
- * Change first name field label on the Profile form: edit mode.
+ * function my_change_first_name_label( $label, $data ) {
+ * $label = 'My label';
* return $label;
* }
- * ?>
+ * add_filter( 'um_edit_label_first_name', 'my_change_first_name_label', 10, 2 );
*/
- $label = apply_filters( "um_edit_label_{$key}", $label );
+ $label = apply_filters( "um_edit_label_{$key}", $label, $data );
/**
- * UM hook
+ * Filters Ultimate Member field label on the Profile form: Edit mode.
*
- * @type filter
- * @title um_edit_label_all_fields
- * @description Change field label on view by field $key
- * @input_vars
- * [{"var":"$label","type":"string","desc":"Field Label"},
- * {"var":"$data","type":"array","desc":"Field Data"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_edit_label_all_fields', 'function_name', 10, 2 );
- * @example
- * Change first name field label on the Profile form: edit mode.
+ * function my_change_first_name_label( $label, $data ) {
+ * if ( 'first_name' === $data['metakey'] ) {
+ * $label = 'My label';
+ * }
* return $label;
* }
- * ?>
+ * add_filter( 'um_edit_label_all_fields', 'my_change_first_name_label', 10, 2 );
*/
$label = apply_filters( 'um_edit_label_all_fields', $label, $data );
}
$fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
- $for_attr = '';
- if ( ! in_array( $data['type'], $fields_without_metakey ) ) {
+ $for_attr = '';
+ if ( ! in_array( $data['type'], $fields_without_metakey, true ) ) {
$for_attr = ' for="' . esc_attr( $key . UM()->form()->form_suffix ) . '"';
}
$output .= '
';
- if ( ! empty( $data['help'] ) && false === $this->viewing && ! strstr( $key, 'confirm_user_pass' ) ) {
+ if ( ! empty( $data['help'] ) && false === $this->viewing && false === strpos( $key, 'confirm_user_pass' ) ) {
if ( ! UM()->mobile()->isMobile() ) {
if ( false === $this->disable_tooltips ) {
$output .= '
';
}
}
- if ( UM()->mobile()->isMobile() || false !== $this->disable_tooltips ) {
+ if ( false !== $this->disable_tooltips || UM()->mobile()->isMobile() ) {
$output .= '
' . __( $data['help'], 'ultimate-member' ) . '';
}
}
@@ -749,9 +749,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
return $output;
}
-
/**
- * Output field classes
+ * Output field classes.
*
* @param string $key
* @param array $data
@@ -759,7 +758,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
*
* @return string
*/
- function get_class( $key, $data, $add = null ) {
+ public function get_class( $key, $data, $add = null ) {
$classes = null;
$classes .= 'um-form-field ';
@@ -1523,27 +1522,29 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
}
/**
- * UM hook
+ * Filters Ultimate Member field label.
*
- * @type filter
- * @title um_change_field_label
- * @description Change Field Label
- * @input_vars
- * [{"var":"$label","type":"string","desc":"Field Label"},
- * {"var":"$key","type":"string","desc":"Field Key"}]
- * @change_log
- * ["Since: 2.0.30"]
- * @usage add_filter( 'um_change_field_label', 'function_name', 10, 2 );
- * @example
- * Change first name field label.
+ * function my_change_field_label( $label, $key, $data ) {
+ * if ( 'first_name' === $key ) {
+ * $label = 'My label';
+ * }
* return $label;
* }
- * ?>
+ * add_filter( 'um_change_field_label', 'my_change_field_label', 10, 3 );
*/
- $label = apply_filters( 'um_change_field_label', $label, $key );
+ $label = apply_filters( 'um_change_field_label', $label, $key, $fields[ $key ] );
$label = sprintf( __( '%s', 'ultimate-member' ), $label );
return $label;
diff --git a/includes/core/um-filters-fields.php b/includes/core/um-filters-fields.php
index 70f817b8..e75af85c 100644
--- a/includes/core/um-filters-fields.php
+++ b/includes/core/um-filters-fields.php
@@ -1007,18 +1007,34 @@ add_filter( 'um_edit_url_field_value', 'um_edit_url_field_value', 10, 2 );
/**
- * Change field label from "Birth Date" to "Age" in the directory and in the profile view.
+ * Change field label from "Birth Date" to "Age" in the profile view.
*
* @param string $label Field Label.
- * @param string $key Field Key.
+ * @param string $data Field data.
*
* @return string
*/
-function um_view_label_birth_date( $label, $key = 'birth_date' ) {
- if ( 'birth_date' === $key ) {
+function um_view_label_birth_date( $label, $data ) {
+ if ( ! empty( $data['pretty_format'] ) ) {
$label = __( 'Age', 'ultimate-member' );
}
return $label;
}
-add_filter( 'um_view_label_birth_date', 'um_view_label_birth_date', 10, 1 );
-add_filter( 'um_change_field_label', 'um_view_label_birth_date', 10, 2 );
+add_filter( 'um_view_label_birth_date', 'um_view_label_birth_date', 10, 2 );
+
+/**
+ * Change field label from "Birth Date" to "Age" in the member directory.
+ *
+ * @param string $label Field Label.
+ * @param string $key Field Key.
+ * @param string $data Field data.
+ *
+ * @return string
+ */
+function um_md_label_birth_date( $label, $key, $data ) {
+ if ( 'birth_date' === $key && ! empty( $data['pretty_format'] ) ) {
+ $label = __( 'Age', 'ultimate-member' );
+ }
+ return $label;
+}
+add_filter( 'um_change_field_label', 'um_md_label_birth_date', 10, 3 );