mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
Add field notice
This commit is contained in:
@@ -388,6 +388,35 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print field notice
|
||||
*
|
||||
* @param string $text
|
||||
* @param bool $force_show
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function field_notice( $text, $force_show = false ) {
|
||||
if ( $force_show ) {
|
||||
$output = '<div class="um-field-notice"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . $text . '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
if ( isset( $this->set_id ) && UM()->form()->processing == $this->set_id ) {
|
||||
$output = '<div class="um-field-notice"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . $text . '</div>';
|
||||
} else {
|
||||
$output = '';
|
||||
}
|
||||
|
||||
if ( ! UM()->form()->processing ) {
|
||||
$output = '<div class="um-field-notice"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>' . $text . '</div>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if field has a server-side error
|
||||
*
|
||||
@@ -399,6 +428,17 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
return UM()->form()->has_error( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if field has a notice
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function is_notice( $key ) {
|
||||
return UM()->form()->has_notice( $key );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns field error
|
||||
@@ -411,6 +451,17 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
return UM()->form()->errors[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns field notices
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function show_notice( $key ) {
|
||||
return UM()->form()->notices[ $key ];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display field label
|
||||
@@ -2026,6 +2077,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
* ?>
|
||||
*/
|
||||
$field_id = apply_filters( 'um_completeness_field_id', $field_id, $data, $args );
|
||||
|
||||
|
||||
/* Begin by field type */
|
||||
switch ( $type ) {
|
||||
|
||||
@@ -2054,6 +2107,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
|
||||
$output .= apply_filters( "um_edit_field_{$mode}_{$type}", $output, $data );
|
||||
break;
|
||||
|
||||
@@ -2090,9 +2144,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
break;
|
||||
|
||||
/* Text */
|
||||
@@ -2125,6 +2181,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
@@ -2161,6 +2219,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
@@ -2195,6 +2255,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
@@ -2224,6 +2286,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
@@ -2258,6 +2322,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
@@ -2285,6 +2351,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
@@ -2318,6 +2386,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
@@ -2346,6 +2416,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
@@ -2374,6 +2446,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
@@ -2454,6 +2528,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
@@ -2555,8 +2631,10 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
/* end */
|
||||
if ($this->is_error( $key )) {
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
$output .= '</div>';
|
||||
|
||||
@@ -2654,6 +2732,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
/* end */
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
$output .= '</div>';
|
||||
|
||||
@@ -3142,6 +3222,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
@@ -3278,8 +3360,10 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
if ( $this->is_error( $form_key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $form_key ) );
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
@@ -3428,6 +3512,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
|
||||
if ( $this->is_error( $key ) ) {
|
||||
$output .= $this->field_error( $this->show_error( $key ) );
|
||||
}else if ( $this->is_notice( $key ) ) {
|
||||
$output .= $this->field_notice( $this->show_notice( $key ) );
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
@@ -232,6 +232,40 @@ if ( ! class_exists( 'um\core\Form' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends field notices
|
||||
* @param string $key
|
||||
* @param string $notice
|
||||
*/
|
||||
function add_notice( $key, $notice ) {
|
||||
if ( ! isset( $this->notices[ $key ] ) ){
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_submit_form_notice
|
||||
* @description Change notice text on submit form
|
||||
* @input_vars
|
||||
* [{"var":"$notice","type":"string","desc":"notice String"},
|
||||
* {"var":"$key","type":"string","desc":"notice Key"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_submit_form_notice', 'function_name', 10, 2 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_submit_form_notice', 'my_submit_form_notice', 10, 2 );
|
||||
* function my_submit_form_notice( $notice, $key ) {
|
||||
* // your code here
|
||||
* return $notice;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$notice = apply_filters( 'um_submit_form_notice', $notice, $key );
|
||||
$this->notices[ $key ] = $notice;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If a form has errors
|
||||
@@ -245,6 +279,18 @@ if ( ! class_exists( 'um\core\Form' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a form has notices/info
|
||||
* @param string $key
|
||||
* @return boolean
|
||||
*/
|
||||
function has_notice( $key ) {
|
||||
if ( isset( $this->notices[ $key ] ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Declare all fields
|
||||
|
||||
Reference in New Issue
Block a user