1- <?php
1+ <?php
22
33 /*
44 Plugin Name: ACF Input Counter
55 Plugin URI: https://github.com/Hube2/acf-input-counter/
66 Description: Show character count for limited text and textarea fields
7- Version: 1.3.1
7+ Version: 1.4.0
88 Author: John A. Huebner II
99 Author URI: https://github.com/Hube2/
10+ Text-domain: acf-counter
11+ Domain-path: languages
1012 GitHub Plugin URI: https://github.com/Hube2/acf-input-counter/
1113 License: GPL
1214 */
1820
1921 class acf_input_counter {
2022
21- private $ version = '1.2 .0 ' ;
23+ private $ version = '1.4 .0 ' ;
2224
2325 public function __construct () {
24- add_action ('acf/render_field/type=text ' , array ($ this , 'render_field ' ), 20 , 1 );
25- add_action ('acf/render_field/type=textarea ' , array ($ this , 'render_field ' ), 20 , 1 );
26- add_action ('acf/input/admin_enqueue_scripts ' , array ($ this , 'scripts ' ));
27- add_filter ('jh_plugins_list ' , array ($ this , 'meta_box_data ' ));
26+ add_action ('plugins_loaded ' , array ($ this , 'acf_counter_load_plugin_textdomain ' ));
27+ add_action ('acf/render_field/type=text ' , array ($ this , 'render_field ' ), 20 , 1 );
28+ add_action ('acf/render_field/type=textarea ' , array ($ this , 'render_field ' ), 20 , 1 );
29+ add_action ('acf/input/admin_enqueue_scripts ' , array ($ this , 'scripts ' ));
30+ add_filter ('jh_plugins_list ' , array ($ this , 'meta_box_data ' ));
2831 } // end public function __construct
29-
32+
33+ public function acf_counter_load_plugin_textdomain () {
34+ load_plugin_textdomain ( 'acf-counter ' , FALSE , basename ( dirname ( __FILE__ ) ) . '/languages/ ' );
35+ }
36+
3037 function meta_box_data ($ plugins =array ()) {
31-
38+
3239 $ plugins [] = array (
33- 'title ' => 'ACF Input Counter ' ,
34- 'screens ' => array ('acf-field-group ' , 'edit-acf-field-group ' ),
35- 'doc ' => 'https://github.com/Hube2/acf-input-counter '
40+ 'title ' => 'ACF Input Counter ' ,
41+ 'screens ' => array ('acf-field-group ' , 'edit-acf-field-group ' ),
42+ 'doc ' => 'https://github.com/Hube2/acf-input-counter '
3643 );
3744 return $ plugins ;
38-
45+
3946 } // end function meta_box
4047
4148 private function run () {
@@ -54,11 +61,11 @@ public function scripts() {
5461 return ;
5562 }
5663 // wp_enqueue_script
57- $ handle = 'acf-input-counter ' ;
58- $ src = plugin_dir_url (__FILE__ ).'acf-input-counter.js ' ;
59- $ deps = array ('acf-input ' );
60- $ ver = $ this ->version ;
61- $ in_footer = false ;
64+ $ handle = 'acf-input-counter ' ;
65+ $ src = plugin_dir_url (__FILE__ ).'acf-input-counter.js ' ;
66+ $ deps = array ('acf-input ' );
67+ $ ver = $ this ->version ;
68+ $ in_footer = false ;
6269 wp_enqueue_script ($ handle , $ src , $ deps , $ ver , $ in_footer );
6370 wp_enqueue_style ('acf-counter ' , plugins_url ( 'acf-counter.css ' , __FILE__ ));
6471 } // end public function scripts
@@ -73,20 +80,20 @@ public function render_field($field) {
7380 }
7481 $ len = strlen ($ field ['value ' ]);
7582 $ max = $ field ['maxlength ' ];
76-
77- $ classes = apply_filters ('acf-input-counter/classes ' , array ());
78- $ ids = apply_filters ('acf-input-counter/ids ' , array ());
79-
83+
84+ $ classes = apply_filters ('acf-input-counter/classes ' , array ());
85+ $ ids = apply_filters ('acf-input-counter/ids ' , array ());
86+
8087 $ insert = true ;
8188 if (count ($ classes ) || count ($ ids )) {
8289 $ insert = false ;
83-
90+
8491 $ exist = array ();
8592 if ($ field ['wrapper ' ]['class ' ]) {
8693 $ exist = explode (' ' , $ field ['wrapper ' ]['class ' ]);
8794 }
8895 $ insert = $ this ->check ($ classes , $ exist );
89-
96+
9097 if (!$ insert && $ field ['wrapper ' ]['id ' ]) {
9198 $ exist = array ();
9299 if ($ field ['wrapper ' ]['id ' ]) {
@@ -95,23 +102,27 @@ public function render_field($field) {
95102 $ insert = $ this ->check ($ ids , $ exist );
96103 }
97104 } // end if filter classes or ids
98-
105+
99106 if (!$ insert ) {
100107 return ;
101108 }
102- $ display = 'chars: %%len%% of %%max%% ' ;
109+ $ display = sprintf (
110+ __ ('chars: %1$s of %2$s ' , 'acf-counter ' ),
111+ '%%len%% ' ,
112+ '%%max%% '
113+ );
103114 $ display = apply_filters ('acf-input-counter/display ' , $ display );
104115 $ display = str_replace ('%%len%% ' , '<span class="count"> ' .$ len .'</span> ' , $ display );
105116 $ display = str_replace ('%%max%% ' , $ max , $ display );
106117 ?>
107118 <span class="char-count">
108- <?php
119+ <?php
109120 echo $ display ;
110121 ?>
111122 </span>
112123 <?php
113124 } // end public function render_field
114-
125+
115126 private function check ($ allow , $ exist ) {
116127 // if there is anything in $allow
117128 // see if any of those values are in $exist
@@ -123,50 +134,50 @@ private function check($allow, $exist) {
123134 } // end private function check
124135
125136 } // end class acf_input_counter
126-
137+
127138 if (!function_exists ('jh_plugins_list_meta_box ' )) {
128139 function jh_plugins_list_meta_box () {
129140 if (apply_filters ('remove_hube2_nag ' , false )) {
130141 return ;
131142 }
132143 $ plugins = apply_filters ('jh_plugins_list ' , array ());
133-
134- $ id = 'plugins-by-john-huebner ' ;
135- $ title = '<a style="text-decoration: none; font-size: 1em;" href="https://github.com/Hube2" target="_blank">Plugins by John Huebner</a> ' ;
136- $ callback = 'show_blunt_plugins_list_meta_box ' ;
137- $ screens = array ();
144+
145+ $ id = 'plugins-by-john-huebner ' ;
146+ $ title = '<a style="text-decoration: none; font-size: 1em;" href="https://github.com/Hube2" target="_blank">Plugins by John Huebner</a> ' ;
147+ $ callback = 'show_blunt_plugins_list_meta_box ' ;
148+ $ screens = array ();
138149 foreach ($ plugins as $ plugin ) {
139150 $ screens = array_merge ($ screens , $ plugin ['screens ' ]);
140151 }
141- $ context = 'side ' ;
142- $ priority = 'low ' ;
152+ $ context = 'side ' ;
153+ $ priority = 'low ' ;
143154 add_meta_box ($ id , $ title , $ callback , $ screens , $ context , $ priority );
144-
145-
155+
156+
146157 } // end function jh_plugins_list_meta_box
147158 add_action ('add_meta_boxes ' , 'jh_plugins_list_meta_box ' );
148-
159+
149160 function show_blunt_plugins_list_meta_box () {
150161 $ plugins = apply_filters ('jh_plugins_list ' , array ());
151162 ?>
152163 <p style="margin-bottom: 0;">Thank you for using my plugins</p>
153164 <ul style="margin-top: 0; margin-left: 1em;">
154- <?php
165+ <?php
155166 foreach ($ plugins as $ plugin ) {
156167 ?>
157168 <li style="list-style-type: disc; list-style-position:">
158- <?php
169+ <?php
159170 echo $ plugin ['title ' ];
160171 if ($ plugin ['doc ' ]) {
161- ?> <a href="<?php echo $ plugin ['doc ' ]; ?> " target="_blank">Documentation</a><?php
172+ ?> <a href="<?php echo $ plugin ['doc ' ]; ?> " target="_blank">Documentation</a><?php
162173 }
163174 ?>
164175 </li>
165- <?php
176+ <?php
166177 }
167178 ?>
168179 </ul>
169- <p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=hube02%40earthlink%2enet&lc=US&item_name=Donation%20for%20WP%20Plugins%20I%20Use&no_note=0&cn=Add%20special%20instructions%20to%20the%20seller%3a&no_shipping=1¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank">Please consider making a small donation.</a></p><?php
180+ <p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=hube02%40earthlink%2enet&lc=US&item_name=Donation%20for%20WP%20Plugins%20I%20Use&no_note=0&cn=Add%20special%20instructions%20to%20the%20seller%3a&no_shipping=1¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank">Please consider making a small donation.</a></p><?php
170181 }
171182 } // end if !function_exists
172183
0 commit comments