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
*
* @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 .= '<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>';
}
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
* <?php
* add_filter( 'um_view_label_{$key}', 'my_view_label', 10, 1 );
* function my_view_label( $label ) {
* // your code here
* @since 2.0.0
* @since 2.8.0 Added $data attribute.
*
* @hook um_view_label_{$key}
*
* @param {string} $label Field label.
* @param {string} $data Field data.
*
* @return {string} Field label.
*
* @example <caption>Change first name field label on the Profile form: view mode.</caption>
* 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
* <?php
* add_filter( 'um_edit_label_{$key}', 'my_edit_label', 10, 1 );
* function my_edit_label( $label ) {
* // your code here
* @since 2.0.0
* @since 2.8.0 Added $data attribute.
*
* @hook um_edit_label_{$key}
*
* @param {string} $label Field label.
* @param {string} $data Field data.
*
* @return {string} Field label.
*
* @example <caption>Change first name field label on the Profile form: edit mode.</caption>
* 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
* <?php
* add_filter( 'um_edit_label_all_fields', 'my_edit_label_all_fields', 10, 2 );
* function my_edit_label_all_fields( $label, $data ) {
* // your code here
* @since 2.0.0
*
* @hook um_edit_label_all_fields
*
* @param {string} $label Field label.
* @param {string} $data Field data.
*
* @return {string} Field label.
*
* @example <caption>Change first name field label on the Profile form: edit mode.</caption>
* 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 .= '<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 ( 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>';
}
}
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>';
}
}
@@ -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
* <?php
* add_filter( 'um_change_field_label', 'my_change_field_label', 10, 2 );
* function my_form_fields( $label, $key ) {
* // your code here
* @since 2.0.30
* @since 2.8.0 Added $data attribute.
*
* @hook um_change_field_label
*
* @param {string} $label Field label.
* @param {string} $key Field key.
* @param {array} $data Field data.
*
* @return {string} Field label.
*
* @example <caption>Change first name field label.</caption>
* 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;