PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.0.21
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.0.21
1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 All 173 releases
userswp / includes / class-callback.php

class-callback.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.0.21, at includes/class-callback.php

340 lines 12.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Setting fields callback functions
4 *
5 * This class defines all code necessary to display setting field input.
6 *
7 * @link http://wpgeodirectory.com
8 * @since 1.0.0
9 *
10 * @package userswp
11 */
12 class UsersWP_Callback {
13
14 public function uwp_missing_callback($args) {
15 printf(
16 __( 'The callback function used for the %s setting is missing.', 'userswp' ),
17 '<strong>' . $args['id'] . '</strong>'
18 );
19 }
20
21 public function uwp_select_callback($args) {
22
23 global $uwp_options;
24
25 $global = isset( $args['global'] ) ? $args['global'] : true;
26 if ($global) {
27 if ( isset( $uwp_options[ $args['id'] ] ) ) {
28 $value = $uwp_options[ $args['id'] ];
29 } else {
30 $value = isset( $args['std'] ) ? $args['std'] : '';
31 }
32 } else {
33 if ( isset( $args['value'] ) ) {
34 $value = $args['value'];
35 } else {
36 $value = isset( $args['std'] ) ? $args['std'] : '';
37 }
38 }
39
40
41 if ( isset( $args['placeholder'] ) ) {
42 $placeholder = $args['placeholder'];
43 } else {
44 $placeholder = '';
45 }
46
47 if ( isset( $args['chosen'] ) ) {
48 $chosen = ($args['multiple'] ? '[]" multiple="multiple" class="uwp_chosen_select" style="height:auto"' : '"');
49 } else {
50 $chosen = '';
51 }
52
53 $html = '<select id="uwp_settings[' . $args['id'] . ']" name="uwp_settings[' . $args['id'] . ']' . $chosen . ' data-placeholder="' . $placeholder . '" />';
54
55 foreach ( $args['options'] as $option => $name ) {
56 if (is_array($value)) {
57 if (in_array($option, $value)) {
58 $selected = 'selected="selected"';
59 } else {
60 $selected = '';
61 }
62 } else {
63 $selected = selected( $option, $value, false );
64 }
65 $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>';
66 }
67
68 $html .= '</select>';
69 $html .= '<label for="uwp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
70
71 echo $html;
72 }
73
74 public function uwp_select_order_callback($args) {
75
76 global $uwp_options;
77
78 $global = isset( $args['global'] ) ? $args['global'] : true;
79 if ($global) {
80 if ( isset( $uwp_options[ $args['id'] ] ) ) {
81 $value = $uwp_options[ $args['id'] ];
82 } else {
83 $value = isset( $args['std'] ) ? $args['std'] : '';
84 }
85 } else {
86 if ( isset( $args['value'] ) ) {
87 $value = $args['value'];
88 } else {
89 $value = isset( $args['std'] ) ? $args['std'] : '';
90 }
91 }
92
93
94 if ( isset( $args['placeholder'] ) ) {
95 $placeholder = $args['placeholder'];
96 } else {
97 $placeholder = '';
98 }
99
100 if ( isset( $args['chosen'] ) ) {
101 $chosen = ($args['multiple'] ? '[]" multiple="multiple" style="height:auto;width:100%"' : "'");
102 } else {
103 $chosen = '';
104 }
105
106 //print_r($args);
107
108 $html = '<select id="uwp_dummy_' . $args['id'] . '" name="uwp_dummy_settings[' . $args['id'] . ']' . $chosen . ' data-placeholder="' . $placeholder . '" />';
109
110 foreach ( $args['options'] as $option => $name ) {
111 if (is_array($value)) {
112 if (in_array($option, $value)) {
113 $selected = 'selected="selected"';
114 } else {
115 $selected = '';
116 }
117 } else {
118 $selected = selected( $option, $value, false );
119 }
120 $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>';
121 }
122
123 $html .= '</select>';
124 $html .= '<label for="uwp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
125
126 // The hidden select with correct orders
127 $html .= '<select style="visibility: hidden;
128 height: 0px;
129 padding: 0;
130 margin: 0;
131 float: left;" id="' . $args['id'] . '" name="uwp_settings[' . $args['id'] . '][]" multiple="multiple" data-placeholder="' . $placeholder . '" />';
132
133 if (is_array($value)) {
134 foreach ( $value as $option ) {
135 if ( in_array( $option,array_keys($args['options']) ) ) {
136 $selected = 'selected="selected"';
137 $html .= '<option value="' . $option . '" ' . $selected . '>' . $args['options'][$option] . '</option>';
138 }
139 }
140 }
141
142 $html .= '</select>';
143
144 echo $html;
145
146
147 ?>
148 <script>
149 jQuery(document).ready(function() {
150
151 jQuery("#uwp_dummy_<?php echo $args['id'];?>").chosen();
152
153 // Set the current order on load
154 var current_order = jQuery('#<?php echo $args['id'];?>').val();
155
156 if(current_order){
157 current_order = jQuery.unique( current_order );
158 ChosenOrder.setSelectionOrder(jQuery("#uwp_dummy_<?php echo $args['id'];?>"), current_order);
159 }
160
161 // on order change update the hidden real values
162 jQuery("#uwp_dummy_<?php echo $args['id'];?>").chosen().change(function () {
163 //console.log('changed');
164
165 setTimeout(function(){ // trigers before the item is removed so we add a slight delay
166 var selection = ChosenOrder.getSelectionOrder(jQuery("#uwp_dummy_<?php echo $args['id'];?>"));
167 //console.log(selection);
168 jQuery('#<?php echo $args['id'];?>').find('option').remove().end();
169
170 jQuery.each( selection, function( key, value ) {
171 jQuery('#<?php echo $args['id'];?>').append('<option value="'+value+'" selected>'+value+'</option>')
172 });
173
174 }, 50);
175
176 });
177
178 });
179 </script>
180
181 <?php
182 }
183
184 public function uwp_text_callback( $args ) {
185 global $uwp_options;
186
187 $global = isset( $args['global'] ) ? $args['global'] : true;
188 if ($global) {
189 if ( isset( $uwp_options[ $args['id'] ] ) ) {
190 $value = $uwp_options[ $args['id'] ];
191 } else {
192 $value = isset( $args['std'] ) ? $args['std'] : '';
193 }
194 } else {
195 if ( isset( $args['value'] ) ) {
196 $value = $args['value'];
197 } else {
198 $value = isset( $args['std'] ) ? $args['std'] : '';
199 }
200 }
201
202 if ( isset( $args['faux'] ) && true === $args['faux'] ) {
203 $args['readonly'] = true;
204 $value = isset( $args['std'] ) ? $args['std'] : '';
205 $name = '';
206 } else {
207 $name = 'name="uwp_settings[' . $args['id'] . ']"';
208 }
209
210 $readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
211 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
212 $html = '<input type="text" class="' . $size . '-text" id="uwp_settings[' . $args['id'] . ']"' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
213 $html .= '<label for="uwp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
214
215 echo $html;
216 }
217
218 public function uwp_textarea_callback( $args ) {
219 global $uwp_options;
220
221 $global = isset( $args['global'] ) ? $args['global'] : true;
222 if ($global) {
223 if ( isset( $uwp_options[ $args['id'] ] ) ) {
224 $value = $uwp_options[ $args['id'] ];
225 } else {
226 $value = isset( $args['std'] ) ? $args['std'] : '';
227 }
228 } else {
229 if ( isset( $args['value'] ) ) {
230 $value = $args['value'];
231 } else {
232 $value = isset( $args['std'] ) ? $args['std'] : '';
233 }
234 }
235
236 $html = '<textarea class="large-text" cols="50" rows="5" id="uwp_settings[' . $args['id'] . ']" name="uwp_settings[' . $args['id'] . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
237 $html .= '<label for="uwp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
238
239 echo $html;
240 }
241
242 public function uwp_checkbox_callback( $args ) {
243 global $uwp_options;
244
245 if ( isset( $args['faux'] ) && true === $args['faux'] ) {
246 $name = '';
247 } else {
248 $name = 'name="uwp_settings[' . $args['id'] . ']"';
249 }
250
251 $checked = isset( $uwp_options[ $args['id'] ] ) ? checked( 1, $uwp_options[ $args['id'] ], false ) : '';
252 $html = '<input type="checkbox" id="uwp_settings[' . $args['id'] . ']"' . $name . ' value="1" ' . $checked . '/>';
253 $html .= '<label for="uwp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
254
255 echo $html;
256 }
257
258 public function uwp_number_callback( $args ) {
259 global $uwp_options;
260
261 $global = isset( $args['global'] ) ? $args['global'] : true;
262 if ($global) {
263 if ( isset( $uwp_options[ $args['id'] ] ) ) {
264 $value = $uwp_options[ $args['id'] ];
265 } else {
266 $value = isset( $args['std'] ) ? $args['std'] : '';
267 }
268 } else {
269 if ( isset( $args['value'] ) ) {
270 $value = $args['value'];
271 } else {
272 $value = isset( $args['std'] ) ? $args['std'] : '';
273 }
274 }
275
276 if ( isset( $args['faux'] ) && true === $args['faux'] ) {
277 $args['readonly'] = true;
278 $value = isset( $args['std'] ) ? $args['std'] : '';
279 $name = '';
280 } else {
281 $name = 'name="uwp_settings[' . $args['id'] . ']"';
282 }
283
284 $max = isset( $args['max'] ) ? $args['max'] : 999999;
285 $min = isset( $args['min'] ) ? $args['min'] : 0;
286 $step = isset( $args['step'] ) ? $args['step'] : 1;
287
288 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
289 $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . $size . '-text" id="uwp_settings[' . $args['id'] . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
290 $html .= '<label for="uwp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
291
292 echo $html;
293 }
294
295 public function uwp_info_callback( $args ) {
296 echo $args['desc'];
297 }
298
299 public function uwp_media_callback( $args ) {
300 global $uwp_options;
301
302 $global = isset( $args['global'] ) ? $args['global'] : true;
303 if ($global) {
304 if ( isset( $uwp_options[ $args['id'] ] ) ) {
305 $value = $uwp_options[ $args['id'] ];
306 } else {
307 $value = isset( $args['std'] ) ? $args['std'] : '';
308 }
309 } else {
310 if ( isset( $args['value'] ) ) {
311 $value = $args['value'];
312 } else {
313 $value = isset( $args['std'] ) ? $args['std'] : '';
314 }
315 }
316 wp_enqueue_media();
317 if(isset($value) && $value > 0){
318 $image = wp_get_attachment_url($value);
319 $is_default = false;
320 } elseif(isset($args['placeholder']) && $args['placeholder']){
321 $image = esc_attr($args['placeholder']);
322 $is_default = true;
323 }else {
324 $image = admin_url('images/media-button-image.gif');
325 $is_default = true;
326 }
327 ?>
328 <div class="uwp_media_input">
329 <input type="hidden" id="uwp_settings[<?php echo $args['id']; ?>]" class="uwp_img_url" name="uwp_settings[<?php echo $args['id']; ?>]" value="<?php echo $value; ?>" />
330 <input id="uwp_upload_btn" type="button" class="button uwp_upload_btn" value="<?php _e( 'Upload', 'wptuts' ); ?>" /><br><br>
331 <input id="uwp_remove_btn" type="button" class="button uwp_remove_btn" value="<?php _e( 'Remove', 'wptuts' ); ?>" style="<?php if($is_default){ echo "display:none;"; } ?>" />
332 </div>
333 <div class="uwp_media_preview">
334 <img src="<?php echo $image; ?>" style="max-height: 100px;" />
335 </div>
336 <label for="uwp_settings[<?php echo $args['id']; ?>]"><?php echo $args['desc']; ?></label>
337 <?php
338 }
339
340 }