1
- <?php
1
+ <?php
2
2
3
3
/*
4
4
Plugin Name: ACF Input Counter
5
5
Plugin URI: https://github.com/Hube2/acf-input-counter/
6
6
Description: Show character count for limited text and textarea fields
7
- Version: 1.3.1
7
+ Version: 1.4.0
8
8
Author: John A. Huebner II
9
9
Author URI: https://github.com/Hube2/
10
+ Text-domain: acf-counter
11
+ Domain-path: languages
10
12
GitHub Plugin URI: https://github.com/Hube2/acf-input-counter/
11
13
License: GPL
12
14
*/
18
20
19
21
class acf_input_counter {
20
22
21
- private $ version = '1.2 .0 ' ;
23
+ private $ version = '1.4 .0 ' ;
22
24
23
25
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 ' ));
28
31
} // 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
+
30
37
function meta_box_data ($ plugins =array ()) {
31
-
38
+
32
39
$ 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 '
36
43
);
37
44
return $ plugins ;
38
-
45
+
39
46
} // end function meta_box
40
47
41
48
private function run () {
@@ -54,11 +61,11 @@ public function scripts() {
54
61
return ;
55
62
}
56
63
// 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 ;
62
69
wp_enqueue_script ($ handle , $ src , $ deps , $ ver , $ in_footer );
63
70
wp_enqueue_style ('acf-counter ' , plugins_url ( 'acf-counter.css ' , __FILE__ ));
64
71
} // end public function scripts
@@ -73,20 +80,20 @@ public function render_field($field) {
73
80
}
74
81
$ len = strlen ($ field ['value ' ]);
75
82
$ 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
+
80
87
$ insert = true ;
81
88
if (count ($ classes ) || count ($ ids )) {
82
89
$ insert = false ;
83
-
90
+
84
91
$ exist = array ();
85
92
if ($ field ['wrapper ' ]['class ' ]) {
86
93
$ exist = explode (' ' , $ field ['wrapper ' ]['class ' ]);
87
94
}
88
95
$ insert = $ this ->check ($ classes , $ exist );
89
-
96
+
90
97
if (!$ insert && $ field ['wrapper ' ]['id ' ]) {
91
98
$ exist = array ();
92
99
if ($ field ['wrapper ' ]['id ' ]) {
@@ -95,23 +102,27 @@ public function render_field($field) {
95
102
$ insert = $ this ->check ($ ids , $ exist );
96
103
}
97
104
} // end if filter classes or ids
98
-
105
+
99
106
if (!$ insert ) {
100
107
return ;
101
108
}
102
- $ display = 'chars: %%len%% of %%max%% ' ;
109
+ $ display = sprintf (
110
+ __ ('chars: %1$s of %2$s ' , 'acf-counter ' ),
111
+ '%%len%% ' ,
112
+ '%%max%% '
113
+ );
103
114
$ display = apply_filters ('acf-input-counter/display ' , $ display );
104
115
$ display = str_replace ('%%len%% ' , '<span class="count"> ' .$ len .'</span> ' , $ display );
105
116
$ display = str_replace ('%%max%% ' , $ max , $ display );
106
117
?>
107
118
<span class="char-count">
108
- <?php
119
+ <?php
109
120
echo $ display ;
110
121
?>
111
122
</span>
112
123
<?php
113
124
} // end public function render_field
114
-
125
+
115
126
private function check ($ allow , $ exist ) {
116
127
// if there is anything in $allow
117
128
// see if any of those values are in $exist
@@ -123,50 +134,50 @@ private function check($allow, $exist) {
123
134
} // end private function check
124
135
125
136
} // end class acf_input_counter
126
-
137
+
127
138
if (!function_exists ('jh_plugins_list_meta_box ' )) {
128
139
function jh_plugins_list_meta_box () {
129
140
if (apply_filters ('remove_hube2_nag ' , false )) {
130
141
return ;
131
142
}
132
143
$ 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 ();
138
149
foreach ($ plugins as $ plugin ) {
139
150
$ screens = array_merge ($ screens , $ plugin ['screens ' ]);
140
151
}
141
- $ context = 'side ' ;
142
- $ priority = 'low ' ;
152
+ $ context = 'side ' ;
153
+ $ priority = 'low ' ;
143
154
add_meta_box ($ id , $ title , $ callback , $ screens , $ context , $ priority );
144
-
145
-
155
+
156
+
146
157
} // end function jh_plugins_list_meta_box
147
158
add_action ('add_meta_boxes ' , 'jh_plugins_list_meta_box ' );
148
-
159
+
149
160
function show_blunt_plugins_list_meta_box () {
150
161
$ plugins = apply_filters ('jh_plugins_list ' , array ());
151
162
?>
152
163
<p style="margin-bottom: 0;">Thank you for using my plugins</p>
153
164
<ul style="margin-top: 0; margin-left: 1em;">
154
- <?php
165
+ <?php
155
166
foreach ($ plugins as $ plugin ) {
156
167
?>
157
168
<li style="list-style-type: disc; list-style-position:">
158
- <?php
169
+ <?php
159
170
echo $ plugin ['title ' ];
160
171
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
162
173
}
163
174
?>
164
175
</li>
165
- <?php
176
+ <?php
166
177
}
167
178
?>
168
179
</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
170
181
}
171
182
} // end if !function_exists
172
183
0 commit comments