acceptance.php
11 years ago
akismet.php
11 years ago
captcha.php
11 years ago
checkbox.php
11 years ago
count.php
11 years ago
date.php
11 years ago
file.php
11 years ago
flamingo.php
11 years ago
jetpack.php
11 years ago
listo.php
12 years ago
number.php
11 years ago
quiz.php
11 years ago
response.php
11 years ago
select.php
11 years ago
submit.php
11 years ago
text.php
11 years ago
textarea.php
11 years ago
count.php
57 lines
| 1 | <?php |
| 2 | /** |
| 3 | ** A base module for [count], Twitter-like character count |
| 4 | **/ |
| 5 | |
| 6 | /* Shortcode handler */ |
| 7 | |
| 8 | add_action( 'wpcf7_init', 'wpcf7_add_shortcode_count' ); |
| 9 | |
| 10 | function wpcf7_add_shortcode_count() { |
| 11 | wpcf7_add_shortcode( 'count', 'wpcf7_count_shortcode_handler', true ); |
| 12 | } |
| 13 | |
| 14 | function wpcf7_count_shortcode_handler( $tag ) { |
| 15 | $tag = new WPCF7_Shortcode( $tag ); |
| 16 | |
| 17 | if ( empty( $tag->name ) ) { |
| 18 | return ''; |
| 19 | } |
| 20 | |
| 21 | $target = wpcf7_scan_shortcode( array( 'name' => $tag->name ) ); |
| 22 | $maxlength = $minlength = null; |
| 23 | |
| 24 | if ( $target ) { |
| 25 | $target = new WPCF7_Shortcode( $target[0] ); |
| 26 | $maxlength = $target->get_maxlength_option(); |
| 27 | $minlength = $target->get_minlength_option(); |
| 28 | |
| 29 | if ( $maxlength && $minlength && $maxlength < $minlength ) { |
| 30 | $maxlength = $minlength = null; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | if ( $tag->has_option( 'down' ) ) { |
| 35 | $value = (int) $maxlength; |
| 36 | $class = 'wpcf7-character-count down'; |
| 37 | } else { |
| 38 | $value = '0'; |
| 39 | $class = 'wpcf7-character-count up'; |
| 40 | } |
| 41 | |
| 42 | $atts = array(); |
| 43 | $atts['id'] = $tag->get_id_option(); |
| 44 | $atts['class'] = $tag->get_class_option( $class ); |
| 45 | $atts['data-target-name'] = $tag->name; |
| 46 | $atts['data-starting-value'] = $value; |
| 47 | $atts['data-current-value'] = $value; |
| 48 | $atts['data-maximum-value'] = $maxlength; |
| 49 | $atts['data-minimum-value'] = $minlength; |
| 50 | $atts = wpcf7_format_atts( $atts ); |
| 51 | |
| 52 | $html = sprintf( '<span %1$s>%2$s</span>', $atts, $value ); |
| 53 | |
| 54 | return $html; |
| 55 | } |
| 56 | |
| 57 | ?> |