PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 2.33
Strong Testimonials v2.33
3.3.3 3.3.2 3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / admin / custom-fields.php
strong-testimonials / admin Last commit date
about 7 years ago css 7 years ago img 8 years ago js 7 years ago menu 8 years ago partials 7 years ago scss 7 years ago settings 7 years ago admin-notices.php 8 years ago admin.php 7 years ago class-strong-testimonials-admin-category-list.php 8 years ago class-strong-testimonials-admin-list.php 7 years ago class-strong-testimonials-admin-scripts.php 8 years ago class-strong-testimonials-defaults.php 7 years ago class-strong-testimonials-help.php 8 years ago class-strong-testimonials-list-table.php 7 years ago class-strong-testimonials-page-shortcodes.php 7 years ago class-strong-testimonials-post-editor.php 7 years ago class-strong-testimonials-updater.php 7 years ago class-strong-views-list-table.php 8 years ago class-walker-strong-category-checklist.php 7 years ago class-walker-strong-form-category-checklist.php 7 years ago compat.php 8 years ago custom-fields-ajax.php 8 years ago custom-fields.php 7 years ago form-preview.php 8 years ago view-list-order.php 8 years ago views-ajax.php 7 years ago views-validate.php 7 years ago views.php 7 years ago
custom-fields.php
493 lines
1 <?php
2 /**
3 * Strong Testimonials - Custom fields admin functions
4 */
5
6 function wpmtst_form_admin() {
7 do_action( 'wpmtst_form_admin' );
8 }
9
10 function wpmtst_form_admin2() {
11 wpmtst_settings_custom_fields( 1 );
12 }
13
14 add_action( 'wpmtst_form_admin', 'wpmtst_form_admin2' );
15
16 /**
17 * Save changes to custom fields.
18 *
19 * @since 2.28.5 As separate function on custom action.
20 */
21 function wpmtst_update_custom_fields() {
22 $goback = wp_get_referer();
23
24 if ( ! isset( $_POST['wpmtst_form_submitted'] ) ) {
25 wp_redirect( $goback );
26 exit;
27 }
28
29 if ( ! wp_verify_nonce( $_POST['wpmtst_form_submitted'], 'wpmtst_custom_fields_form' ) ) {
30 wp_redirect( $goback );
31 exit;
32 }
33
34 $form_id = $_POST['form_id'];
35 $forms = get_option( 'wpmtst_custom_forms' );
36 $field_options = apply_filters( 'wpmtst_fields', get_option( 'wpmtst_fields' ) );
37
38 if ( isset( $_POST['reset'] ) ) {
39
40 // Undo changes
41 wpmtst_add_admin_notice( 'changes-cancelled' );
42
43 }
44 elseif ( isset( $_POST['restore-defaults'] ) ) {
45
46 // Restore defaults
47 $default_forms = Strong_Testimonials_Defaults::get_base_forms();
48 $fields = $default_forms['default']['fields'];
49 $forms[ $form_id ]['fields'] = $fields;
50 update_option( 'wpmtst_custom_forms', $forms );
51 do_action( 'wpmtst_fields_updated', $fields );
52
53 wpmtst_add_admin_notice( 'defaults-restored' );
54
55 }
56 else {
57
58 // Save changes
59 $fields = array();
60 $new_key = 0;
61
62 /**
63 * Strip the dang slashes from the dang magic quotes.
64 *
65 * @since 2.0.0
66 */
67 $post_fields = stripslashes_deep( $_POST['fields'] );
68
69 foreach ( $post_fields as $key => $field ) {
70
71 /*
72 * Before merging onto base field, catch fields that are "off"
73 * which the form does not submit. Otherwise, the default "on"
74 * would override the requested (but not submitted) "off".
75 */
76 $field['show_label'] = isset( $field['show_label'] ) ? 1 : 0;
77 $field['required'] = isset( $field['required'] ) ? 1 : 0;
78
79 $field = array_merge( $field_options['field_base'], $field );
80
81 $field['name'] = sanitize_text_field( $field['name'] );
82 $field['label'] = sanitize_text_field( $field['label'] );
83
84 // TODO Replace this special handling
85 if ( 'checkbox' == $field['input_type'] ) {
86 $field['default_form_value'] = wpmtst_sanitize_checkbox( $field, 'default_form_value' );
87 } else {
88 $field['default_form_value'] = sanitize_text_field( $field['default_form_value'] );
89 }
90 $field['action_input'] = isset( $field['action_input'] ) ? sanitize_text_field( $field['action_input'] ) : '';
91 $field['action_output'] = isset( $field['action_output'] ) ? sanitize_text_field( $field['action_output'] ) : '';
92
93 $field['default_display_value'] = sanitize_text_field( $field['default_display_value'] );
94
95 $field['placeholder'] = sanitize_text_field( $field['placeholder'] );
96
97 if ( isset( $field['text'] ) ) {
98 $field['text'] = wp_kses_post( $field['text'] );
99 }
100 $field['before'] = wp_kses_post( $field['before'] );
101 $field['after'] = wp_kses_post( $field['after'] );
102
103 $field['shortcode_on_form'] = sanitize_text_field( $field['shortcode_on_form'] );
104 $field['shortcode_on_display'] = sanitize_text_field( $field['shortcode_on_display'] );
105 $field['show_shortcode_options'] = $field['show_shortcode_options'] ? 1 : 0;
106
107 // Hidden options (no need to check if isset)
108 $field['admin_table'] = $field['admin_table'] ? 1 : 0;
109 $field['show_admin_table_option'] = $field['show_admin_table_option'] ? 1 : 0;
110 $field['show_text_option'] = $field['show_text_option'] ? 1 : 0;
111 $field['show_placeholder_option'] = $field['show_placeholder_option'] ? 1 : 0;
112 $field['show_default_options'] = $field['show_default_options'] ? 1 : 0;
113
114 // add to fields array in display order
115 $fields[ $new_key++ ] = $field;
116
117 }
118
119 $forms[ $form_id ]['fields'] = $fields;
120
121 if ( isset( $_POST['field_group_label'] ) ) {
122 // TODO Catch if empty.
123 $new_label = sanitize_text_field( $_POST['field_group_label'] );
124 $forms[ $form_id ]['label'] = $new_label;
125 }
126
127 update_option( 'wpmtst_custom_forms', $forms );
128 do_action( 'wpmtst_fields_updated', $fields );
129
130 wpmtst_add_admin_notice( 'fields-saved' );
131
132 }
133
134 wp_redirect( $goback );
135 exit;
136 }
137
138 add_action( 'admin_post_wpmtst_update_custom_fields', 'wpmtst_update_custom_fields' );
139
140 /**
141 * Custom Fields form
142 *
143 * @param int $form_id
144 */
145 function wpmtst_settings_custom_fields( $form_id = 1 ) {
146 if ( ! current_user_can( 'strong_testimonials_fields' ) ) {
147 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
148 }
149
150 if ( ! $form_id ) {
151 echo '<div class="wrap wpmtst"><p>' . __( 'No fields selected.', 'strong-testimonials' ) .'</p></div>';
152 return;
153 }
154
155 $forms = get_option( 'wpmtst_custom_forms' );
156 $fields = $forms[$form_id]['fields'];
157 ?>
158 <div class="wrap wpmtst">
159 <h1 class="wp-heading-inline"><?php _e( 'Fields', 'strong-testimonials' ); ?></h1>
160 <hr class="wp-header-end">
161 <?php do_action( 'wpmtst_fields_editor_before_fields_intro' ); ?>
162
163 <div id="left-col">
164 <div>
165 <h3><?php _e( 'Editor', 'strong-testimonials' ); ?></h3>
166 <p>
167 <?php _e( 'Click a field to open its options panel.', 'strong-testimonials' ); ?>
168 <a class="open-help-tab" href="#tab-panel-wpmtst-help"><?php _e( 'Help' ); ?></a>
169 </p>
170 <?php do_action( 'wpmtst_before_fields_settings', 'form-fields' ); ?>
171 </div>
172
173 <form id="wpmtst-custom-fields-form" method="post" action="<?php echo admin_url( 'admin-post.php' ); ?>" autocomplete="off">
174 <?php wp_nonce_field( 'wpmtst_custom_fields_form', 'wpmtst_form_submitted' ); ?>
175 <input type="hidden" name="action" value="wpmtst_update_custom_fields">
176 <input type="hidden" name="form_id" value="<?php echo $form_id; ?>">
177
178 <?php do_action( 'wpmtst_fields_editor_before_fields_editor', $forms[ $form_id ] ); ?>
179
180 <ul id="custom-field-list">
181 <?php
182 foreach ( $fields as $key => $field ) {
183 echo '<li id="field-' . $key . '">' . wpmtst_show_field( $key, $field, false ) . '</li>' . "\n";
184 }
185 ?>
186 </ul>
187
188 <div id="add-field-bar">
189 <input id="add-field" type="button" class="button" name="add-field" value="<?php _e( 'Add New Field', 'strong-testimonials' ); ?>">
190 </div>
191
192 <div id="field-group-actions">
193 <div><?php submit_button( '', 'primary', 'submit-form', false ); ?></div>
194 <div><?php submit_button( __( 'Cancel Changes', 'strong-testimonials' ), 'secondary', 'reset', false ); ?></div>
195 <div><?php submit_button( __( 'Restore Defaults', 'strong-testimonials' ), 'secondary', 'restore-defaults', false ); ?></div>
196 </div>
197 </form>
198 </div><!-- #left-col -->
199
200 <div id="right-col">
201 <div class="intro">
202 <h3><?php _e( 'Basic Preview', 'strong-testimonials' ); ?></h3>
203 <p><?php _e( 'Only to demonstrate the fields. May look different in your theme.', 'strong-testimonials' ); ?></p>
204 </div>
205 <div id="fields-editor-preview">
206 <div><!-- placeholder --></div>
207 </div>
208 </div><!-- #right-col -->
209
210 </div><!-- .wrap -->
211 <?php
212 }
213
214 /**
215 * Add a field to the form
216 *
217 * @param $key
218 * @param $field
219 * @param $adding
220 *
221 * @return string
222 */
223 function wpmtst_show_field( $key, $field, $adding ) {
224 $fields = apply_filters( 'wpmtst_fields', get_option( 'wpmtst_fields' ) );
225 $field_types = $fields['field_types'];
226
227 ob_start();
228
229 include 'partials/fields/field-header.php';
230 ?>
231 <div class="custom-field" style="display: none;">
232 <table class="field-table">
233 <?php
234 include 'partials/fields/field-type.php';
235 include 'partials/fields/field-label.php';
236 include 'partials/fields/field-name.php';
237
238 if ( ! $adding ) {
239 echo wpmtst_show_field_secondary( $key, $field );
240 echo wpmtst_show_field_admin_table( $key, $field );
241 }
242 ?>
243 </table>
244
245 <?php
246 if ( ! $adding ) {
247 echo wpmtst_show_field_hidden( $key, $field );
248 }
249 include 'partials/fields/field-controls.php';
250 ?>
251 </div><!-- .custom-field -->
252
253 <?php
254 $html = ob_get_contents();
255 ob_end_clean();
256
257 return $html;
258 }
259
260
261 /**
262 * Create the secondary inputs for a new custom field.
263 * Called after field type is chosen (Post or Custom).
264 *
265 * @param $key
266 * @param $field
267 *
268 * @return string
269 */
270 function wpmtst_show_field_secondary( $key, $field ) {
271 $html = '';
272
273 /*
274 * Required
275 */
276 if ( isset( $field['show_required_option'] ) && $field['show_required_option'] ) {
277 // Disable option if this is a core field like post_content.
278 if ( isset( $field['core'] ) && $field['core'] ) {
279 $disabled = ' disabled="disabled"';
280 } else {
281 $disabled = false;
282 }
283
284 $html .= '<tr class="field-secondary">' . "\n";
285 $html .= '<th>' . __( 'Required', 'strong-testimonials' ) . '</th>' . "\n";
286 $html .= '<td>' . "\n";
287 if ( $disabled ) {
288 $html .= '<input type="hidden" name="fields[' . $key . '][required]" value="' . $field['required'] . '">';
289 $html .= '<input type="checkbox" ' . checked( $field['required'], true, false ) . $disabled . '>';
290 } else {
291 $html .= '<input type="checkbox" name="fields[' . $key . '][required]" ' . checked( $field['required'], true, false ) . '>';
292 }
293 $html .= '</td>' . "\n";
294 $html .= '</tr>' . "\n";
295 }
296
297 /*
298 * Placeholder
299 */
300 if ( $field['show_placeholder_option'] ) {
301 if ( isset( $field['placeholder'] ) ) {
302 $html .= '<tr class="field-secondary">' . "\n";
303 $html .= '<th>' . __( 'Placeholder', 'strong-testimonials' ) . '</th>' . "\n";
304 $html .= '<td><input type="text" name="fields[' . $key . '][placeholder]" value="' . esc_attr( $field['placeholder'] ) . '"></td>' . "\n";
305 $html .= '</tr>' . "\n";
306 }
307 }
308
309 /**
310 * Text (checkbox, radio)
311 *
312 * @since 2.23.0
313 */
314 if ( $field['show_text_option'] ) {
315 if ( isset( $field['text'] ) ) {
316 $html .= '<tr class="field-secondary">' . "\n";
317 $html .= '<th>' . __( 'Text', 'strong-testimonials' ) . '</th>' . "\n";
318 $html .= '<td><input type="text" name="fields[' . $key . '][text]" value="' . esc_attr( $field['text'] ) . '" placeholder="' . __( 'next to the checkbox', 'strong-testimonials' ) . '"></td>' . "\n";
319 $html .= '</tr>' . "\n";
320 }
321 }
322
323 /*
324 * Before
325 */
326 $html .= '<tr class="field-secondary">' . "\n";
327 $html .= '<th>' . __( 'Before', 'strong-testimonials' ) . '</th>' . "\n";
328 $html .= '<td><input type="text" name="fields[' . $key . '][before]" value="' . esc_attr( $field['before'] ) . '"></td>' . "\n";
329 $html .= '</tr>' . "\n";
330
331 /*
332 * After
333 */
334 $html .= '<tr class="field-secondary">' . "\n";
335 $html .= '<th>' . __( 'After', 'strong-testimonials' ) . '</th>' . "\n";
336 $html .= '<td><input type="text" name="fields[' . $key . '][after]" value="' . esc_attr( $field['after'] ) . '"></td>' . "\n";
337 $html .= '</tr>' . "\n";
338
339 /*
340 * Default Form Value
341 */
342 if ( $field['show_default_options'] ) {
343 if ( isset( $field['default_form_value'] ) ) {
344 $html .= '<tr class="field-secondary">' . "\n";
345 $html .= '<th>' . __( 'Default Form Value', 'strong-testimonials' ) . '</th>' . "\n";
346 $html .= '<td>' . "\n";
347
348 // TODO Replace this special handling
349 if ( 'rating' == $field['input_type'] ) {
350
351 $html .= '<input type="text" name="fields[' . $key . '][default_form_value]" value="' . esc_attr( $field['default_form_value'] ) . '" class="as-number">';
352 $html .= '<span class="help inline">' . __( 'stars', 'strong-testimonials' ) . '</span>';
353 $html .= '<span class="help">' . __( 'Populate the field with this value.', 'strong-testimonials' ) . '</span>';
354
355 } elseif ( 'checkbox' == $field['input_type'] ) {
356
357 $html .= '<label>';
358 $html .= '<input type="checkbox" name="fields[' . $key . '][default_form_value]" ' . checked( $field['default_form_value'], true, false ) . '>';
359 $html .= '<span class="help inline">' . __( 'Checked by default.', 'strong-testimonials' ) . '</span>';
360 $html .= '</label>';
361
362 } else {
363
364 $html .= '<input type="text" name="fields[' . $key . '][default_form_value]" value="' . esc_attr( $field['default_form_value'] ) . '">';
365 $html .= '<span class="help">' . __( 'Populate the field with this value.', 'strong-testimonials' ) . '</span>';
366
367 }
368
369 $html .= '</td>' . "\n";
370 $html .= '</tr>' . "\n";
371 }
372 }
373
374 /*
375 * Default Display Value
376 */
377 if ( $field['show_default_options'] ) {
378 // TODO Replace this special handling for checkbox type
379 if ( 'checkbox' != $field['input_type'] ) {
380 if ( isset( $field['default_display_value'] ) ) {
381 $html .= '<tr class="field-secondary">' . "\n";
382 $html .= '<th>' . __( 'Default Display Value', 'strong-testimonials' ) . '</th>' . "\n";
383 $html .= '<td>' . "\n";
384
385 // TODO Replace this special handling
386 if ( 'rating' == $field['input_type'] ) {
387 $html .= '<input type="text" name="fields[' . $key . '][default_display_value]" value="' . esc_attr( $field['default_display_value'] ) . '" class="as-number">';
388 $html .= '<span class="help inline">' . __( 'stars', 'strong-testimonials' ) . '</span>';
389 } else {
390 $html .= '<input type="text" name="fields[' . $key . '][default_display_value]" value="' . esc_attr( $field['default_display_value'] ) . '">';
391 }
392
393 $html .= '<span class="help">' . __( 'Display this on the testimonial if no value is submitted.', 'strong-testimonials' ) . '</span>';
394 $html .= '</td>' . "\n";
395 $html .= '</tr>' . "\n";
396 }
397 }
398 }
399
400 /*
401 * Shortcode Options
402 */
403 if ( $field['show_shortcode_options'] ) {
404 if ( isset( $field['shortcode_on_form'] ) ) {
405 $html .= '<tr class="field-secondary">' . "\n";
406 $html .= '<th>' . __( 'Shortcode on form', 'strong-testimonials' ) . '</th>' . "\n";
407 $html .= '<td>' . "\n";
408 $html .= '<input type="text" name="fields[' . $key . '][shortcode_on_form]" value="' . esc_attr( $field['shortcode_on_form'] ) . '">';
409 $html .= '</td>' . "\n";
410 $html .= '</tr>' . "\n";
411 }
412 if ( isset( $field['shortcode_on_display'] ) ) {
413 $html .= '<tr class="field-secondary">' . "\n";
414 $html .= '<th>' . __( 'Shortcode on display', 'strong-testimonials' ) . '</th>' . "\n";
415 $html .= '<td>' . "\n";
416 $html .= '<input type="text" name="fields[' . $key . '][shortcode_on_display]" value="' . esc_attr( $field['shortcode_on_display'] ) . '">';
417 $html .= '</td>' . "\n";
418 $html .= '</tr>' . "\n";
419 }
420 }
421
422 return $html;
423 }
424
425
426 /**
427 * Add type-specific [Admin Table] setting to form.
428 */
429 function wpmtst_show_field_admin_table( $key, $field ) {
430 // -------------------
431 // Show in Admin Table
432 // -------------------
433 if ( ! $field['show_admin_table_option'] ) {
434 $html = '<input type="hidden" name="fields[' . $key . '][show_admin_table_option]" value="' . $field['show_admin_table_option'] . '">';
435 return $html;
436 }
437
438 $html = '<tr class="field-admin-table">' . "\n";
439 $html .= '<th>' . __( 'Admin List', 'strong-testimonials' ) . '</th>' . "\n";
440 $html .= '<td>' . "\n";
441 if ( $field['admin_table_option'] ) {
442 $html .= '<label><input type="checkbox" class="field-admin-table" name="fields[' . $key . '][admin_table]" ' . checked( $field['admin_table'], 1, false ) . '>';
443 } else {
444 $html .= '<input type="checkbox" ' . checked( $field['admin_table'], 1, false ) . ' disabled="disabled"> <em>' . __( 'required', 'strong-testimonials' ) . '</em>';
445 $html .= '<input type="hidden" name="fields[' . $key . '][admin_table]" value="' . $field['admin_table'] . '">';
446 }
447 $html .= '<span class="help inline">' . __( 'Show this field in the admin list table.', 'strong-testimonials' ) . '</span>';
448 $html .= '</label>';
449 $html .= '</td>' . "\n";
450 $html .= '</tr>' . "\n";
451
452 return $html;
453 }
454
455
456 /**
457 * Add hidden fields to form.
458 *
459 * @param $key
460 * @param $field
461 *
462 * @return string
463 */
464 function wpmtst_show_field_hidden( $key, $field ) {
465 $pattern = '<input type="hidden" name="fields[%s][%s]" value="%s">';
466
467 $html = sprintf( $pattern, $key, 'record_type', $field['record_type'] ) . "\n";
468 $html .= sprintf( $pattern, $key, 'input_type', $field['input_type'] ) . "\n";
469 if ( isset( $field['action_input'] ) ) {
470 $html .= sprintf( $pattern, $key, 'action_input', $field['action_input'] ) . "\n";
471 }
472 if ( isset( $field['action_output'] ) ) {
473 $html .= sprintf( $pattern, $key, 'action_output', $field['action_output'] ) . "\n";
474 }
475 $html .= sprintf( $pattern, $key, 'name_mutable', $field['name_mutable'] ) . "\n";
476 $html .= sprintf( $pattern, $key, 'show_text_option', $field['show_text_option'] ) . "\n";
477 $html .= sprintf( $pattern, $key, 'show_placeholder_option', $field['show_placeholder_option'] ) . "\n";
478 $html .= sprintf( $pattern, $key, 'show_default_options', $field['show_default_options'] ) . "\n";
479 $html .= sprintf( $pattern, $key, 'admin_table_option', $field['admin_table_option'] ) . "\n";
480 $html .= sprintf( $pattern, $key, 'show_admin_table_option', $field['show_admin_table_option'] ) . "\n";
481 $html .= sprintf( $pattern, $key, 'show_shortcode_options', $field['show_shortcode_options'] ) . "\n";
482
483 if ( isset( $field['map'] ) ) {
484 $html .= sprintf( $pattern, $key, 'map', $field['map'] ) . "\n";
485 }
486
487 if ( isset( $field['core'] ) ) {
488 $html .= sprintf( $pattern, $key, 'core', $field['core'] ) . "\n";
489 }
490
491 return $html;
492 }
493