Changeset 1373385
- Timestamp:
- 03/17/2016 08:40:14 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
contact-form-7-textarea-wordcount/trunk/cf7-textarea-wordcount.php
r1373384 r1373385 13 13 */ 14 14 15 /* Shortcode handler */ 16 15 // Shortcode handler, overwriting the default cf7 version 17 16 function wpcf7wc_textarea_shortcode_handler( $tag ) { 18 19 17 $tag = new WPCF7_Shortcode( $tag ); 20 18 … … 72 70 $atts['name'] = $tag->name; 73 71 74 // inject our counter stuff 75 // add word counter? 72 // inject our word counter 76 73 if( $atts['data-maxwc'] ) { 77 74 $validation_error .= '<span class="wpcf7wc-msg"><br /><br /><input type="text" name="wcount_'. $atts['name'] .'" id="wcount_'. $atts['name'] .'" size="3" maxlength="'. ( $atts['data-maxwc'] % 10 ) .'" style="text-align:center; width: auto" value="" readonly="readonly" /> words. Please limit to '. $atts['data-maxwc'] .' words or less.</span>'; … … 86 83 87 84 return $html; 88 /*89 if ( ! is_array( $tag ) )90 return '';91 92 $type = $tag['type'];93 $name = $tag['name'];94 $options = (array) $tag['options'];95 $values = (array) $tag['values'];96 $content = $tag['content'];97 98 if ( empty( $name ) )99 return '';100 101 $atts = '';102 $id_att = '';103 $class_att = 'maxwordcount';104 $cols_att = '';105 $rows_att = '';106 $tabindex_att = '';107 $title_att = '';108 // and109 $size_att = '';110 $maxlength_att = '';111 112 if ( 'textarea*' == $type )113 $class_att .= ' wpcf7-validates-as-required';114 115 foreach ( $options as $option ) {116 if ( preg_match( '%^id:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {117 $id_att = $matches[1];118 119 } elseif ( preg_match( '%^class:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {120 $class_att .= ' ' . $matches[1];121 122 } elseif ( preg_match( '%^([0-9]*)[/]([0-9]*)$%', $option, $matches ) ) {123 $size_att = (int) $matches[1];124 $maxlength_att = (int) $matches[2];125 126 } elseif ( preg_match( '%^([0-9]*)[x/]([0-9]*)$%', $option, $matches ) ) {127 $cols_att = (int) $matches[1];128 $rows_att = (int) $matches[2];129 130 } elseif ( preg_match( '%^tabindex:(\d+)$%', $option, $matches ) ) {131 $tabindex_att = (int) $matches[1];132 133 }134 }135 136 $value = (string) reset( $values );137 138 if ( ! empty( $content ) )139 $value = $content;140 141 if ( wpcf7_script_is() && $value && preg_grep( '%^watermark$%', $options ) ) {142 $class_att .= ' wpcf7-use-title-as-watermark';143 $title_att .= sprintf( ' %s', $value );144 $value = '';145 }146 147 if ( wpcf7_is_posted() )148 $value = stripslashes_deep( $_POST[$name] );149 150 if ( $id_att )151 $atts .= ' id="' . trim( $id_att ) . '"';152 153 if ( $class_att )154 $atts .= ' class="' . trim( $class_att ) . '"';155 156 if ( $cols_att )157 $atts .= ' cols="' . $cols_att . '"';158 else159 $atts .= ' cols="40"'; // default size160 161 if ( $rows_att )162 $atts .= ' rows="' . $rows_att . '"';163 else164 $atts .= ' rows="10"'; // default size165 166 if ( '' !== $tabindex_att )167 $atts .= sprintf( ' tabindex="%d"', $tabindex_att );168 169 if ( $title_att )170 $atts .= sprintf( ' title="%s"', trim( esc_attr( $title_att ) ) );171 172 $html = '<textarea name="' . $name . '"' . $atts . '>' . esc_html( $value ) . '</textarea>';173 174 $validation_error = wpcf7_get_validation_error( $name );175 176 $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . $html . $validation_error . '</span>';177 178 return $html;179 */180 85 } 181 86 182 183 /* Validation filter */ 184 87 // Validation filter re adjusting hooks 185 88 function wpcf7wc_undo_hooks( $length ) { 186 //remove_filter( 'wpcf7_validate_textarea', 'wpcf7_textarea_validation_filter' );187 //remove_filter( 'wpcf7_validate_textarea*', 'wpcf7_textarea_validation_filter' );188 189 89 remove_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_textarea', 20 ); 190 90 } … … 201 101 add_action( 'wpcf7_init', 'wpcf7wc_add_shortcode_textarea', 20 ); 202 102 203 /*204 add_filter( 'wpcf7_validate_textarea', 'wpcf7wc_textarea_validation_filter', 10, 2 );205 add_filter( 'wpcf7_validate_textarea*', 'wpcf7wc_textarea_validation_filter', 10, 2 );206 207 function wpcf7wc_textarea_validation_filter( $result, $tag ) {208 $type = $tag['type'];209 $name = $tag['name'];210 211 $_POST[$name] = (string) $_POST[$name];212 213 if ( 'textarea*' == $type ) {214 if ( '' == $_POST[$name] ) {215 $result['valid'] = false;216 $result['reason'][$name] = wpcf7_get_message( 'invalid_required' );217 }218 }219 220 return $result;221 }222 */223 add_action( 'wpcf7_enqueue_scripts', 'wpcf7wc_enqueue_scripts' );224 225 103 function wpcf7wc_enqueue_scripts() { 226 104 $plugin_dir = trailingslashit(plugins_url(basename(dirname(__FILE__)))); 227 105 wp_enqueue_script( 'wpcf7wc', $plugin_dir .'wpcf7wc.js', 228 array( ' contact-form-7' ), 1.0, true );106 array( 'jquery', 'contact-form-7' ), '1.1', true ); 229 107 } 108 add_action( 'wpcf7_enqueue_scripts', 'wpcf7wc_enqueue_scripts' ); 230 109 231 / * Tag generator */110 // Tag generator 232 111 233 112 add_action( 'wpcf7_admin_init', 'wpcf7wc_add_tag_generator_textarea', 20 ); 234 113 235 114 function wpcf7wc_add_tag_generator_textarea() { 236 /*237 if ( function_exists( 'wpcf7_add_tag_generator' ) ) {238 wpcf7_add_tag_generator( 'textarea', __( 'Text area', 'wpcf7' ), 'wpcf7-tg-pane-textarea', 'wpcf7wc_tg_pane_textarea' );239 }240 */241 115 if ( class_exists( 'WPCF7_TagGenerator' ) ) { 242 116 $tag_generator = WPCF7_TagGenerator::get_instance(); … … 245 119 } 246 120 } 247 248 121 249 122 function wpcf7wc_tag_generator_textarea( $contact_form, $args = '' ) { … … 293 166 </tr> 294 167 295 296 297 168 <tr> 298 169 <th scope="row"><label for=<?php echo esc_attr( $args['content'] . '-maxwc' ); ?>"><?php echo esc_html( __( 'Max Wordcount', 'wpcf7wc' ) ); ?></label></th> … … 317 188 <?php 318 189 } 319 320 /*321 function wpcf7wc_tg_pane_textarea( &$contact_form ) {322 ?>323 <div id="wpcf7-tg-pane-textarea" class="hidden">324 <form action="" name="wpcf7wc">325 <table>326 <tr><td><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field?', 'wpcf7' ) ); ?></td></tr>327 <tr><td><?php echo esc_html( __( 'Name', 'wpcf7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>328 </table>329 330 <table>331 <tr>332 <td><code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />333 <input type="text" name="id" class="idvalue oneline option" /></td>334 335 <td><code>class</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />336 <input type="text" name="class" class="classvalue oneline option" /></td>337 </tr>338 339 <tr>340 <td><code>cols</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />341 <input type="text" name="cols" class="numeric oneline option" /></td>342 343 <td><code>rows</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />344 <input type="text" name="rows" class="numeric oneline option" /></td>345 </tr>346 347 <tr>348 <td><code>max word count</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />349 <input type="text" name="maxlength" class="numeric oneline option" /></td>350 351 <td><input type="hidden" name="size" value="" /></td>352 </tr>353 354 <tr>355 <td><?php echo esc_html( __( 'Default value', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /><input type="text" name="values" class="oneline" /></td>356 357 <td>358 <br /><input type="checkbox" name="watermark" class="option" /> <?php echo esc_html( __( 'Use this text as watermark?', 'wpcf7' ) ); ?>359 </td>360 </tr>361 </table>362 363 <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?><br /><input type="text" name="textarea" class="tag" readonly="readonly" onfocus="this.select()" /></div>364 365 <div class="tg-mail-tag"><?php echo esc_html( __( "And, put this code into the Mail fields below.", 'wpcf7' ) ); ?><br /><span class="arrow">⬇</span> <input type="text" class="mail-tag" readonly="readonly" onfocus="this.select()" /></div>366 </form>367 </div>368 <?php369 }370 */
Note: See TracChangeset
for help on using the changeset viewer.