Changeset 2740791
- Timestamp:
- 06/11/2022 11:02:40 AM (4 years ago)
- Location:
- watts
- Files:
-
- 8 added
- 8 deleted
- 10 edited
- 5 copied
-
tags/1.2.1 (copied) (copied from watts/trunk)
-
tags/1.2.1/includes/assets (copied) (copied from watts/trunk/includes/assets)
-
tags/1.2.1/includes/auto-validation.php (deleted)
-
tags/1.2.1/includes/controller.php (modified) (1 diff)
-
tags/1.2.1/includes/css (copied) (copied from watts/trunk/includes/css)
-
tags/1.2.1/includes/css/style.css (modified) (1 diff)
-
tags/1.2.1/includes/js/auto-validation.js (deleted)
-
tags/1.2.1/includes/js/full-to-half.js (added)
-
tags/1.2.1/includes/js/realtime-validation.js (added)
-
tags/1.2.1/includes/js/zenkaku-to-hankaku.js (deleted)
-
tags/1.2.1/includes/options-page.php (added)
-
tags/1.2.1/includes/realtime-validation.php (added)
-
tags/1.2.1/languages (deleted)
-
tags/1.2.1/modules/confirm-email.php (modified) (8 diffs)
-
tags/1.2.1/modules/dob.php (modified) (11 diffs)
-
tags/1.2.1/readme.txt (copied) (copied from watts/trunk/readme.txt) (2 diffs)
-
tags/1.2.1/watts.php (copied) (copied from watts/trunk/watts.php) (2 diffs)
-
trunk/includes/auto-validation.php (deleted)
-
trunk/includes/controller.php (modified) (1 diff)
-
trunk/includes/css/style.css (modified) (1 diff)
-
trunk/includes/js/auto-validation.js (deleted)
-
trunk/includes/js/full-to-half.js (added)
-
trunk/includes/js/realtime-validation.js (added)
-
trunk/includes/js/zenkaku-to-hankaku.js (deleted)
-
trunk/includes/options-page.php (added)
-
trunk/includes/realtime-validation.php (added)
-
trunk/languages (deleted)
-
trunk/modules/confirm-email.php (modified) (8 diffs)
-
trunk/modules/dob.php (modified) (11 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/watts.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
watts/tags/1.2.1/includes/controller.php
r2628083 r2740791 1 1 <?php 2 require_once ' auto-validation.php';3 class Watts_Rest_Controller 4 {2 require_once 'realtime-validation.php'; 3 4 class Watts_Rest_Controller { 5 5 const route_namespace = 'watts/v1'; 6 public function register_routes() 7 {6 7 public function register_routes() { 8 8 register_rest_route( 9 9 self::route_namespace, 10 10 '/(?P<id>\d+)/validation', 11 11 [ 12 'methods' => WP_REST_Server::CREATABLE,12 'methods' => WP_REST_Server::CREATABLE, 13 13 'permission_callback' => '__return_true', 14 'callback' => array($this, 'auto_validation'),14 'callback' => array( $this, 'realtime_validation' ), 15 15 ] 16 16 ); 17 17 } 18 18 19 public function auto_validation(WP_REST_Request $request)20 {21 $ wav = new Watts_Auto_Validation();22 $response = $wav->main($request); 23 return rest_ensure_response( $response);19 public function realtime_validation( WP_REST_Request $request ) { 20 $wrv = new Watts_Realtime_Validation(); 21 $response = $wrv->main( $request ); 22 23 return rest_ensure_response( $response ); 24 24 } 25 25 } -
watts/tags/1.2.1/includes/css/style.css
r2719563 r2740791 1 1 .watts-validation-icon { 2 width:30px; 3 height:30px; 4 vertical-align:middle; 2 vertical-align: middle; 5 3 margin-left: 10px; 4 } 5 6 .watts-validation-icon-small { 7 width: 20px; 8 height: 20px; 9 } 10 11 .watts-validation-icon-medium { 12 width: 25px; 13 height: 25px; 14 } 15 16 .watts-validation-icon-large { 17 width: 30px; 18 height: 30px; 6 19 } 7 20 -
watts/tags/1.2.1/modules/confirm-email.php
r2630535 r2740791 1 1 <?php 2 if (function_exists('wpcf7_add_form_tag')) { 3 wpcf7_add_form_tag('confirm_email', 'watts_confirm_email_form_tag_handler', true); 4 wpcf7_add_form_tag('confirm_email*', 'watts_confirm_email_form_tag_handler', true); 5 } 6 7 function watts_confirm_email_form_tag_handler($tag) 8 { 2 if ( function_exists( 'wpcf7_add_form_tag' ) ) { 3 wpcf7_add_form_tag( 'confirm_email', 'watts_confirm_email_form_tag_handler', true ); 4 wpcf7_add_form_tag( 'confirm_email*', 'watts_confirm_email_form_tag_handler', true ); 5 } 6 7 function watts_confirm_email_form_tag_handler( $tag ) { 9 8 if ( empty( $tag->name ) ) { 10 9 return ''; … … 23 22 $atts = array(); 24 23 25 $atts['class'] = $tag->get_class_option( $class );26 $atts['id'] = $tag->get_id_option();24 $atts['class'] = $tag->get_class_option( $class ); 25 $atts['id'] = $tag->get_id_option(); 27 26 $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true ); 28 27 … … 39 38 40 39 if ( $validation_error ) { 41 $atts['aria-invalid'] = 'true';40 $atts['aria-invalid'] = 'true'; 42 41 $atts['aria-describedby'] = wpcf7_get_validation_error_reference( 43 42 $tag->name … … 50 49 51 50 if ( $tag->has_option( 'placeholder' ) 52 or $tag->has_option( 'watermark' ) ) {51 or $tag->has_option( 'watermark' ) ) { 53 52 $atts['placeholder'] = $value; 54 $value = '';53 $value = ''; 55 54 } 56 55 … … 81 80 } 82 81 83 add_filter('wpcf7_validate_confirm_email', 'watts_confirm_email_validation_filter', 10, 2); 84 add_filter('wpcf7_validate_confirm_email*', 'watts_confirm_email_validation_filter', 10, 2); 85 86 function watts_confirm_email_validation_filter($result, $tag) 87 { 82 add_filter( 'wpcf7_validate_confirm_email', 'watts_confirm_email_validation_filter', 10, 2 ); 83 add_filter( 'wpcf7_validate_confirm_email*', 'watts_confirm_email_validation_filter', 10, 2 ); 84 85 function watts_confirm_email_validation_filter( $result, $tag ) { 88 86 $name = $tag->name; 89 87 90 $value = isset( $_POST[ $name] )91 ? trim( wp_unslash( strtr( (string) $_POST[ $name], "\n", " " ) ) )88 $value = isset( $_POST[ $name ] ) 89 ? trim( wp_unslash( strtr( (string) $_POST[ $name ], "\n", " " ) ) ) 92 90 : ''; 93 91 … … 97 95 $result->invalidate( $tag, wpcf7_get_message( 'invalid_email' ) ); 98 96 } 99 $target = $tag->get_option( 'target' )[0];100 $target_value = isset( $_POST[$target])101 ? trim( wp_unslash( strtr( (string) $_POST[ $target], "\n", " " ) ) )97 $target = $tag->get_option( 'target' )[0]; 98 $target_value = isset( $_POST[ $target ] ) 99 ? trim( wp_unslash( strtr( (string) $_POST[ $target ], "\n", " " ) ) ) 102 100 : ''; 103 if ( $value !== $target_value) {104 $result->invalidate( $tag, __( 'Email addresses you entered do not match.', 'watts'));101 if ( $value !== $target_value ) { 102 $result->invalidate( $tag, __( 'Email addresses you entered do not match.', 'watts' ) ); 105 103 } 106 104 … … 108 106 } 109 107 110 add_action('wpcf7_admin_init', 'watts_add_tag_generator_confirm_email', 16, 0); 111 112 function watts_add_tag_generator_confirm_email() 113 { 108 add_action( 'wpcf7_admin_init', 'watts_add_tag_generator_confirm_email', 16, 0 ); 109 110 function watts_add_tag_generator_confirm_email() { 114 111 $tag_generator = WPCF7_TagGenerator::get_instance(); 115 $tag_generator->add('confirm-email', __('confirm email', 'watts'), 116 'watts_tag_generator_confirm_email'); 117 } 118 119 function watts_tag_generator_confirm_email($contact_form, $args = '') 120 { 121 $args = wp_parse_args($args, array()); 112 $tag_generator->add( 'confirm-email', __( 'confirm email', 'watts' ), 113 'watts_tag_generator_confirm_email' ); 114 } 115 116 function watts_tag_generator_confirm_email( $contact_form, $args = '' ) { 117 $args = wp_parse_args( $args, array() ); 122 118 $type = 'confirm_email'; 123 119 … … 125 121 126 122 ?> 127 <div class="control-box"> 128 <fieldset> 129 <legend><?php echo esc_html($description); ?></legend> 130 131 <table class="form-table"> 132 <tbody> 133 <tr> 134 <th scope="row"><?php echo esc_html(__('Field type', 'watts')); ?></th> 135 <td> 123 <div class="control-box"> 136 124 <fieldset> 137 <legend class="screen-reader-text"><?php echo esc_html(__('Field type', 'watts')); ?></legend> 138 <label><input type="checkbox" name="required" /> <?php echo esc_html(__('Required field', 'watts')); ?></label> 125 <legend><?php echo esc_html( $description ); ?></legend> 126 127 <table class="form-table"> 128 <tbody> 129 <tr> 130 <th scope="row"><?php echo esc_html( __( 'Field type', 'watts' ) ); ?></th> 131 <td> 132 <fieldset> 133 <legend 134 class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'watts' ) ); ?></legend> 135 <label><input type="checkbox" 136 name="required"/> <?php echo esc_html( __( 'Required field', 'watts' ) ); ?> 137 </label> 138 </fieldset> 139 </td> 140 </tr> 141 142 <tr> 143 <th scope="row"><label 144 for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'watts' ) ); ?></label> 145 </th> 146 <td><input type="text" name="name" class="tg-name oneline" 147 id="<?php echo esc_attr( $args['content'] . '-name' ); ?>"/></td> 148 </tr> 149 150 <tr> 151 <th scope="row"><label 152 for="<?php echo esc_attr( $args['content'] . '-target' ); ?>"><?php echo esc_html( __( 'Target name*', 'watts' ) ); ?></label> 153 </th> 154 <td><input type="text" name="target" class="targetvalue oneline option" 155 id="<?php echo esc_attr( $args['content'] . '-target' ); ?>"/></td> 156 </tr> 157 158 <tr> 159 <th scope="row"><label 160 for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'watts' ) ); ?></label> 161 </th> 162 <td><input type="text" name="values" class="oneline" 163 id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"/><br/> 164 </tr> 165 166 <tr> 167 <th scope="row"><label 168 for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'watts' ) ); ?></label> 169 </th> 170 <td><input type="text" name="id" class="idvalue oneline option" 171 id="<?php echo esc_attr( $args['content'] . '-id' ); ?>"/></td> 172 </tr> 173 174 <tr> 175 <th scope="row"><label 176 for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'watts' ) ); ?></label> 177 </th> 178 <td><input type="text" name="class" class="classvalue oneline option" 179 id="<?php echo esc_attr( $args['content'] . '-class' ); ?>"/></td> 180 </tr> 181 </tbody> 182 </table> 139 183 </fieldset> 140 </td>141 </tr>142 143 <tr>144 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-name'); ?>"><?php echo esc_html(__('Name', 'watts')); ?></label></th>145 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr($args['content'] . '-name'); ?>" /></td>146 </tr>147 148 <tr>149 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-target'); ?>"><?php echo esc_html(__('Target name*', 'watts')); ?></label></th>150 <td><input type="text" name="target" class="targetvalue oneline option" id="<?php echo esc_attr($args['content'] . '-target'); ?>" /></td>151 </tr>152 153 <tr>154 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-values'); ?>"><?php echo esc_html(__('Default value', 'watts')); ?></label></th>155 <td><input type="text" name="values" class="oneline" id="<?php echo esc_attr($args['content'] . '-values'); ?>" /><br />156 </tr>157 158 <tr>159 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-id'); ?>"><?php echo esc_html(__('Id attribute', 'watts')); ?></label></th>160 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr($args['content'] . '-id'); ?>" /></td>161 </tr>162 163 <tr>164 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-class'); ?>"><?php echo esc_html(__('Class attribute', 'watts')); ?></label></th>165 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr($args['content'] . '-class'); ?>" /></td>166 </tr>167 </tbody>168 </table>169 </fieldset>170 </div>171 172 <div class="insert-box">173 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />174 175 <div class="submitbox">176 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr(__('Insert Tag', 'watts')); ?>" />177 184 </div> 178 185 179 <br class="clear" /> 180 181 <p class="description mail-tag"><label for="<?php echo esc_attr($args['content'] . '-mailtag'); ?>"><?php echo sprintf(esc_html(__("To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'watts')), '<strong><span class="mail-tag"></span></strong>'); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr($args['content'] . '-mailtag'); ?>" /></label></p> 182 </div> 183 <?php 184 } 186 <div class="insert-box"> 187 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()"/> 188 189 <div class="submitbox"> 190 <input type="button" class="button button-primary insert-tag" 191 value="<?php echo esc_attr( __( 'Insert Tag', 'watts' ) ); ?>"/> 192 </div> 193 194 <br class="clear"/> 195 196 <p class="description mail-tag"><label 197 for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'watts' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?> 198 <input type="text" class="mail-tag code hidden" readonly="readonly" 199 id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"/></label></p> 200 </div> 201 <?php 202 } -
watts/tags/1.2.1/modules/dob.php
r2648825 r2740791 1 1 <?php 2 2 3 if (function_exists('wpcf7_add_form_tag')) { 4 wpcf7_add_form_tag('dob', 'watts_dob_form_tag_handler', true); 5 wpcf7_add_form_tag('dob*', 'watts_dob_form_tag_handler', true); 6 } 7 8 function watts_dob_form_tag_handler($tag) 9 { 10 if (empty($tag->name)) { 3 if ( function_exists( 'wpcf7_add_form_tag' ) ) { 4 wpcf7_add_form_tag( 'dob', 'watts_dob_form_tag_handler', true ); 5 wpcf7_add_form_tag( 'dob*', 'watts_dob_form_tag_handler', true ); 6 } 7 8 function watts_dob_form_tag_handler( $tag ) { 9 if ( empty( $tag->name ) ) { 11 10 return ''; 12 11 } 13 12 14 $validation_error = wpcf7_get_validation_error( $tag->name);15 16 $class = wpcf7_form_controls_class( $tag->type);13 $validation_error = wpcf7_get_validation_error( $tag->name ); 14 15 $class = wpcf7_form_controls_class( $tag->type ); 17 16 18 17 $class .= ' wpcf7-validates-as-dob'; 19 18 20 if ( $validation_error) {19 if ( $validation_error ) { 21 20 $class .= ' wpcf7-not-valid'; 22 21 } … … 24 23 $atts = array(); 25 24 26 $atts['class'] = $tag->get_class_option($class);27 $atts['id'] = $tag->get_id_option();28 $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true);29 $format = isset($tag->get_option('format')[0]) ? $tag->get_option('format')[0] : 'YMD';30 31 if ( $tag->is_required()) {25 $atts['class'] = $tag->get_class_option( $class ); 26 $atts['id'] = $tag->get_id_option(); 27 $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true ); 28 $format = isset( $tag->get_option( 'format' )[0] ) ? $tag->get_option( 'format' )[0] : 'YMD'; 29 30 if ( $tag->is_required() ) { 32 31 $atts['aria-required'] = 'true'; 33 32 } 34 33 35 if ( $validation_error) {36 $atts['aria-invalid'] = 'true';34 if ( $validation_error ) { 35 $atts['aria-invalid'] = 'true'; 37 36 $atts['aria-describedby'] = wpcf7_get_validation_error_reference( 38 37 $tag->name … … 42 41 } 43 42 44 $value = (string) reset($tag->values); 45 46 $value = $tag->get_default_option($value); 47 if ($value) { 48 $datetime_obj = date_create_immutable($value, wp_timezone()); 49 50 if ($datetime_obj) { 43 $value = (string) reset( $tag->values ); 44 $default_value = [ 45 'year' => null, 46 'month' => null, 47 'day' => null, 48 ]; 49 50 $value = $tag->get_default_option( $value ); 51 if ( $value ) { 52 $datetime_obj = date_create_immutable( $value, wp_timezone() ); 53 54 if ( $datetime_obj ) { 51 55 // NOTE: プルダウンのvalueが0サプレスなので、初期値も合わせる 52 56 $default_value = [ 53 'year' => $datetime_obj->format('Y'),54 'month' => $datetime_obj->format( 'n'),55 'day' => $datetime_obj->format('j'),57 'year' => $datetime_obj->format( 'Y' ), 58 'month' => $datetime_obj->format( 'n' ), 59 'day' => $datetime_obj->format( 'j' ), 56 60 ]; 57 61 } … … 60 64 // NOTE: 寿命をもとに生年月日の範囲を算出 61 65 $max_lifespan = 120; 62 $start_year = intval(date_i18n('Y'));63 $until_year = $start_year - $max_lifespan;66 $start_year = intval( date_i18n( 'Y' ) ); 67 $until_year = $start_year - $max_lifespan; 64 68 65 69 $html_parts = [ 66 'year' => watts_dob_form_part($tag, $atts, 'year', $default_value['year'], range($start_year, $until_year), esc_html(__('Year', 'watts'))),67 'month' => watts_dob_form_part( $tag, $atts, 'month', $default_value['month'], range(1, 12), esc_html(__('Month', 'watts'))),68 'day' => watts_dob_form_part($tag, $atts, 'day', $default_value['day'], range(1, 31), esc_html(__('Day', 'watts')))70 'year' => watts_dob_form_part( $tag, $atts, 'year', $default_value['year'], range( $start_year, $until_year ), esc_html( __( 'Year', 'watts' ) ) ), 71 'month' => watts_dob_form_part( $tag, $atts, 'month', $default_value['month'], range( 1, 12 ), esc_html( __( 'Month', 'watts' ) ) ), 72 'day' => watts_dob_form_part( $tag, $atts, 'day', $default_value['day'], range( 1, 31 ), esc_html( __( 'Day', 'watts' ) ) ) 69 73 ]; 70 74 71 75 $html = ''; 72 if ( $format === 'DMY') {76 if ( $format === 'DMY' ) { 73 77 $html = $html_parts['day'] . $html_parts['month'] . $html_parts['year']; 74 } elseif ( $format === 'MDY') {78 } elseif ( $format === 'MDY' ) { 75 79 $html = $html_parts['month'] . $html_parts['day'] . $html_parts['year']; 76 80 } else { // default … … 80 84 $html = sprintf( 81 85 '<span class="wpcf7-form-control-wrap %1$s">%2$s%3$s</span>', 82 sanitize_html_class( $tag->name), $html, $validation_error86 sanitize_html_class( $tag->name ), $html, $validation_error 83 87 ); 84 88 … … 86 90 } 87 91 88 function watts_dob_form_part($tag, $atts, $name_key, $default_value, $values, $blank_item) 89 { 90 $atts['name'] = sprintf('%1$s[%2$s]', $tag->name, $name_key); 91 $atts['id'] .= '-' . $name_key; 92 function watts_dob_form_part( $tag, $atts, $name_key, $default_value, $values, $blank_item ) { 93 $atts['name'] = sprintf( '%1$s[%2$s]', $tag->name, $name_key ); 94 $atts['id'] .= '-' . $name_key; 92 95 93 96 $labels = $values; 94 97 95 $include_blank = $tag->has_option( 'include_blank');96 97 if ( $include_blank) {98 array_unshift( $labels, $blank_item);99 array_unshift( $values, '');100 } 101 102 $html = '';103 $hangover = wpcf7_get_hangover( $tag->name);104 105 foreach ( $values as $key => $value) {106 if ( $hangover) {107 $selected = $value === (int) $hangover[ $name_key];98 $include_blank = $tag->has_option( 'include_blank' ); 99 100 if ( $include_blank ) { 101 array_unshift( $labels, $blank_item ); 102 array_unshift( $values, '' ); 103 } 104 105 $html = ''; 106 $hangover = wpcf7_get_hangover( $tag->name ); 107 108 foreach ( $values as $key => $value ) { 109 if ( $hangover ) { 110 $selected = $value === (int) $hangover[ $name_key ]; 108 111 } else { 109 112 $selected = $value === (int) $default_value; … … 111 114 112 115 $item_atts = array( 113 'value' => $value,116 'value' => $value, 114 117 'selected' => $selected ? 'selected' : '', 115 118 ); 116 119 117 $item_atts = wpcf7_format_atts( $item_atts);118 119 $label = isset( $labels[$key]) ? $labels[$key] : $value;120 $item_atts = wpcf7_format_atts( $item_atts ); 121 122 $label = isset( $labels[ $key ] ) ? $labels[ $key ] : $value; 120 123 121 124 $html .= sprintf( 122 125 '<option %1$s>%2$s</option>', 123 126 $item_atts, 124 esc_html( $label)127 esc_html( $label ) 125 128 ); 126 129 } 127 $atts = wpcf7_format_atts( $atts);130 $atts = wpcf7_format_atts( $atts ); 128 131 129 132 $html = sprintf( … … 135 138 } 136 139 137 add_filter('wpcf7_posted_data_dob', 'watts_posted_data_dob', 10, 3); 138 add_filter('wpcf7_posted_data_dob*', 'watts_posted_data_dob', 10, 3); 139 140 function watts_posted_data_dob($value, $value_orig, $tag) 141 { 142 if (!isset($value_orig) || 143 !isset($value_orig['year']) || 144 !isset($value_orig['month']) || 145 !isset($value_orig['day']) || 146 in_array('', $value_orig, true)) { 140 add_filter( 'wpcf7_posted_data_dob', 'watts_posted_data_dob', 10, 3 ); 141 add_filter( 'wpcf7_posted_data_dob*', 'watts_posted_data_dob', 10, 3 ); 142 143 function watts_posted_data_dob( $value, $value_orig, $tag ) { 144 if ( ! isset( $value_orig ) || 145 ! isset( $value_orig['year'] ) || 146 ! isset( $value_orig['month'] ) || 147 ! isset( $value_orig['day'] ) || 148 in_array( '', $value_orig, true ) ) { 147 149 return ''; 148 150 } 149 151 150 $format = isset($tag->get_option('format')[0]) ? $tag->get_option('format')[0] : 'YMD';151 $separator_option = isset( $tag->get_option('separator')[0]) ? $tag->get_option('separator')[0] : 'slash';152 $separator_map = [153 'slash' => '/',154 'dash' => '-',152 $format = isset( $tag->get_option( 'format' )[0] ) ? $tag->get_option( 'format' )[0] : 'YMD'; 153 $separator_option = isset( $tag->get_option( 'separator' )[0] ) ? $tag->get_option( 'separator' )[0] : 'slash'; 154 $separator_map = [ 155 'slash' => '/', 156 'dash' => '-', 155 157 'period' => '.', 156 'comma' => ',',157 'blank' => ' '158 ]; 159 $separator = array_key_exists($separator_option, $separator_map) ? $separator_map[$separator_option] : '/';160 $leading_zero = $tag->has_option('leading_zero');161 162 $year = $value_orig['year'];163 $month = $value_orig['month'];164 $day = $value_orig['day'];165 if ($leading_zero) {166 $month = str_pad($month, 2, '0', STR_PAD_LEFT);167 $day = str_pad($day, 2, '0', STR_PAD_LEFT);158 'comma' => ',', 159 'blank' => ' ' 160 ]; 161 $separator = array_key_exists( $separator_option, $separator_map ) ? $separator_map[ $separator_option ] : '/'; 162 $leading_zero = $tag->has_option( 'leading_zero' ); 163 164 $year = $value_orig['year']; 165 $month = $value_orig['month']; 166 $day = $value_orig['day']; 167 if ( $leading_zero ) { 168 $month = str_pad( $month, 2, '0', STR_PAD_LEFT ); 169 $day = str_pad( $day, 2, '0', STR_PAD_LEFT ); 168 170 } 169 171 170 172 $result = ''; 171 if ( $format === 'DMY') {172 $result = implode( [$day, $month, $year], $separator);173 } elseif ( $format === 'MDY') {174 $result = implode( [$month, $day, $year], $separator);173 if ( $format === 'DMY' ) { 174 $result = implode( [ $day, $month, $year ], $separator ); 175 } elseif ( $format === 'MDY' ) { 176 $result = implode( [ $month, $day, $year ], $separator ); 175 177 } else { // default 176 $result = implode( [$year, $month, $day], $separator);178 $result = implode( [ $year, $month, $day ], $separator ); 177 179 } 178 180 … … 180 182 } 181 183 182 add_filter('wpcf7_validate_dob', 'watts_dob_validation_filter', 10, 2); 183 add_filter('wpcf7_validate_dob*', 'watts_dob_validation_filter', 10, 2); 184 185 function watts_dob_validation_filter($result, $tag) 186 { 184 add_filter( 'wpcf7_validate_dob', 'watts_dob_validation_filter', 10, 2 ); 185 add_filter( 'wpcf7_validate_dob*', 'watts_dob_validation_filter', 10, 2 ); 186 187 function watts_dob_validation_filter( $result, $tag ) { 187 188 $name = $tag->name; 188 189 189 190 $values = [ 190 'year' => isset($_POST[$name]['year']) ? trim(sanitize_text_field($_POST[$name]['year'])) : '',191 'month' => isset( $_POST[$name]['month']) ? trim(sanitize_text_field($_POST[$name]['month'])) : '',192 'day' => isset($_POST[$name]['day']) ? trim(sanitize_text_field($_POST[$name]['day'])) : '',191 'year' => isset( $_POST[ $name ]['year'] ) ? trim( sanitize_text_field( $_POST[ $name ]['year'] ) ) : '', 192 'month' => isset( $_POST[ $name ]['month'] ) ? trim( sanitize_text_field( $_POST[ $name ]['month'] ) ) : '', 193 'day' => isset( $_POST[ $name ]['day'] ) ? trim( sanitize_text_field( $_POST[ $name ]['day'] ) ) : '', 193 194 ]; 194 195 195 196 $blank_flags = [ 196 'year' => $values['year'] === '',197 'year' => $values['year'] === '', 197 198 'month' => $values['month'] === '', 198 'day' => $values['day'] === '',199 ]; 200 201 if ( !in_array(false, $blank_flags, true) !== false) {199 'day' => $values['day'] === '', 200 ]; 201 202 if ( ! in_array( false, $blank_flags, true ) !== false ) { 202 203 // すべて入力されていない 203 if ( $tag->is_required()) {204 if ( $tag->is_required() ) { 204 205 // 必須項目 205 206 $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); 206 207 } 207 208 // 必須項目ではなく、全て入力されていない場合は許容 208 } else if ( in_array(true, $blank_flags, true) !== false) {209 } else if ( in_array( true, $blank_flags, true ) !== false ) { 209 210 // 中途半端な入力 210 211 $result->invalidate( $tag, wpcf7_get_message( 'invalid_date' ) ); 211 } else if ( in_array(false, array_map('is_numeric', array_values($values)), true)) {212 } else if ( in_array( false, array_map( 'is_numeric', array_values( $values ) ), true ) ) { 212 213 // 数値かどうか 213 214 $result->invalidate( $tag, wpcf7_get_message( 'invalid_date' ) ); 214 } else if ( !checkdate($values['month'], $values['day'], $values['year'])) {215 } else if ( ! checkdate( $values['month'], $values['day'], $values['year'] ) ) { 215 216 // 数値が入力されていた場合のチェック 216 $result->invalidate( $tag, __( 'The date specified is not a valid date value.', 'watts'));217 $result->invalidate( $tag, __( 'The date specified is not a valid date value.', 'watts' ) ); 217 218 } 218 219 … … 220 221 } 221 222 222 add_action('wpcf7_admin_init', 'watts_add_tag_generator_dob', 20, 0); 223 224 function watts_add_tag_generator_dob() 225 { 223 add_action( 'wpcf7_admin_init', 'watts_add_tag_generator_dob', 20, 0 ); 224 225 function watts_add_tag_generator_dob() { 226 226 $tag_generator = WPCF7_TagGenerator::get_instance(); 227 $tag_generator->add('dob', __('DOB', 'watts'), 228 'watts_tag_generator_dob'); 229 } 230 231 function watts_tag_generator_dob($contact_form, $args = '') 232 { 233 $args = wp_parse_args($args, array()); 227 $tag_generator->add( 'dob', __( 'DOB', 'watts' ), 228 'watts_tag_generator_dob' ); 229 } 230 231 function watts_tag_generator_dob( $contact_form, $args = '' ) { 232 $args = wp_parse_args( $args, array() ); 234 233 $type = 'dob'; 235 234 … … 237 236 238 237 ?> 239 <div class="control-box"> 240 <fieldset> 241 <legend><?php echo esc_html($description); ?></legend> 242 243 <table class="form-table"> 244 <tbody> 245 <tr> 246 <th scope="row"><?php echo esc_html(__('Field type', 'watts')); ?></th> 247 <td> 238 <div class="control-box"> 248 239 <fieldset> 249 <legend class="screen-reader-text"><?php echo esc_html(__('Field type', 'watts')); ?></legend> 250 <label><input type="checkbox" name="required" /> <?php echo esc_html(__('Required field', 'watts')); ?></label> 240 <legend><?php echo esc_html( $description ); ?></legend> 241 242 <table class="form-table"> 243 <tbody> 244 <tr> 245 <th scope="row"><?php echo esc_html( __( 'Field type', 'watts' ) ); ?></th> 246 <td> 247 <fieldset> 248 <legend 249 class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'watts' ) ); ?></legend> 250 <label><input type="checkbox" 251 name="required"/> <?php echo esc_html( __( 'Required field', 'watts' ) ); ?> 252 </label> 253 </fieldset> 254 </td> 255 </tr> 256 257 <tr> 258 <th scope="row"><label 259 for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'watts' ) ); ?></label> 260 </th> 261 <td><input type="text" name="name" class="tg-name oneline" 262 id="<?php echo esc_attr( $args['content'] . '-name' ); ?>"/></td> 263 </tr> 264 265 <tr> 266 <th scope="row"><label 267 for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'watts' ) ); ?></label> 268 </th> 269 <td><input type="text" name="values" class="oneline" 270 id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"/><br/> 271 </tr> 272 273 <tr> 274 <th scope="row"><?php echo esc_html( __( 'Options', 'watts' ) ); ?></th> 275 <td> 276 <fieldset> 277 <legend 278 class="screen-reader-text"><?php echo esc_html( __( 'Options', 'watts' ) ); ?></legend> 279 <label><input type="checkbox" name="include_blank" 280 class="option"/> <?php echo esc_html( __( 'Insert a blank item as the first option', 'watts' ) ); ?> 281 </label> 282 </fieldset> 283 </td> 284 </tr> 285 286 <tr> 287 <th scope="row" rowspan="3"><?php echo esc_html( __( 'Date Format', 'watts' ) ); ?></th> 288 <td> 289 <fieldset> 290 <legend><?php echo esc_html( __( 'Date Style', 'watts' ) ); ?></legend> 291 <input type="radio" name="format" class="formatvalue option" 292 id="<?php echo esc_attr( $args['content'] . '-format-ymd' ); ?>" value="YMD" checked> 293 <label for="<?php echo esc_attr( $args['content'] . '-format-ymd' ); ?>">YMD</label> 294 <input type="radio" name="format" class="formatvalue option" 295 id="<?php echo esc_attr( $args['content'] . '-format-mdy' ); ?>" value="MDY"> 296 <label for="<?php echo esc_attr( $args['content'] . '-format-mdy' ); ?>">MDY</label> 297 <input type="radio" name="format" class="formatvalue option" 298 id="<?php echo esc_attr( $args['content'] . '-format-dmy' ); ?>" value="DMY"> 299 <label for="<?php echo esc_attr( $args['content'] . '-format-dmy' ); ?>">DMY</label> 300 </fieldset> 301 </td> 302 </tr> 303 <tr> 304 <td> 305 <fieldset> 306 <legend><?php echo esc_html( __( 'Date Separator', 'watts' ) ); ?></legend> 307 <input type="radio" name="separator" class="separatorvalue option" 308 id="<?php echo esc_attr( $args['content'] . '-separator-slash' ); ?>" value="slash" 309 checked> 310 <label 311 for="<?php echo esc_attr( $args['content'] . '-separator-slash' ); ?>"><?php echo esc_html( __( 'slash', 'watts' ) ); ?></label> 312 <input type="radio" name="separator" class="separatorvalue option" 313 id="<?php echo esc_attr( $args['content'] . '-separator-dash' ); ?>" value="dash"> 314 <label 315 for="<?php echo esc_attr( $args['content'] . '-separator-dash' ); ?>"><?php echo esc_html( __( 'dash', 'watts' ) ); ?></label> 316 <input type="radio" name="separator" class="separatorvalue option" 317 id="<?php echo esc_attr( $args['content'] . '-separator-period' ); ?>" 318 value="period"> 319 <label 320 for="<?php echo esc_attr( $args['content'] . '-separator-period' ); ?>"><?php echo esc_html( __( 'period', 'watts' ) ); ?></label> 321 <input type="radio" name="separator" class="separatorvalue option" 322 id="<?php echo esc_attr( $args['content'] . '-separator-comma' ); ?>" value="comma"> 323 <label 324 for="<?php echo esc_attr( $args['content'] . '-separator-comma' ); ?>"><?php echo esc_html( __( 'comma', 'watts' ) ); ?></label> 325 <input type="radio" name="separator" class="separatorvalue option" 326 id="<?php echo esc_attr( $args['content'] . '-separator-blank' ); ?>" value="blank"> 327 <label 328 for="<?php echo esc_attr( $args['content'] . '-separator-blank' ); ?>"><?php echo esc_html( __( 'blank', 'watts' ) ); ?></label> 329 </fieldset> 330 </td> 331 </tr> 332 333 <tr> 334 <td> 335 <fieldset> 336 <legend><?php echo esc_html( __( 'Display Leading Zero', 'watts' ) ); ?></legend> 337 <label><input type="checkbox" name="leading_zero" 338 class="option"/> <?php echo esc_html( __( 'Indicates whether to display (or suppress) leading zeros.', 'watts' ) ); ?> 339 </label> 340 </fieldset> 341 </td> 342 </tr> 343 344 <tr> 345 <th scope="row"><label 346 for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'watts' ) ); ?></label> 347 </th> 348 <td><input type="text" name="id" class="idvalue oneline option" 349 id="<?php echo esc_attr( $args['content'] . '-id' ); ?>"/></td> 350 </tr> 351 352 <tr> 353 <th scope="row"><label 354 for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'watts' ) ); ?></label> 355 </th> 356 <td><input type="text" name="class" class="classvalue oneline option" 357 id="<?php echo esc_attr( $args['content'] . '-class' ); ?>"/></td> 358 </tr> 359 </tbody> 360 </table> 251 361 </fieldset> 252 </td>253 </tr>254 255 <tr>256 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-name'); ?>"><?php echo esc_html(__('Name', 'watts')); ?></label></th>257 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr($args['content'] . '-name'); ?>" /></td>258 </tr>259 260 <tr>261 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-values'); ?>"><?php echo esc_html(__('Default value', 'watts')); ?></label></th>262 <td><input type="text" name="values" class="oneline" id="<?php echo esc_attr($args['content'] . '-values'); ?>" /><br />263 </tr>264 265 <tr>266 <th scope="row"><?php echo esc_html(__('Options', 'watts')); ?></th>267 <td>268 <fieldset>269 <legend class="screen-reader-text"><?php echo esc_html(__('Options', 'watts')); ?></legend>270 <label><input type="checkbox" name="include_blank" class="option" /> <?php echo esc_html(__('Insert a blank item as the first option', 'watts')); ?></label>271 </fieldset>272 </td>273 </tr>274 275 <tr>276 <th scope="row" rowspan="3"><?php echo esc_html(__('Date Format', 'watts')); ?></th>277 <td>278 <fieldset>279 <legend><?php echo esc_html(__('Date Style', 'watts')); ?></legend>280 <input type="radio" name="format" class="formatvalue option" id="<?php echo esc_attr($args['content'] . '-format-ymd'); ?>" value="YMD" checked >281 <label for="<?php echo esc_attr($args['content'] . '-format-ymd'); ?>">YMD</label>282 <input type="radio" name="format" class="formatvalue option" id="<?php echo esc_attr($args['content'] . '-format-mdy'); ?>" value="MDY" >283 <label for="<?php echo esc_attr($args['content'] . '-format-mdy'); ?>">MDY</label>284 <input type="radio" name="format" class="formatvalue option" id="<?php echo esc_attr($args['content'] . '-format-dmy'); ?>" value="DMY" >285 <label for="<?php echo esc_attr($args['content'] . '-format-dmy'); ?>">DMY</label>286 </fieldset>287 </td>288 </tr>289 <tr>290 <td>291 <fieldset>292 <legend><?php echo esc_html(__('Date Separator', 'watts')); ?></legend>293 <input type="radio" name="separator" class="separatorvalue option" id="<?php echo esc_attr($args['content'] . '-separator-slash'); ?>" value="slash" checked >294 <label for="<?php echo esc_attr($args['content'] . '-separator-slash'); ?>"><?php echo esc_html(__('slash', 'watts')); ?></label>295 <input type="radio" name="separator" class="separatorvalue option" id="<?php echo esc_attr($args['content'] . '-separator-dash'); ?>" value="dash" >296 <label for="<?php echo esc_attr($args['content'] . '-separator-dash'); ?>"><?php echo esc_html(__('dash', 'watts')); ?></label>297 <input type="radio" name="separator" class="separatorvalue option" id="<?php echo esc_attr($args['content'] . '-separator-period'); ?>" value="period" >298 <label for="<?php echo esc_attr($args['content'] . '-separator-period'); ?>"><?php echo esc_html(__('period', 'watts')); ?></label>299 <input type="radio" name="separator" class="separatorvalue option" id="<?php echo esc_attr($args['content'] . '-separator-comma'); ?>" value="comma" >300 <label for="<?php echo esc_attr($args['content'] . '-separator-comma'); ?>"><?php echo esc_html(__('comma', 'watts')); ?></label>301 <input type="radio" name="separator" class="separatorvalue option" id="<?php echo esc_attr($args['content'] . '-separator-blank'); ?>" value="blank" >302 <label for="<?php echo esc_attr($args['content'] . '-separator-blank'); ?>"><?php echo esc_html(__('blank', 'watts')); ?></label>303 </fieldset>304 </td>305 </tr>306 307 <tr>308 <td>309 <fieldset>310 <legend><?php echo esc_html(__('Display Leading Zero', 'watts')); ?></legend>311 <label><input type="checkbox" name="leading_zero" class="option" /> <?php echo esc_html(__('Indicates whether to display (or suppress) leading zeros.', 'watts')); ?></label>312 </fieldset>313 </td>314 </tr>315 316 <tr>317 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-id'); ?>"><?php echo esc_html(__('Id attribute', 'watts')); ?></label></th>318 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr($args['content'] . '-id'); ?>" /></td>319 </tr>320 321 <tr>322 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-class'); ?>"><?php echo esc_html(__('Class attribute', 'watts')); ?></label></th>323 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr($args['content'] . '-class'); ?>" /></td>324 </tr>325 </tbody>326 </table>327 </fieldset>328 </div>329 330 <div class="insert-box">331 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />332 333 <div class="submitbox">334 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr(__('Insert Tag', 'watts')); ?>" />335 362 </div> 336 363 337 <br class="clear" /> 338 339 <p class="description mail-tag"><label for="<?php echo esc_attr($args['content'] . '-mailtag'); ?>"><?php echo sprintf(esc_html(__("To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'watts')), '<strong><span class="mail-tag"></span></strong>'); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr($args['content'] . '-mailtag'); ?>" /></label></p> 340 </div> 341 <?php 342 } 364 <div class="insert-box"> 365 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()"/> 366 367 <div class="submitbox"> 368 <input type="button" class="button button-primary insert-tag" 369 value="<?php echo esc_attr( __( 'Insert Tag', 'watts' ) ); ?>"/> 370 </div> 371 372 <br class="clear"/> 373 374 <p class="description mail-tag"><label 375 for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'watts' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?> 376 <input type="text" class="mail-tag code hidden" readonly="readonly" 377 id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"/></label></p> 378 </div> 379 <?php 380 } -
watts/tags/1.2.1/readme.txt
r2719562 r2740791 6 6 Tested up to: 5.9.3 7 7 Requires PHP: 5.6 8 Stable tag: 1.2. 08 Stable tag: 1.2.1 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 57 57 == Changelog == 58 58 59 = 1.2.1 = 60 * Added settings page. 61 59 62 = 1.2.0 = 60 63 * Supports icon display showing validation results. -
watts/tags/1.2.1/watts.php
r2719562 r2740791 7 7 * Author URI: https://github.com/solaito/ 8 8 * Text Domain: watts 9 * Domain Path: /languages 10 * Version: 1.2.0 9 * Version: 1.2.1 11 10 * 12 11 * @package Watts 13 12 */ 14 13 14 define( "WATTS_PLUGIN", __FILE__ ); 15 define( "WATTS_PLUGIN_BASENAME", plugin_basename( WATTS_PLUGIN ) ); 16 define( "WATTS_PLUGIN_DIR_URL", plugin_dir_url( WATTS_PLUGIN ) ); 17 18 require_once 'includes/options-page.php'; 15 19 require_once 'includes/controller.php'; 16 20 … … 18 22 require_once "modules/confirm-email.php"; 19 23 20 add_action('wp_enqueue_scripts', 'watts_enqueue_scripts'); 21 function watts_enqueue_scripts() 22 { 23 $data = get_file_data(__FILE__, array('version' => 'Version')); 24 add_action( 'wp_enqueue_scripts', 'watts_enqueue_scripts' ); 25 function watts_enqueue_scripts() { 26 $data = get_file_data( WATTS_PLUGIN, array( 'version' => 'Version' ) ); 24 27 $version = $data['version']; 25 if (in_array(get_locale(), ['ja', 'ko_KR', 'zh_CN', 'zh_HK', 'zh_TW'], true)) { 26 wp_enqueue_script('watts-zenkaku-to-hankaku', plugin_dir_url(__FILE__) . 'includes/js/zenkaku-to-hankaku.js', array('contact-form-7'), $version); 28 $options = get_option( 'watts_option_name' ); 29 if ( $options[ Watts_Options_Page::IDS['FULL_TO_HALF_ENABLE'] ] === 'on' ) { 30 wp_enqueue_script( 'watts-full-to-half', WATTS_PLUGIN_DIR_URL . 'includes/js/full-to-half.js', array( 'contact-form-7' ), $version ); 27 31 } 28 if(!(strstr($_SERVER['HTTP_USER_AGENT'], 'Trident') || strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))) { 29 wp_enqueue_script('watts-auto-validation', plugin_dir_url(__FILE__) . 'includes/js/auto-validation.js', array('contact-form-7'), $version); 30 $watts= array( 31 'api' => array( 32 'root' => esc_url_raw( get_rest_url() ), 32 if ( $options[ Watts_Options_Page::IDS['REALTIME_VALIDATION_ENABLE'] ] === 'on' ) { 33 if ( ! ( strstr( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) || strstr( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) ) ) { 34 wp_enqueue_script( 'watts-realtime-validation', WATTS_PLUGIN_DIR_URL . 'includes/js/realtime-validation.js', array( 'contact-form-7' ), $version ); 35 $watts = array( 36 'api' => array( 37 'root' => esc_url_raw( get_rest_url() ), 33 38 'namespace' => 'watts/v1', 34 ), 35 'plugin' => array( 36 'dir' => esc_url_raw(plugin_dir_url(__FILE__)), 37 ) 38 ); 39 wp_localize_script( 'watts-auto-validation', 'watts', $watts ); 39 ), 40 'plugin' => array( 41 'dir' => esc_url_raw( WATTS_PLUGIN_DIR_URL ), 42 'validate_icon_enable' => $options[ Watts_Options_Page::IDS['VALIDATE_ICON_ENABLE'] ] === 'on', 43 'validate_icon_size' => isset( $options[ Watts_Options_Page::IDS['VALIDATE_ICON_SIZE'] ] ) ? $options[ Watts_Options_Page::IDS['VALIDATE_ICON_SIZE'] ] : 'medium', 44 ) 45 ); 46 wp_localize_script( 'watts-realtime-validation', 'watts', $watts ); 47 } 40 48 } 41 wp_enqueue_style( 'watts', plugin_dir_url(__FILE__) . 'includes/css/style.css', array('contact-form-7'), $version);49 wp_enqueue_style( 'watts', WATTS_PLUGIN_DIR_URL . 'includes/css/style.css', array( 'contact-form-7' ), $version ); 42 50 } 43 51 44 add_action( 'rest_api_init', function () {52 add_action( 'rest_api_init', function () { 45 53 $controller = new Watts_Rest_Controller; 46 54 $controller->register_routes(); 47 } );55 } ); -
watts/trunk/includes/controller.php
r2628083 r2740791 1 1 <?php 2 require_once ' auto-validation.php';3 class Watts_Rest_Controller 4 {2 require_once 'realtime-validation.php'; 3 4 class Watts_Rest_Controller { 5 5 const route_namespace = 'watts/v1'; 6 public function register_routes() 7 {6 7 public function register_routes() { 8 8 register_rest_route( 9 9 self::route_namespace, 10 10 '/(?P<id>\d+)/validation', 11 11 [ 12 'methods' => WP_REST_Server::CREATABLE,12 'methods' => WP_REST_Server::CREATABLE, 13 13 'permission_callback' => '__return_true', 14 'callback' => array($this, 'auto_validation'),14 'callback' => array( $this, 'realtime_validation' ), 15 15 ] 16 16 ); 17 17 } 18 18 19 public function auto_validation(WP_REST_Request $request)20 {21 $ wav = new Watts_Auto_Validation();22 $response = $wav->main($request); 23 return rest_ensure_response( $response);19 public function realtime_validation( WP_REST_Request $request ) { 20 $wrv = new Watts_Realtime_Validation(); 21 $response = $wrv->main( $request ); 22 23 return rest_ensure_response( $response ); 24 24 } 25 25 } -
watts/trunk/includes/css/style.css
r2719563 r2740791 1 1 .watts-validation-icon { 2 width:30px; 3 height:30px; 4 vertical-align:middle; 2 vertical-align: middle; 5 3 margin-left: 10px; 4 } 5 6 .watts-validation-icon-small { 7 width: 20px; 8 height: 20px; 9 } 10 11 .watts-validation-icon-medium { 12 width: 25px; 13 height: 25px; 14 } 15 16 .watts-validation-icon-large { 17 width: 30px; 18 height: 30px; 6 19 } 7 20 -
watts/trunk/modules/confirm-email.php
r2630535 r2740791 1 1 <?php 2 if (function_exists('wpcf7_add_form_tag')) { 3 wpcf7_add_form_tag('confirm_email', 'watts_confirm_email_form_tag_handler', true); 4 wpcf7_add_form_tag('confirm_email*', 'watts_confirm_email_form_tag_handler', true); 5 } 6 7 function watts_confirm_email_form_tag_handler($tag) 8 { 2 if ( function_exists( 'wpcf7_add_form_tag' ) ) { 3 wpcf7_add_form_tag( 'confirm_email', 'watts_confirm_email_form_tag_handler', true ); 4 wpcf7_add_form_tag( 'confirm_email*', 'watts_confirm_email_form_tag_handler', true ); 5 } 6 7 function watts_confirm_email_form_tag_handler( $tag ) { 9 8 if ( empty( $tag->name ) ) { 10 9 return ''; … … 23 22 $atts = array(); 24 23 25 $atts['class'] = $tag->get_class_option( $class );26 $atts['id'] = $tag->get_id_option();24 $atts['class'] = $tag->get_class_option( $class ); 25 $atts['id'] = $tag->get_id_option(); 27 26 $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true ); 28 27 … … 39 38 40 39 if ( $validation_error ) { 41 $atts['aria-invalid'] = 'true';40 $atts['aria-invalid'] = 'true'; 42 41 $atts['aria-describedby'] = wpcf7_get_validation_error_reference( 43 42 $tag->name … … 50 49 51 50 if ( $tag->has_option( 'placeholder' ) 52 or $tag->has_option( 'watermark' ) ) {51 or $tag->has_option( 'watermark' ) ) { 53 52 $atts['placeholder'] = $value; 54 $value = '';53 $value = ''; 55 54 } 56 55 … … 81 80 } 82 81 83 add_filter('wpcf7_validate_confirm_email', 'watts_confirm_email_validation_filter', 10, 2); 84 add_filter('wpcf7_validate_confirm_email*', 'watts_confirm_email_validation_filter', 10, 2); 85 86 function watts_confirm_email_validation_filter($result, $tag) 87 { 82 add_filter( 'wpcf7_validate_confirm_email', 'watts_confirm_email_validation_filter', 10, 2 ); 83 add_filter( 'wpcf7_validate_confirm_email*', 'watts_confirm_email_validation_filter', 10, 2 ); 84 85 function watts_confirm_email_validation_filter( $result, $tag ) { 88 86 $name = $tag->name; 89 87 90 $value = isset( $_POST[ $name] )91 ? trim( wp_unslash( strtr( (string) $_POST[ $name], "\n", " " ) ) )88 $value = isset( $_POST[ $name ] ) 89 ? trim( wp_unslash( strtr( (string) $_POST[ $name ], "\n", " " ) ) ) 92 90 : ''; 93 91 … … 97 95 $result->invalidate( $tag, wpcf7_get_message( 'invalid_email' ) ); 98 96 } 99 $target = $tag->get_option( 'target' )[0];100 $target_value = isset( $_POST[$target])101 ? trim( wp_unslash( strtr( (string) $_POST[ $target], "\n", " " ) ) )97 $target = $tag->get_option( 'target' )[0]; 98 $target_value = isset( $_POST[ $target ] ) 99 ? trim( wp_unslash( strtr( (string) $_POST[ $target ], "\n", " " ) ) ) 102 100 : ''; 103 if ( $value !== $target_value) {104 $result->invalidate( $tag, __( 'Email addresses you entered do not match.', 'watts'));101 if ( $value !== $target_value ) { 102 $result->invalidate( $tag, __( 'Email addresses you entered do not match.', 'watts' ) ); 105 103 } 106 104 … … 108 106 } 109 107 110 add_action('wpcf7_admin_init', 'watts_add_tag_generator_confirm_email', 16, 0); 111 112 function watts_add_tag_generator_confirm_email() 113 { 108 add_action( 'wpcf7_admin_init', 'watts_add_tag_generator_confirm_email', 16, 0 ); 109 110 function watts_add_tag_generator_confirm_email() { 114 111 $tag_generator = WPCF7_TagGenerator::get_instance(); 115 $tag_generator->add('confirm-email', __('confirm email', 'watts'), 116 'watts_tag_generator_confirm_email'); 117 } 118 119 function watts_tag_generator_confirm_email($contact_form, $args = '') 120 { 121 $args = wp_parse_args($args, array()); 112 $tag_generator->add( 'confirm-email', __( 'confirm email', 'watts' ), 113 'watts_tag_generator_confirm_email' ); 114 } 115 116 function watts_tag_generator_confirm_email( $contact_form, $args = '' ) { 117 $args = wp_parse_args( $args, array() ); 122 118 $type = 'confirm_email'; 123 119 … … 125 121 126 122 ?> 127 <div class="control-box"> 128 <fieldset> 129 <legend><?php echo esc_html($description); ?></legend> 130 131 <table class="form-table"> 132 <tbody> 133 <tr> 134 <th scope="row"><?php echo esc_html(__('Field type', 'watts')); ?></th> 135 <td> 123 <div class="control-box"> 136 124 <fieldset> 137 <legend class="screen-reader-text"><?php echo esc_html(__('Field type', 'watts')); ?></legend> 138 <label><input type="checkbox" name="required" /> <?php echo esc_html(__('Required field', 'watts')); ?></label> 125 <legend><?php echo esc_html( $description ); ?></legend> 126 127 <table class="form-table"> 128 <tbody> 129 <tr> 130 <th scope="row"><?php echo esc_html( __( 'Field type', 'watts' ) ); ?></th> 131 <td> 132 <fieldset> 133 <legend 134 class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'watts' ) ); ?></legend> 135 <label><input type="checkbox" 136 name="required"/> <?php echo esc_html( __( 'Required field', 'watts' ) ); ?> 137 </label> 138 </fieldset> 139 </td> 140 </tr> 141 142 <tr> 143 <th scope="row"><label 144 for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'watts' ) ); ?></label> 145 </th> 146 <td><input type="text" name="name" class="tg-name oneline" 147 id="<?php echo esc_attr( $args['content'] . '-name' ); ?>"/></td> 148 </tr> 149 150 <tr> 151 <th scope="row"><label 152 for="<?php echo esc_attr( $args['content'] . '-target' ); ?>"><?php echo esc_html( __( 'Target name*', 'watts' ) ); ?></label> 153 </th> 154 <td><input type="text" name="target" class="targetvalue oneline option" 155 id="<?php echo esc_attr( $args['content'] . '-target' ); ?>"/></td> 156 </tr> 157 158 <tr> 159 <th scope="row"><label 160 for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'watts' ) ); ?></label> 161 </th> 162 <td><input type="text" name="values" class="oneline" 163 id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"/><br/> 164 </tr> 165 166 <tr> 167 <th scope="row"><label 168 for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'watts' ) ); ?></label> 169 </th> 170 <td><input type="text" name="id" class="idvalue oneline option" 171 id="<?php echo esc_attr( $args['content'] . '-id' ); ?>"/></td> 172 </tr> 173 174 <tr> 175 <th scope="row"><label 176 for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'watts' ) ); ?></label> 177 </th> 178 <td><input type="text" name="class" class="classvalue oneline option" 179 id="<?php echo esc_attr( $args['content'] . '-class' ); ?>"/></td> 180 </tr> 181 </tbody> 182 </table> 139 183 </fieldset> 140 </td>141 </tr>142 143 <tr>144 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-name'); ?>"><?php echo esc_html(__('Name', 'watts')); ?></label></th>145 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr($args['content'] . '-name'); ?>" /></td>146 </tr>147 148 <tr>149 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-target'); ?>"><?php echo esc_html(__('Target name*', 'watts')); ?></label></th>150 <td><input type="text" name="target" class="targetvalue oneline option" id="<?php echo esc_attr($args['content'] . '-target'); ?>" /></td>151 </tr>152 153 <tr>154 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-values'); ?>"><?php echo esc_html(__('Default value', 'watts')); ?></label></th>155 <td><input type="text" name="values" class="oneline" id="<?php echo esc_attr($args['content'] . '-values'); ?>" /><br />156 </tr>157 158 <tr>159 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-id'); ?>"><?php echo esc_html(__('Id attribute', 'watts')); ?></label></th>160 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr($args['content'] . '-id'); ?>" /></td>161 </tr>162 163 <tr>164 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-class'); ?>"><?php echo esc_html(__('Class attribute', 'watts')); ?></label></th>165 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr($args['content'] . '-class'); ?>" /></td>166 </tr>167 </tbody>168 </table>169 </fieldset>170 </div>171 172 <div class="insert-box">173 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />174 175 <div class="submitbox">176 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr(__('Insert Tag', 'watts')); ?>" />177 184 </div> 178 185 179 <br class="clear" /> 180 181 <p class="description mail-tag"><label for="<?php echo esc_attr($args['content'] . '-mailtag'); ?>"><?php echo sprintf(esc_html(__("To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'watts')), '<strong><span class="mail-tag"></span></strong>'); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr($args['content'] . '-mailtag'); ?>" /></label></p> 182 </div> 183 <?php 184 } 186 <div class="insert-box"> 187 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()"/> 188 189 <div class="submitbox"> 190 <input type="button" class="button button-primary insert-tag" 191 value="<?php echo esc_attr( __( 'Insert Tag', 'watts' ) ); ?>"/> 192 </div> 193 194 <br class="clear"/> 195 196 <p class="description mail-tag"><label 197 for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'watts' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?> 198 <input type="text" class="mail-tag code hidden" readonly="readonly" 199 id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"/></label></p> 200 </div> 201 <?php 202 } -
watts/trunk/modules/dob.php
r2648825 r2740791 1 1 <?php 2 2 3 if (function_exists('wpcf7_add_form_tag')) { 4 wpcf7_add_form_tag('dob', 'watts_dob_form_tag_handler', true); 5 wpcf7_add_form_tag('dob*', 'watts_dob_form_tag_handler', true); 6 } 7 8 function watts_dob_form_tag_handler($tag) 9 { 10 if (empty($tag->name)) { 3 if ( function_exists( 'wpcf7_add_form_tag' ) ) { 4 wpcf7_add_form_tag( 'dob', 'watts_dob_form_tag_handler', true ); 5 wpcf7_add_form_tag( 'dob*', 'watts_dob_form_tag_handler', true ); 6 } 7 8 function watts_dob_form_tag_handler( $tag ) { 9 if ( empty( $tag->name ) ) { 11 10 return ''; 12 11 } 13 12 14 $validation_error = wpcf7_get_validation_error( $tag->name);15 16 $class = wpcf7_form_controls_class( $tag->type);13 $validation_error = wpcf7_get_validation_error( $tag->name ); 14 15 $class = wpcf7_form_controls_class( $tag->type ); 17 16 18 17 $class .= ' wpcf7-validates-as-dob'; 19 18 20 if ( $validation_error) {19 if ( $validation_error ) { 21 20 $class .= ' wpcf7-not-valid'; 22 21 } … … 24 23 $atts = array(); 25 24 26 $atts['class'] = $tag->get_class_option($class);27 $atts['id'] = $tag->get_id_option();28 $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true);29 $format = isset($tag->get_option('format')[0]) ? $tag->get_option('format')[0] : 'YMD';30 31 if ( $tag->is_required()) {25 $atts['class'] = $tag->get_class_option( $class ); 26 $atts['id'] = $tag->get_id_option(); 27 $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true ); 28 $format = isset( $tag->get_option( 'format' )[0] ) ? $tag->get_option( 'format' )[0] : 'YMD'; 29 30 if ( $tag->is_required() ) { 32 31 $atts['aria-required'] = 'true'; 33 32 } 34 33 35 if ( $validation_error) {36 $atts['aria-invalid'] = 'true';34 if ( $validation_error ) { 35 $atts['aria-invalid'] = 'true'; 37 36 $atts['aria-describedby'] = wpcf7_get_validation_error_reference( 38 37 $tag->name … … 42 41 } 43 42 44 $value = (string) reset($tag->values); 45 46 $value = $tag->get_default_option($value); 47 if ($value) { 48 $datetime_obj = date_create_immutable($value, wp_timezone()); 49 50 if ($datetime_obj) { 43 $value = (string) reset( $tag->values ); 44 $default_value = [ 45 'year' => null, 46 'month' => null, 47 'day' => null, 48 ]; 49 50 $value = $tag->get_default_option( $value ); 51 if ( $value ) { 52 $datetime_obj = date_create_immutable( $value, wp_timezone() ); 53 54 if ( $datetime_obj ) { 51 55 // NOTE: プルダウンのvalueが0サプレスなので、初期値も合わせる 52 56 $default_value = [ 53 'year' => $datetime_obj->format('Y'),54 'month' => $datetime_obj->format( 'n'),55 'day' => $datetime_obj->format('j'),57 'year' => $datetime_obj->format( 'Y' ), 58 'month' => $datetime_obj->format( 'n' ), 59 'day' => $datetime_obj->format( 'j' ), 56 60 ]; 57 61 } … … 60 64 // NOTE: 寿命をもとに生年月日の範囲を算出 61 65 $max_lifespan = 120; 62 $start_year = intval(date_i18n('Y'));63 $until_year = $start_year - $max_lifespan;66 $start_year = intval( date_i18n( 'Y' ) ); 67 $until_year = $start_year - $max_lifespan; 64 68 65 69 $html_parts = [ 66 'year' => watts_dob_form_part($tag, $atts, 'year', $default_value['year'], range($start_year, $until_year), esc_html(__('Year', 'watts'))),67 'month' => watts_dob_form_part( $tag, $atts, 'month', $default_value['month'], range(1, 12), esc_html(__('Month', 'watts'))),68 'day' => watts_dob_form_part($tag, $atts, 'day', $default_value['day'], range(1, 31), esc_html(__('Day', 'watts')))70 'year' => watts_dob_form_part( $tag, $atts, 'year', $default_value['year'], range( $start_year, $until_year ), esc_html( __( 'Year', 'watts' ) ) ), 71 'month' => watts_dob_form_part( $tag, $atts, 'month', $default_value['month'], range( 1, 12 ), esc_html( __( 'Month', 'watts' ) ) ), 72 'day' => watts_dob_form_part( $tag, $atts, 'day', $default_value['day'], range( 1, 31 ), esc_html( __( 'Day', 'watts' ) ) ) 69 73 ]; 70 74 71 75 $html = ''; 72 if ( $format === 'DMY') {76 if ( $format === 'DMY' ) { 73 77 $html = $html_parts['day'] . $html_parts['month'] . $html_parts['year']; 74 } elseif ( $format === 'MDY') {78 } elseif ( $format === 'MDY' ) { 75 79 $html = $html_parts['month'] . $html_parts['day'] . $html_parts['year']; 76 80 } else { // default … … 80 84 $html = sprintf( 81 85 '<span class="wpcf7-form-control-wrap %1$s">%2$s%3$s</span>', 82 sanitize_html_class( $tag->name), $html, $validation_error86 sanitize_html_class( $tag->name ), $html, $validation_error 83 87 ); 84 88 … … 86 90 } 87 91 88 function watts_dob_form_part($tag, $atts, $name_key, $default_value, $values, $blank_item) 89 { 90 $atts['name'] = sprintf('%1$s[%2$s]', $tag->name, $name_key); 91 $atts['id'] .= '-' . $name_key; 92 function watts_dob_form_part( $tag, $atts, $name_key, $default_value, $values, $blank_item ) { 93 $atts['name'] = sprintf( '%1$s[%2$s]', $tag->name, $name_key ); 94 $atts['id'] .= '-' . $name_key; 92 95 93 96 $labels = $values; 94 97 95 $include_blank = $tag->has_option( 'include_blank');96 97 if ( $include_blank) {98 array_unshift( $labels, $blank_item);99 array_unshift( $values, '');100 } 101 102 $html = '';103 $hangover = wpcf7_get_hangover( $tag->name);104 105 foreach ( $values as $key => $value) {106 if ( $hangover) {107 $selected = $value === (int) $hangover[ $name_key];98 $include_blank = $tag->has_option( 'include_blank' ); 99 100 if ( $include_blank ) { 101 array_unshift( $labels, $blank_item ); 102 array_unshift( $values, '' ); 103 } 104 105 $html = ''; 106 $hangover = wpcf7_get_hangover( $tag->name ); 107 108 foreach ( $values as $key => $value ) { 109 if ( $hangover ) { 110 $selected = $value === (int) $hangover[ $name_key ]; 108 111 } else { 109 112 $selected = $value === (int) $default_value; … … 111 114 112 115 $item_atts = array( 113 'value' => $value,116 'value' => $value, 114 117 'selected' => $selected ? 'selected' : '', 115 118 ); 116 119 117 $item_atts = wpcf7_format_atts( $item_atts);118 119 $label = isset( $labels[$key]) ? $labels[$key] : $value;120 $item_atts = wpcf7_format_atts( $item_atts ); 121 122 $label = isset( $labels[ $key ] ) ? $labels[ $key ] : $value; 120 123 121 124 $html .= sprintf( 122 125 '<option %1$s>%2$s</option>', 123 126 $item_atts, 124 esc_html( $label)127 esc_html( $label ) 125 128 ); 126 129 } 127 $atts = wpcf7_format_atts( $atts);130 $atts = wpcf7_format_atts( $atts ); 128 131 129 132 $html = sprintf( … … 135 138 } 136 139 137 add_filter('wpcf7_posted_data_dob', 'watts_posted_data_dob', 10, 3); 138 add_filter('wpcf7_posted_data_dob*', 'watts_posted_data_dob', 10, 3); 139 140 function watts_posted_data_dob($value, $value_orig, $tag) 141 { 142 if (!isset($value_orig) || 143 !isset($value_orig['year']) || 144 !isset($value_orig['month']) || 145 !isset($value_orig['day']) || 146 in_array('', $value_orig, true)) { 140 add_filter( 'wpcf7_posted_data_dob', 'watts_posted_data_dob', 10, 3 ); 141 add_filter( 'wpcf7_posted_data_dob*', 'watts_posted_data_dob', 10, 3 ); 142 143 function watts_posted_data_dob( $value, $value_orig, $tag ) { 144 if ( ! isset( $value_orig ) || 145 ! isset( $value_orig['year'] ) || 146 ! isset( $value_orig['month'] ) || 147 ! isset( $value_orig['day'] ) || 148 in_array( '', $value_orig, true ) ) { 147 149 return ''; 148 150 } 149 151 150 $format = isset($tag->get_option('format')[0]) ? $tag->get_option('format')[0] : 'YMD';151 $separator_option = isset( $tag->get_option('separator')[0]) ? $tag->get_option('separator')[0] : 'slash';152 $separator_map = [153 'slash' => '/',154 'dash' => '-',152 $format = isset( $tag->get_option( 'format' )[0] ) ? $tag->get_option( 'format' )[0] : 'YMD'; 153 $separator_option = isset( $tag->get_option( 'separator' )[0] ) ? $tag->get_option( 'separator' )[0] : 'slash'; 154 $separator_map = [ 155 'slash' => '/', 156 'dash' => '-', 155 157 'period' => '.', 156 'comma' => ',',157 'blank' => ' '158 ]; 159 $separator = array_key_exists($separator_option, $separator_map) ? $separator_map[$separator_option] : '/';160 $leading_zero = $tag->has_option('leading_zero');161 162 $year = $value_orig['year'];163 $month = $value_orig['month'];164 $day = $value_orig['day'];165 if ($leading_zero) {166 $month = str_pad($month, 2, '0', STR_PAD_LEFT);167 $day = str_pad($day, 2, '0', STR_PAD_LEFT);158 'comma' => ',', 159 'blank' => ' ' 160 ]; 161 $separator = array_key_exists( $separator_option, $separator_map ) ? $separator_map[ $separator_option ] : '/'; 162 $leading_zero = $tag->has_option( 'leading_zero' ); 163 164 $year = $value_orig['year']; 165 $month = $value_orig['month']; 166 $day = $value_orig['day']; 167 if ( $leading_zero ) { 168 $month = str_pad( $month, 2, '0', STR_PAD_LEFT ); 169 $day = str_pad( $day, 2, '0', STR_PAD_LEFT ); 168 170 } 169 171 170 172 $result = ''; 171 if ( $format === 'DMY') {172 $result = implode( [$day, $month, $year], $separator);173 } elseif ( $format === 'MDY') {174 $result = implode( [$month, $day, $year], $separator);173 if ( $format === 'DMY' ) { 174 $result = implode( [ $day, $month, $year ], $separator ); 175 } elseif ( $format === 'MDY' ) { 176 $result = implode( [ $month, $day, $year ], $separator ); 175 177 } else { // default 176 $result = implode( [$year, $month, $day], $separator);178 $result = implode( [ $year, $month, $day ], $separator ); 177 179 } 178 180 … … 180 182 } 181 183 182 add_filter('wpcf7_validate_dob', 'watts_dob_validation_filter', 10, 2); 183 add_filter('wpcf7_validate_dob*', 'watts_dob_validation_filter', 10, 2); 184 185 function watts_dob_validation_filter($result, $tag) 186 { 184 add_filter( 'wpcf7_validate_dob', 'watts_dob_validation_filter', 10, 2 ); 185 add_filter( 'wpcf7_validate_dob*', 'watts_dob_validation_filter', 10, 2 ); 186 187 function watts_dob_validation_filter( $result, $tag ) { 187 188 $name = $tag->name; 188 189 189 190 $values = [ 190 'year' => isset($_POST[$name]['year']) ? trim(sanitize_text_field($_POST[$name]['year'])) : '',191 'month' => isset( $_POST[$name]['month']) ? trim(sanitize_text_field($_POST[$name]['month'])) : '',192 'day' => isset($_POST[$name]['day']) ? trim(sanitize_text_field($_POST[$name]['day'])) : '',191 'year' => isset( $_POST[ $name ]['year'] ) ? trim( sanitize_text_field( $_POST[ $name ]['year'] ) ) : '', 192 'month' => isset( $_POST[ $name ]['month'] ) ? trim( sanitize_text_field( $_POST[ $name ]['month'] ) ) : '', 193 'day' => isset( $_POST[ $name ]['day'] ) ? trim( sanitize_text_field( $_POST[ $name ]['day'] ) ) : '', 193 194 ]; 194 195 195 196 $blank_flags = [ 196 'year' => $values['year'] === '',197 'year' => $values['year'] === '', 197 198 'month' => $values['month'] === '', 198 'day' => $values['day'] === '',199 ]; 200 201 if ( !in_array(false, $blank_flags, true) !== false) {199 'day' => $values['day'] === '', 200 ]; 201 202 if ( ! in_array( false, $blank_flags, true ) !== false ) { 202 203 // すべて入力されていない 203 if ( $tag->is_required()) {204 if ( $tag->is_required() ) { 204 205 // 必須項目 205 206 $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); 206 207 } 207 208 // 必須項目ではなく、全て入力されていない場合は許容 208 } else if ( in_array(true, $blank_flags, true) !== false) {209 } else if ( in_array( true, $blank_flags, true ) !== false ) { 209 210 // 中途半端な入力 210 211 $result->invalidate( $tag, wpcf7_get_message( 'invalid_date' ) ); 211 } else if ( in_array(false, array_map('is_numeric', array_values($values)), true)) {212 } else if ( in_array( false, array_map( 'is_numeric', array_values( $values ) ), true ) ) { 212 213 // 数値かどうか 213 214 $result->invalidate( $tag, wpcf7_get_message( 'invalid_date' ) ); 214 } else if ( !checkdate($values['month'], $values['day'], $values['year'])) {215 } else if ( ! checkdate( $values['month'], $values['day'], $values['year'] ) ) { 215 216 // 数値が入力されていた場合のチェック 216 $result->invalidate( $tag, __( 'The date specified is not a valid date value.', 'watts'));217 $result->invalidate( $tag, __( 'The date specified is not a valid date value.', 'watts' ) ); 217 218 } 218 219 … … 220 221 } 221 222 222 add_action('wpcf7_admin_init', 'watts_add_tag_generator_dob', 20, 0); 223 224 function watts_add_tag_generator_dob() 225 { 223 add_action( 'wpcf7_admin_init', 'watts_add_tag_generator_dob', 20, 0 ); 224 225 function watts_add_tag_generator_dob() { 226 226 $tag_generator = WPCF7_TagGenerator::get_instance(); 227 $tag_generator->add('dob', __('DOB', 'watts'), 228 'watts_tag_generator_dob'); 229 } 230 231 function watts_tag_generator_dob($contact_form, $args = '') 232 { 233 $args = wp_parse_args($args, array()); 227 $tag_generator->add( 'dob', __( 'DOB', 'watts' ), 228 'watts_tag_generator_dob' ); 229 } 230 231 function watts_tag_generator_dob( $contact_form, $args = '' ) { 232 $args = wp_parse_args( $args, array() ); 234 233 $type = 'dob'; 235 234 … … 237 236 238 237 ?> 239 <div class="control-box"> 240 <fieldset> 241 <legend><?php echo esc_html($description); ?></legend> 242 243 <table class="form-table"> 244 <tbody> 245 <tr> 246 <th scope="row"><?php echo esc_html(__('Field type', 'watts')); ?></th> 247 <td> 238 <div class="control-box"> 248 239 <fieldset> 249 <legend class="screen-reader-text"><?php echo esc_html(__('Field type', 'watts')); ?></legend> 250 <label><input type="checkbox" name="required" /> <?php echo esc_html(__('Required field', 'watts')); ?></label> 240 <legend><?php echo esc_html( $description ); ?></legend> 241 242 <table class="form-table"> 243 <tbody> 244 <tr> 245 <th scope="row"><?php echo esc_html( __( 'Field type', 'watts' ) ); ?></th> 246 <td> 247 <fieldset> 248 <legend 249 class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'watts' ) ); ?></legend> 250 <label><input type="checkbox" 251 name="required"/> <?php echo esc_html( __( 'Required field', 'watts' ) ); ?> 252 </label> 253 </fieldset> 254 </td> 255 </tr> 256 257 <tr> 258 <th scope="row"><label 259 for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'watts' ) ); ?></label> 260 </th> 261 <td><input type="text" name="name" class="tg-name oneline" 262 id="<?php echo esc_attr( $args['content'] . '-name' ); ?>"/></td> 263 </tr> 264 265 <tr> 266 <th scope="row"><label 267 for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'watts' ) ); ?></label> 268 </th> 269 <td><input type="text" name="values" class="oneline" 270 id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"/><br/> 271 </tr> 272 273 <tr> 274 <th scope="row"><?php echo esc_html( __( 'Options', 'watts' ) ); ?></th> 275 <td> 276 <fieldset> 277 <legend 278 class="screen-reader-text"><?php echo esc_html( __( 'Options', 'watts' ) ); ?></legend> 279 <label><input type="checkbox" name="include_blank" 280 class="option"/> <?php echo esc_html( __( 'Insert a blank item as the first option', 'watts' ) ); ?> 281 </label> 282 </fieldset> 283 </td> 284 </tr> 285 286 <tr> 287 <th scope="row" rowspan="3"><?php echo esc_html( __( 'Date Format', 'watts' ) ); ?></th> 288 <td> 289 <fieldset> 290 <legend><?php echo esc_html( __( 'Date Style', 'watts' ) ); ?></legend> 291 <input type="radio" name="format" class="formatvalue option" 292 id="<?php echo esc_attr( $args['content'] . '-format-ymd' ); ?>" value="YMD" checked> 293 <label for="<?php echo esc_attr( $args['content'] . '-format-ymd' ); ?>">YMD</label> 294 <input type="radio" name="format" class="formatvalue option" 295 id="<?php echo esc_attr( $args['content'] . '-format-mdy' ); ?>" value="MDY"> 296 <label for="<?php echo esc_attr( $args['content'] . '-format-mdy' ); ?>">MDY</label> 297 <input type="radio" name="format" class="formatvalue option" 298 id="<?php echo esc_attr( $args['content'] . '-format-dmy' ); ?>" value="DMY"> 299 <label for="<?php echo esc_attr( $args['content'] . '-format-dmy' ); ?>">DMY</label> 300 </fieldset> 301 </td> 302 </tr> 303 <tr> 304 <td> 305 <fieldset> 306 <legend><?php echo esc_html( __( 'Date Separator', 'watts' ) ); ?></legend> 307 <input type="radio" name="separator" class="separatorvalue option" 308 id="<?php echo esc_attr( $args['content'] . '-separator-slash' ); ?>" value="slash" 309 checked> 310 <label 311 for="<?php echo esc_attr( $args['content'] . '-separator-slash' ); ?>"><?php echo esc_html( __( 'slash', 'watts' ) ); ?></label> 312 <input type="radio" name="separator" class="separatorvalue option" 313 id="<?php echo esc_attr( $args['content'] . '-separator-dash' ); ?>" value="dash"> 314 <label 315 for="<?php echo esc_attr( $args['content'] . '-separator-dash' ); ?>"><?php echo esc_html( __( 'dash', 'watts' ) ); ?></label> 316 <input type="radio" name="separator" class="separatorvalue option" 317 id="<?php echo esc_attr( $args['content'] . '-separator-period' ); ?>" 318 value="period"> 319 <label 320 for="<?php echo esc_attr( $args['content'] . '-separator-period' ); ?>"><?php echo esc_html( __( 'period', 'watts' ) ); ?></label> 321 <input type="radio" name="separator" class="separatorvalue option" 322 id="<?php echo esc_attr( $args['content'] . '-separator-comma' ); ?>" value="comma"> 323 <label 324 for="<?php echo esc_attr( $args['content'] . '-separator-comma' ); ?>"><?php echo esc_html( __( 'comma', 'watts' ) ); ?></label> 325 <input type="radio" name="separator" class="separatorvalue option" 326 id="<?php echo esc_attr( $args['content'] . '-separator-blank' ); ?>" value="blank"> 327 <label 328 for="<?php echo esc_attr( $args['content'] . '-separator-blank' ); ?>"><?php echo esc_html( __( 'blank', 'watts' ) ); ?></label> 329 </fieldset> 330 </td> 331 </tr> 332 333 <tr> 334 <td> 335 <fieldset> 336 <legend><?php echo esc_html( __( 'Display Leading Zero', 'watts' ) ); ?></legend> 337 <label><input type="checkbox" name="leading_zero" 338 class="option"/> <?php echo esc_html( __( 'Indicates whether to display (or suppress) leading zeros.', 'watts' ) ); ?> 339 </label> 340 </fieldset> 341 </td> 342 </tr> 343 344 <tr> 345 <th scope="row"><label 346 for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'watts' ) ); ?></label> 347 </th> 348 <td><input type="text" name="id" class="idvalue oneline option" 349 id="<?php echo esc_attr( $args['content'] . '-id' ); ?>"/></td> 350 </tr> 351 352 <tr> 353 <th scope="row"><label 354 for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'watts' ) ); ?></label> 355 </th> 356 <td><input type="text" name="class" class="classvalue oneline option" 357 id="<?php echo esc_attr( $args['content'] . '-class' ); ?>"/></td> 358 </tr> 359 </tbody> 360 </table> 251 361 </fieldset> 252 </td>253 </tr>254 255 <tr>256 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-name'); ?>"><?php echo esc_html(__('Name', 'watts')); ?></label></th>257 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr($args['content'] . '-name'); ?>" /></td>258 </tr>259 260 <tr>261 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-values'); ?>"><?php echo esc_html(__('Default value', 'watts')); ?></label></th>262 <td><input type="text" name="values" class="oneline" id="<?php echo esc_attr($args['content'] . '-values'); ?>" /><br />263 </tr>264 265 <tr>266 <th scope="row"><?php echo esc_html(__('Options', 'watts')); ?></th>267 <td>268 <fieldset>269 <legend class="screen-reader-text"><?php echo esc_html(__('Options', 'watts')); ?></legend>270 <label><input type="checkbox" name="include_blank" class="option" /> <?php echo esc_html(__('Insert a blank item as the first option', 'watts')); ?></label>271 </fieldset>272 </td>273 </tr>274 275 <tr>276 <th scope="row" rowspan="3"><?php echo esc_html(__('Date Format', 'watts')); ?></th>277 <td>278 <fieldset>279 <legend><?php echo esc_html(__('Date Style', 'watts')); ?></legend>280 <input type="radio" name="format" class="formatvalue option" id="<?php echo esc_attr($args['content'] . '-format-ymd'); ?>" value="YMD" checked >281 <label for="<?php echo esc_attr($args['content'] . '-format-ymd'); ?>">YMD</label>282 <input type="radio" name="format" class="formatvalue option" id="<?php echo esc_attr($args['content'] . '-format-mdy'); ?>" value="MDY" >283 <label for="<?php echo esc_attr($args['content'] . '-format-mdy'); ?>">MDY</label>284 <input type="radio" name="format" class="formatvalue option" id="<?php echo esc_attr($args['content'] . '-format-dmy'); ?>" value="DMY" >285 <label for="<?php echo esc_attr($args['content'] . '-format-dmy'); ?>">DMY</label>286 </fieldset>287 </td>288 </tr>289 <tr>290 <td>291 <fieldset>292 <legend><?php echo esc_html(__('Date Separator', 'watts')); ?></legend>293 <input type="radio" name="separator" class="separatorvalue option" id="<?php echo esc_attr($args['content'] . '-separator-slash'); ?>" value="slash" checked >294 <label for="<?php echo esc_attr($args['content'] . '-separator-slash'); ?>"><?php echo esc_html(__('slash', 'watts')); ?></label>295 <input type="radio" name="separator" class="separatorvalue option" id="<?php echo esc_attr($args['content'] . '-separator-dash'); ?>" value="dash" >296 <label for="<?php echo esc_attr($args['content'] . '-separator-dash'); ?>"><?php echo esc_html(__('dash', 'watts')); ?></label>297 <input type="radio" name="separator" class="separatorvalue option" id="<?php echo esc_attr($args['content'] . '-separator-period'); ?>" value="period" >298 <label for="<?php echo esc_attr($args['content'] . '-separator-period'); ?>"><?php echo esc_html(__('period', 'watts')); ?></label>299 <input type="radio" name="separator" class="separatorvalue option" id="<?php echo esc_attr($args['content'] . '-separator-comma'); ?>" value="comma" >300 <label for="<?php echo esc_attr($args['content'] . '-separator-comma'); ?>"><?php echo esc_html(__('comma', 'watts')); ?></label>301 <input type="radio" name="separator" class="separatorvalue option" id="<?php echo esc_attr($args['content'] . '-separator-blank'); ?>" value="blank" >302 <label for="<?php echo esc_attr($args['content'] . '-separator-blank'); ?>"><?php echo esc_html(__('blank', 'watts')); ?></label>303 </fieldset>304 </td>305 </tr>306 307 <tr>308 <td>309 <fieldset>310 <legend><?php echo esc_html(__('Display Leading Zero', 'watts')); ?></legend>311 <label><input type="checkbox" name="leading_zero" class="option" /> <?php echo esc_html(__('Indicates whether to display (or suppress) leading zeros.', 'watts')); ?></label>312 </fieldset>313 </td>314 </tr>315 316 <tr>317 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-id'); ?>"><?php echo esc_html(__('Id attribute', 'watts')); ?></label></th>318 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr($args['content'] . '-id'); ?>" /></td>319 </tr>320 321 <tr>322 <th scope="row"><label for="<?php echo esc_attr($args['content'] . '-class'); ?>"><?php echo esc_html(__('Class attribute', 'watts')); ?></label></th>323 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr($args['content'] . '-class'); ?>" /></td>324 </tr>325 </tbody>326 </table>327 </fieldset>328 </div>329 330 <div class="insert-box">331 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />332 333 <div class="submitbox">334 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr(__('Insert Tag', 'watts')); ?>" />335 362 </div> 336 363 337 <br class="clear" /> 338 339 <p class="description mail-tag"><label for="<?php echo esc_attr($args['content'] . '-mailtag'); ?>"><?php echo sprintf(esc_html(__("To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'watts')), '<strong><span class="mail-tag"></span></strong>'); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr($args['content'] . '-mailtag'); ?>" /></label></p> 340 </div> 341 <?php 342 } 364 <div class="insert-box"> 365 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()"/> 366 367 <div class="submitbox"> 368 <input type="button" class="button button-primary insert-tag" 369 value="<?php echo esc_attr( __( 'Insert Tag', 'watts' ) ); ?>"/> 370 </div> 371 372 <br class="clear"/> 373 374 <p class="description mail-tag"><label 375 for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'watts' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?> 376 <input type="text" class="mail-tag code hidden" readonly="readonly" 377 id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"/></label></p> 378 </div> 379 <?php 380 } -
watts/trunk/readme.txt
r2719562 r2740791 6 6 Tested up to: 5.9.3 7 7 Requires PHP: 5.6 8 Stable tag: 1.2. 08 Stable tag: 1.2.1 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 57 57 == Changelog == 58 58 59 = 1.2.1 = 60 * Added settings page. 61 59 62 = 1.2.0 = 60 63 * Supports icon display showing validation results. -
watts/trunk/watts.php
r2719562 r2740791 7 7 * Author URI: https://github.com/solaito/ 8 8 * Text Domain: watts 9 * Domain Path: /languages 10 * Version: 1.2.0 9 * Version: 1.2.1 11 10 * 12 11 * @package Watts 13 12 */ 14 13 14 define( "WATTS_PLUGIN", __FILE__ ); 15 define( "WATTS_PLUGIN_BASENAME", plugin_basename( WATTS_PLUGIN ) ); 16 define( "WATTS_PLUGIN_DIR_URL", plugin_dir_url( WATTS_PLUGIN ) ); 17 18 require_once 'includes/options-page.php'; 15 19 require_once 'includes/controller.php'; 16 20 … … 18 22 require_once "modules/confirm-email.php"; 19 23 20 add_action('wp_enqueue_scripts', 'watts_enqueue_scripts'); 21 function watts_enqueue_scripts() 22 { 23 $data = get_file_data(__FILE__, array('version' => 'Version')); 24 add_action( 'wp_enqueue_scripts', 'watts_enqueue_scripts' ); 25 function watts_enqueue_scripts() { 26 $data = get_file_data( WATTS_PLUGIN, array( 'version' => 'Version' ) ); 24 27 $version = $data['version']; 25 if (in_array(get_locale(), ['ja', 'ko_KR', 'zh_CN', 'zh_HK', 'zh_TW'], true)) { 26 wp_enqueue_script('watts-zenkaku-to-hankaku', plugin_dir_url(__FILE__) . 'includes/js/zenkaku-to-hankaku.js', array('contact-form-7'), $version); 28 $options = get_option( 'watts_option_name' ); 29 if ( $options[ Watts_Options_Page::IDS['FULL_TO_HALF_ENABLE'] ] === 'on' ) { 30 wp_enqueue_script( 'watts-full-to-half', WATTS_PLUGIN_DIR_URL . 'includes/js/full-to-half.js', array( 'contact-form-7' ), $version ); 27 31 } 28 if(!(strstr($_SERVER['HTTP_USER_AGENT'], 'Trident') || strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))) { 29 wp_enqueue_script('watts-auto-validation', plugin_dir_url(__FILE__) . 'includes/js/auto-validation.js', array('contact-form-7'), $version); 30 $watts= array( 31 'api' => array( 32 'root' => esc_url_raw( get_rest_url() ), 32 if ( $options[ Watts_Options_Page::IDS['REALTIME_VALIDATION_ENABLE'] ] === 'on' ) { 33 if ( ! ( strstr( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) || strstr( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) ) ) { 34 wp_enqueue_script( 'watts-realtime-validation', WATTS_PLUGIN_DIR_URL . 'includes/js/realtime-validation.js', array( 'contact-form-7' ), $version ); 35 $watts = array( 36 'api' => array( 37 'root' => esc_url_raw( get_rest_url() ), 33 38 'namespace' => 'watts/v1', 34 ), 35 'plugin' => array( 36 'dir' => esc_url_raw(plugin_dir_url(__FILE__)), 37 ) 38 ); 39 wp_localize_script( 'watts-auto-validation', 'watts', $watts ); 39 ), 40 'plugin' => array( 41 'dir' => esc_url_raw( WATTS_PLUGIN_DIR_URL ), 42 'validate_icon_enable' => $options[ Watts_Options_Page::IDS['VALIDATE_ICON_ENABLE'] ] === 'on', 43 'validate_icon_size' => isset( $options[ Watts_Options_Page::IDS['VALIDATE_ICON_SIZE'] ] ) ? $options[ Watts_Options_Page::IDS['VALIDATE_ICON_SIZE'] ] : 'medium', 44 ) 45 ); 46 wp_localize_script( 'watts-realtime-validation', 'watts', $watts ); 47 } 40 48 } 41 wp_enqueue_style( 'watts', plugin_dir_url(__FILE__) . 'includes/css/style.css', array('contact-form-7'), $version);49 wp_enqueue_style( 'watts', WATTS_PLUGIN_DIR_URL . 'includes/css/style.css', array( 'contact-form-7' ), $version ); 42 50 } 43 51 44 add_action( 'rest_api_init', function () {52 add_action( 'rest_api_init', function () { 45 53 $controller = new Watts_Rest_Controller; 46 54 $controller->register_routes(); 47 } );55 } );
Note: See TracChangeset
for help on using the changeset viewer.