This commit is contained in:
Mykyta Synelnikov
2023-11-21 14:52:55 +02:00
parent 898b377629
commit 6fc35d3cbb
2 changed files with 115 additions and 98 deletions
+93 -92
View File
@@ -596,150 +596,150 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
/** /**
* Checks if field has a server-side error * 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 ); return UM()->form()->has_error( $key );
} }
/** /**
* Checks if field has a notice * 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 ); return UM()->form()->has_notice( $key );
} }
/** /**
* Returns field error * Returns field error
* *
* @param string $key * @param string $key
* *
* @return string * @return string
*/ */
function show_error( $key ) { public function show_error( $key ) {
return UM()->form()->errors[ $key ]; return UM()->form()->errors[ $key ];
} }
/** /**
* Returns field notices * Returns field notices
* *
* @param string $key * @param string $key
* *
* @return string * @return string
*/ */
function show_notice( $key ) { public function show_notice( $key ) {
return UM()->form()->notices[ $key ]; return UM()->form()->notices[ $key ];
} }
/** /**
* Display field label * Display field label.
* *
* @param string $label * @param string $label Field label.
* @param string $key * @param string $key Field key.
* @param array $data * @param array $data Field data.
* *
* @return string * @return string
*/ */
function field_label( $label, $key, $data ) { public function field_label( $label, $key, $data ) {
$output = null; $output = null;
$output .= '<div class="um-field-label">'; $output .= '<div class="um-field-label">';
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 .= '<div class="um-field-label-icon"><i class="' . esc_attr( $data['icon'] ) . '" aria-label="' . esc_attr( $label ) . '"></i></div>'; $output .= '<div class="um-field-label-icon"><i class="' . esc_attr( $data['icon'] ) . '" aria-label="' . esc_attr( $label ) . '"></i></div>';
} }
if ( true === $this->viewing ) { 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 * @since 2.0.0
* @title um_view_label_{$key} * @since 2.8.0 Added $data attribute.
* @description Change field label on view by field $key *
* @input_vars * @hook um_view_label_{$key}
* [{"var":"$label","type":"string","desc":"Field Label"}] *
* @change_log * @param {string} $label Field label.
* ["Since: 2.0"] * @param {string} $data Field data.
* @usage add_filter( 'um_view_label_{$key}', 'function_name', 10, 1 ); *
* @example * @return {string} Field label.
* <?php *
* add_filter( 'um_view_label_{$key}', 'my_view_label', 10, 1 ); * @example <caption>Change first name field label on the Profile form: view mode.</caption>
* function my_view_label( $label ) { * function my_change_first_name_label( $label, $data ) {
* // your code here * $label = 'My label';
* return $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 { } else {
/** /**
* UM hook * Filters Ultimate Member field label on the Profile form: Edit mode.
* Note: $key it's field metakey.
* *
* @type filter * @since 2.0.0
* @title um_edit_label_{$key} * @since 2.8.0 Added $data attribute.
* @description Change field label on edit by field $key *
* @input_vars * @hook um_edit_label_{$key}
* [{"var":"$label","type":"string","desc":"Field Label"}] *
* @change_log * @param {string} $label Field label.
* ["Since: 2.0"] * @param {string} $data Field data.
* @usage add_filter( 'um_edit_label_{$key}', 'function_name', 10, 1 ); *
* @example * @return {string} Field label.
* <?php *
* add_filter( 'um_edit_label_{$key}', 'my_edit_label', 10, 1 ); * @example <caption>Change first name field label on the Profile form: edit mode.</caption>
* function my_edit_label( $label ) { * function my_change_first_name_label( $label, $data ) {
* // your code here * $label = 'My label';
* return $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 * @since 2.0.0
* @title um_edit_label_all_fields *
* @description Change field label on view by field $key * @hook um_edit_label_all_fields
* @input_vars *
* [{"var":"$label","type":"string","desc":"Field Label"}, * @param {string} $label Field label.
* {"var":"$data","type":"array","desc":"Field Data"}] * @param {string} $data Field data.
* @change_log *
* ["Since: 2.0"] * @return {string} Field label.
* @usage add_filter( 'um_edit_label_all_fields', 'function_name', 10, 2 ); *
* @example * @example <caption>Change first name field label on the Profile form: edit mode.</caption>
* <?php * function my_change_first_name_label( $label, $data ) {
* add_filter( 'um_edit_label_all_fields', 'my_edit_label_all_fields', 10, 2 ); * if ( 'first_name' === $data['metakey'] ) {
* function my_edit_label_all_fields( $label, $data ) { * $label = 'My label';
* // your code here * }
* return $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 ); $label = apply_filters( 'um_edit_label_all_fields', $label, $data );
} }
$fields_without_metakey = UM()->builtin()->get_fields_without_metakey(); $fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
$for_attr = ''; $for_attr = '';
if ( ! in_array( $data['type'], $fields_without_metakey ) ) { if ( ! in_array( $data['type'], $fields_without_metakey, true ) ) {
$for_attr = ' for="' . esc_attr( $key . UM()->form()->form_suffix ) . '"'; $for_attr = ' for="' . esc_attr( $key . UM()->form()->form_suffix ) . '"';
} }
$output .= '<label' . $for_attr . '>' . __( $label, 'ultimate-member' ) . '</label>'; $output .= '<label' . $for_attr . '>' . __( $label, 'ultimate-member' ) . '</label>';
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 ( ! UM()->mobile()->isMobile() ) {
if ( false === $this->disable_tooltips ) { if ( false === $this->disable_tooltips ) {
$output .= '<span class="um-tip um-tip-' . ( is_rtl() ? 'e' : 'w' ) . '" title="' . esc_attr__( $data['help'], 'ultimate-member' ) . '"><i class="um-icon-help-circled"></i></span>'; $output .= '<span class="um-tip um-tip-' . ( is_rtl() ? 'e' : 'w' ) . '" title="' . esc_attr__( $data['help'], 'ultimate-member' ) . '"><i class="um-icon-help-circled"></i></span>';
} }
} }
if ( UM()->mobile()->isMobile() || false !== $this->disable_tooltips ) { if ( false !== $this->disable_tooltips || UM()->mobile()->isMobile() ) {
$output .= '<span class="um-tip-text">' . __( $data['help'], 'ultimate-member' ) . '</span>'; $output .= '<span class="um-tip-text">' . __( $data['help'], 'ultimate-member' ) . '</span>';
} }
} }
@@ -749,9 +749,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
return $output; return $output;
} }
/** /**
* Output field classes * Output field classes.
* *
* @param string $key * @param string $key
* @param array $data * @param array $data
@@ -759,7 +758,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
* *
* @return string * @return string
*/ */
function get_class( $key, $data, $add = null ) { public function get_class( $key, $data, $add = null ) {
$classes = null; $classes = null;
$classes .= 'um-form-field '; $classes .= 'um-form-field ';
@@ -1523,27 +1522,29 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
} }
/** /**
* UM hook * Filters Ultimate Member field label.
* *
* @type filter * @since 2.0.30
* @title um_change_field_label * @since 2.8.0 Added $data attribute.
* @description Change Field Label *
* @input_vars * @hook um_change_field_label
* [{"var":"$label","type":"string","desc":"Field Label"}, *
* {"var":"$key","type":"string","desc":"Field Key"}] * @param {string} $label Field label.
* @change_log * @param {string} $key Field key.
* ["Since: 2.0.30"] * @param {array} $data Field data.
* @usage add_filter( 'um_change_field_label', 'function_name', 10, 2 ); *
* @example * @return {string} Field label.
* <?php *
* add_filter( 'um_change_field_label', 'my_change_field_label', 10, 2 ); * @example <caption>Change first name field label.</caption>
* function my_form_fields( $label, $key ) { * function my_change_field_label( $label, $key, $data ) {
* // your code here * if ( 'first_name' === $key ) {
* $label = 'My label';
* }
* return $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 ); $label = sprintf( __( '%s', 'ultimate-member' ), $label );
return $label; return $label;
+22 -6
View File
@@ -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 $label Field Label.
* @param string $key Field Key. * @param string $data Field data.
* *
* @return string * @return string
*/ */
function um_view_label_birth_date( $label, $key = 'birth_date' ) { function um_view_label_birth_date( $label, $data ) {
if ( 'birth_date' === $key ) { if ( ! empty( $data['pretty_format'] ) ) {
$label = __( 'Age', 'ultimate-member' ); $label = __( 'Age', 'ultimate-member' );
} }
return $label; return $label;
} }
add_filter( 'um_view_label_birth_date', 'um_view_label_birth_date', 10, 1 ); add_filter( 'um_view_label_birth_date', 'um_view_label_birth_date', 10, 2 );
add_filter( 'um_change_field_label', '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 );