mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-16 13:13:33 +09:00
Merge remote-tracking branch 'remotes/origin/origin/improvement/field-notice'
This commit is contained in:
@@ -259,6 +259,52 @@ p.um-notice.warning a {
|
||||
margin: 12px 0 0 0;
|
||||
}
|
||||
|
||||
/*
|
||||
- Notices
|
||||
*/
|
||||
.um-field-notice {
|
||||
width: auto;
|
||||
max-width: 100%;
|
||||
background: #497BC7;
|
||||
-moz-border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
color: #fff;
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
padding: 12px;
|
||||
font-size: 14px;
|
||||
line-height: 20px !important;
|
||||
margin: 5px 0 0 0;
|
||||
}
|
||||
|
||||
.um-field-notice a{color: #fff !important;text-decoration: underline !important}
|
||||
|
||||
.um-field-notice .um-field-arrow {
|
||||
top: -17px;
|
||||
left: 10px;
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
color: #497BC7 !important;
|
||||
font-size: 28px;
|
||||
line-height: 1em !important;
|
||||
}
|
||||
|
||||
.um-notice-block {
|
||||
width: auto;
|
||||
max-width: 100%;
|
||||
background: #497BC7;
|
||||
-moz-border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
color: #fff;
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
padding: 12px;
|
||||
font-size: 14px;
|
||||
line-height: 1em !important;
|
||||
margin: 12px 0 0 0;
|
||||
}
|
||||
/*
|
||||
- Help tooltips
|
||||
*/
|
||||
|
||||
@@ -396,6 +396,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
|
||||
*
|
||||
@@ -407,6 +436,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
|
||||
@@ -419,6 +459,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
|
||||
@@ -972,10 +1023,10 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
*/
|
||||
$data = apply_filters( 'um_is_selected_filter_data', $data, $key, $field_value );
|
||||
|
||||
if ( ! $this->editing ) {
|
||||
if ( ! $this->editing || 'custom' == $this->set_mode ) {
|
||||
// show default on register screen if there is default
|
||||
if ( isset( $data['default'] ) ) {
|
||||
if ( strstr( $data['default'], ', ' ) ) {
|
||||
if ( ! is_array( $data['default'] ) && strstr( $data['default'], ', ' ) ) {
|
||||
$data['default'] = explode( ', ', $data['default'] );
|
||||
}
|
||||
|
||||
@@ -986,6 +1037,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
if ( is_array( $data['default'] ) && in_array( $value, $data['default'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( is_array( $data['default'] ) && array_intersect( $data['options'], $data['default'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1008,7 +1064,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
// show default on edit screen if there isn't meta row in usermeta table
|
||||
$direct_db_value = $wpdb->get_var( $wpdb->prepare( "SELECT ISNULL( meta_value ) FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = %s", um_user( 'ID' ), $key ) );
|
||||
if ( ! isset( $direct_db_value ) && isset( $data['default'] ) ) {
|
||||
if ( strstr( $data['default'], ', ' ) ) {
|
||||
if ( ! is_array( $data['default'] ) && strstr( $data['default'], ', ' ) ) {
|
||||
$data['default'] = explode( ', ', $data['default'] );
|
||||
}
|
||||
|
||||
@@ -1039,7 +1095,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
*/
|
||||
function is_radio_checked( $key, $value, $data ) {
|
||||
global $wpdb;
|
||||
|
||||
|
||||
if ( isset( UM()->form()->post_form[ $key ] ) ) {
|
||||
if ( is_array( UM()->form()->post_form[ $key ] ) && in_array( $value, UM()->form()->post_form[ $key ] ) ) {
|
||||
return true;
|
||||
@@ -1048,7 +1104,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
}
|
||||
} else {
|
||||
|
||||
if ( $this->editing ) {
|
||||
if ( $this->editing && 'custom' !== $this->set_mode ) {
|
||||
if ( um_user( $key ) ) {
|
||||
|
||||
if ( strstr( $key, 'role_' ) ) {
|
||||
@@ -2038,6 +2094,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 ) {
|
||||
|
||||
@@ -2066,6 +2124,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
|
||||
$output .= apply_filters( "um_edit_field_{$mode}_{$type}", $output, $data );
|
||||
break;
|
||||
|
||||
@@ -2102,9 +2161,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 */
|
||||
@@ -2137,6 +2198,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>';
|
||||
@@ -2173,6 +2236,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>';
|
||||
@@ -2207,6 +2272,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>';
|
||||
@@ -2236,6 +2303,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>';
|
||||
@@ -2270,6 +2339,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>';
|
||||
@@ -2297,6 +2368,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>';
|
||||
@@ -2330,6 +2403,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>';
|
||||
@@ -2358,6 +2433,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>';
|
||||
@@ -2386,6 +2463,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>';
|
||||
@@ -2466,6 +2545,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>';
|
||||
@@ -2570,6 +2651,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>';
|
||||
|
||||
@@ -2667,6 +2750,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>';
|
||||
|
||||
@@ -3167,6 +3252,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>';
|
||||
@@ -3235,11 +3322,24 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
$i = 0;
|
||||
$field_value = array();
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_radio_option_value
|
||||
* @description Enable options pair by field $data
|
||||
* @input_vars
|
||||
* [{"var":"$options_pair","type":"null","desc":"Enable pairs"},
|
||||
* {"var":"$data","type":"array","desc":"Field Data"}]
|
||||
*/
|
||||
$options_pair = apply_filters( "um_radio_options_pair__{$key}", false, $data );
|
||||
|
||||
|
||||
if ( ! empty( $options ) ) {
|
||||
foreach ( $options as $k => $v ) {
|
||||
|
||||
$v = rtrim( $v );
|
||||
|
||||
|
||||
$um_field_checkbox_item_title = $v;
|
||||
$option_value = $v;
|
||||
|
||||
@@ -3249,6 +3349,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
$option_value = $k;
|
||||
}
|
||||
|
||||
if( $options_pair ){
|
||||
$um_field_checkbox_item_title = $v;
|
||||
$option_value = $k;
|
||||
}
|
||||
|
||||
$i++;
|
||||
if ($i % 2 == 0) {
|
||||
$col_class = 'right';
|
||||
@@ -3303,8 +3408,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>';
|
||||
@@ -3453,6 +3560,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