PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 2.38
Strong Testimonials v2.38
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 7 years ago js 7 years ago menu 7 years ago partials 7 years ago scss 7 years ago settings 7 years ago admin-notices.php 7 years ago admin.php 7 years ago class-strong-testimonials-addons.php 7 years ago class-strong-testimonials-admin-category-list.php 7 years ago class-strong-testimonials-admin-list.php 7 years ago class-strong-testimonials-admin-scripts.php 7 years ago class-strong-testimonials-defaults.php 7 years ago class-strong-testimonials-exporter.php 7 years ago class-strong-testimonials-help.php 7 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-testimonials-upsell.php 7 years ago class-strong-views-list-table.php 7 years ago class-walker-strong-category-checklist.php 7 years ago class-walker-strong-form-category-checklist.php 7 years ago compat.php 7 years ago custom-fields-ajax.php 7 years ago custom-fields.php 7 years ago form-preview.php 7 years ago view-list-order.php 7 years ago views-ajax.php 7 years ago views-validate.php 7 years ago views.php 7 years ago
custom-fields.php
515 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_filter_post_kses( $field['text'] );
99 }
100 $field['before'] = sanitize_text_field( $field['before'] );
101 $field['after'] = sanitize_text_field( $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( esc_html__( 'You do not have sufficient permissions to access this page.', 'strong-testimonials' ) );
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
159 <div class="wrap wpmtst">
160 <h1 class="wp-heading-inline"><?php esc_html_e( 'Fields', 'strong-testimonials' ); ?></h1>
161 <hr class="wp-header-end">
162 <?php do_action( 'wpmtst_fields_editor_before_fields_intro' ); ?>
163
164 <div id="left-col">
165 <div>
166 <h3><?php esc_html_e( 'Editor', 'strong-testimonials' ); ?></h3>
167 <p>
168 <?php esc_html_e( 'Click a field to open its options panel.', 'strong-testimonials' ); ?>
169 <a class="open-help-tab" href="#tab-panel-wpmtst-help"><?php esc_html_e( 'Help', 'strong-testimonials' ); ?></a>
170 </p>
171 <?php do_action( 'wpmtst_before_fields_settings', 'form-fields' ); ?>
172 </div>
173
174 <form id="wpmtst-custom-fields-form" method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" autocomplete="off">
175 <?php wp_nonce_field( 'wpmtst_custom_fields_form', 'wpmtst_form_submitted' ); ?>
176 <input type="hidden" name="action" value="wpmtst_update_custom_fields">
177 <input type="hidden" name="form_id" value="<?php echo esc_attr( $form_id ); ?>">
178
179 <?php do_action( 'wpmtst_fields_editor_before_fields_editor', $forms[ $form_id ] ); ?>
180
181 <ul id="custom-field-list">
182 <?php
183 foreach ( $fields as $key => $field ) {
184 echo '<li id="field-' . esc_attr( $key ) . '">' . wpmtst_show_field( $key, $field, false ) . '</li>' . "\n";
185 }
186 ?>
187 </ul>
188
189 <div id="add-field-bar">
190 <input id="add-field" type="button" class="button" name="add-field" value="<?php esc_attr_e( 'Add New Field', 'strong-testimonials' ); ?>">
191 </div>
192
193 <?php do_action( 'wpmtst_admin_after_form_fields' ); ?>
194
195 <div id="field-group-actions">
196 <div><?php submit_button( '', 'primary', 'submit-form', false ); ?></div>
197 <div><?php submit_button( esc_html__( 'Cancel Changes', 'strong-testimonials' ), 'secondary', 'reset', false ); ?></div>
198 <div><?php submit_button( esc_html__( 'Restore Defaults', 'strong-testimonials' ), 'secondary', 'restore-defaults', false ); ?></div>
199 </div>
200 </form>
201 </div><!-- #left-col -->
202
203 <div id="right-col">
204 <div class="intro">
205 <h3><?php esc_html_e( 'Basic Preview', 'strong-testimonials' ); ?></h3>
206 <p><?php esc_html_e( 'Only to demonstrate the fields. May look different in your theme.', 'strong-testimonials' ); ?></p>
207 </div>
208 <div id="fields-editor-preview">
209 <div><!-- placeholder --></div>
210 </div>
211 </div><!-- #right-col -->
212
213 </div><!-- .wrap -->
214 <?php
215 }
216
217 /**
218 * Add a field to the form
219 *
220 * @param $key
221 * @param $field
222 * @param $adding
223 *
224 * @return string
225 */
226 function wpmtst_show_field( $key, $field, $adding ) {
227 $fields = apply_filters( 'wpmtst_fields', get_option( 'wpmtst_fields' ) );
228 $field_types = $fields['field_types'];
229
230 ob_start();
231
232 include 'partials/fields/field-header.php';
233 ?>
234 <div class="custom-field" style="display: none;">
235
236 <table class="field-table">
237 <?php
238 include 'partials/fields/field-type.php';
239 include 'partials/fields/field-label.php';
240 include 'partials/fields/field-name.php';
241
242 if ( ! $adding ) {
243 echo wpmtst_show_field_secondary( $key, $field );
244 echo wpmtst_show_field_admin_table( $key, $field );
245 }
246
247 ?>
248 </table>
249
250 <?php
251 if ( ! $adding ) {
252 echo wp_kses_post( wpmtst_show_field_hidden( $key, $field ) );
253 }
254 include 'partials/fields/field-controls.php';
255 ?>
256 </div><!-- .custom-field -->
257
258 <?php
259 $html = ob_get_contents();
260 ob_end_clean();
261
262 return $html;
263 }
264
265
266 /**
267 * Create the secondary inputs for a new custom field.
268 * Called after field type is chosen (Post or Custom).
269 *
270 * @param $key
271 * @param $field
272 *
273 * @return string
274 */
275 function wpmtst_show_field_secondary( $key, $field ) {
276 $html = '';
277
278 /*
279 * Required
280 */
281 if ( isset( $field['show_required_option'] ) && $field['show_required_option'] ) {
282 // Disable option if this is a core field like post_content.
283 if ( isset( $field['core'] ) && $field['core'] ) {
284 $disabled = ' disabled="disabled"';
285 } else {
286 $disabled = '';
287 }
288
289 $html .= '<tr class="field-secondary">' . "\n";
290 $html .= '<th>' . esc_html__( 'Required', 'strong-testimonials' ) . '</th>' . "\n";
291 $html .= '<td>' . "\n";
292 if ( $disabled ) {
293 $html .= '<input type="hidden" name="fields[' . esc_attr( $key ) . '][required]" value="' . esc_attr( $field['required'] ) . '">';
294 $html .= '<input type="checkbox" ' . checked( $field['required'], true, false ) . $disabled . '>';
295 } else {
296 $html .= '<input type="checkbox" name="fields[' . esc_attr( $key ) . '][required]" ' . checked( $field['required'], true, false ) . '>';
297 }
298 $html .= '</td>' . "\n";
299 $html .= '</tr>' . "\n";
300 }
301
302 /*
303 * Placeholder
304 */
305 if ( $field['show_placeholder_option'] ) {
306 if ( isset( $field['placeholder'] ) ) {
307 $html .= '<tr class="field-secondary">' . "\n";
308 $html .= '<th>' . esc_html__( 'Placeholder', 'strong-testimonials' ) . '</th>' . "\n";
309 $html .= '<td><input type="text" name="fields[' . esc_attr( $key ) . '][placeholder]" value="' . esc_attr( $field['placeholder'] ) . '"></td>' . "\n";
310 $html .= '</tr>' . "\n";
311 }
312 }
313
314 /**
315 * Text (checkbox, radio)
316 *
317 * @since 2.23.0
318 */
319 if ( $field['show_text_option'] ) {
320 if ( isset( $field['text'] ) ) {
321 $html .= '<tr class="field-secondary">' . "\n";
322 $html .= '<th>' . esc_html__( 'Text', 'strong-testimonials' ) . '</th>' . "\n";
323 $html .= '<td><input type="text" name="fields[' . esc_attr( $key ) . '][text]" value="' . esc_attr( $field['text'] ) . '" placeholder="' . esc_html__( 'next to the checkbox', 'strong-testimonials' ) . '"></td>' . "\n";
324 $html .= '</tr>' . "\n";
325 }
326 }
327
328 /*
329 * Before
330 */
331 $html .= '<tr class="field-secondary">' . "\n";
332 $html .= '<th>' . esc_html__( 'Before', 'strong-testimonials' ) . '</th>' . "\n";
333 $html .= '<td><input type="text" name="fields[' . esc_attr( $key ) . '][before]" value="' . esc_attr( $field['before'] ) . '"></td>' . "\n";
334 $html .= '</tr>' . "\n";
335
336 /*
337 * After
338 */
339 $html .= '<tr class="field-secondary">' . "\n";
340 $html .= '<th>' . esc_html__( 'After', 'strong-testimonials' ) . '</th>' . "\n";
341 $html .= '<td><input type="text" name="fields[' . esc_attr( $key ) . '][after]" value="' . esc_attr( $field['after'] ) . '"></td>' . "\n";
342 $html .= '</tr>' . "\n";
343
344 /*
345 * Default Form Value
346 */
347 if ( $field['show_default_options'] ) {
348 if ( isset( $field['default_form_value'] ) ) {
349 $html .= '<tr class="field-secondary">' . "\n";
350 $html .= '<th>' . esc_html__( 'Default Form Value', 'strong-testimonials' ) . '</th>' . "\n";
351 $html .= '<td>' . "\n";
352
353 // TODO Replace this special handling
354 if ( 'rating' == $field['input_type'] ) {
355
356 $html .= '<input type="text" name="fields[' . esc_attr( $key ) . '][default_form_value]" value="' . esc_attr( $field['default_form_value'] ) . '" class="as-number">';
357 $html .= '<span class="help inline">' . esc_html__( 'stars', 'strong-testimonials' ) . '</span>';
358 $html .= '<span class="help">' . esc_html__( 'Populate the field with this value.', 'strong-testimonials' ) . '</span>';
359
360 } elseif ( 'checkbox' == $field['input_type'] ) {
361
362 $html .= '<label>';
363 $html .= '<input type="checkbox" name="fields[' . esc_attr( $key ) . '][default_form_value]" ' . checked( $field['default_form_value'], true, false ) . '>';
364 $html .= '<span class="help inline">' . esc_html__( 'Checked by default.', 'strong-testimonials' ) . '</span>';
365 $html .= '</label>';
366
367 } else {
368
369 $html .= '<input type="text" name="fields[' . esc_attr( $key ) . '][default_form_value]" value="' . esc_attr( $field['default_form_value'] ) . '">';
370 $html .= '<span class="help">' . esc_html__( 'Populate the field with this value.', 'strong-testimonials' ) . '</span>';
371
372 }
373
374 $html .= '</td>' . "\n";
375 $html .= '</tr>' . "\n";
376 }
377 }
378
379 /*
380 * Default Display Value
381 */
382 if ( $field['show_default_options'] ) {
383 // TODO Replace this special handling for checkbox type
384 if ( 'checkbox' != $field['input_type'] ) {
385 if ( isset( $field['default_display_value'] ) ) {
386 $html .= '<tr class="field-secondary">' . "\n";
387 $html .= '<th>' . esc_html__( 'Default Display Value', 'strong-testimonials' ) . '</th>' . "\n";
388 $html .= '<td>' . "\n";
389
390 // TODO Replace this special handling
391 if ( 'rating' == $field['input_type'] ) {
392 $html .= '<input type="text" name="fields[' . esc_attr( $key ) . '][default_display_value]" value="' . esc_attr( $field['default_display_value'] ) . '" class="as-number">';
393 $html .= '<span class="help inline">' . esc_html__( 'stars', 'strong-testimonials' ) . '</span>';
394 } else {
395 $html .= '<input type="text" name="fields[' . esc_attr( $key ) . '][default_display_value]" value="' . esc_attr( $field['default_display_value'] ) . '">';
396 }
397
398 $html .= '<span class="help">' . esc_html__( 'Display this on the testimonial if no value is submitted.', 'strong-testimonials' ) . '</span>';
399 $html .= '</td>' . "\n";
400 $html .= '</tr>' . "\n";
401 }
402 }
403 }
404
405 /*
406 * Shortcode Options
407 */
408 if ( $field['show_shortcode_options'] ) {
409 if ( isset( $field['shortcode_on_form'] ) ) {
410 $html .= '<tr class="field-secondary">' . "\n";
411 $html .= '<th>' . esc_html__( 'Shortcode on form', 'strong-testimonials' ) . '</th>' . "\n";
412 $html .= '<td>' . "\n";
413 $html .= '<input type="text" name="fields[' . esc_attr( $key ) . '][shortcode_on_form]" value="' . esc_attr( $field['shortcode_on_form'] ) . '">';
414 $html .= '</td>' . "\n";
415 $html .= '</tr>' . "\n";
416 }
417 if ( isset( $field['shortcode_on_display'] ) ) {
418 $html .= '<tr class="field-secondary">' . "\n";
419 $html .= '<th>' . esc_html__( 'Shortcode on display', 'strong-testimonials' ) . '</th>' . "\n";
420 $html .= '<td>' . "\n";
421 $html .= '<input type="text" name="fields[' . esc_attr( $key ) . '][shortcode_on_display]" value="' . esc_attr( $field['shortcode_on_display'] ) . '">';
422 $html .= '</td>' . "\n";
423 $html .= '</tr>' . "\n";
424 }
425 }
426
427 $html = apply_filters( 'wpmtst_fields_secondary', $html, $key, $field );
428
429 return $html;
430 }
431
432
433 /**
434 * Add type-specific [Admin Table] setting to form.
435 */
436 function wpmtst_show_field_admin_table( $key, $field ) {
437 // -------------------
438 // Show in Admin Table
439 // -------------------
440 if ( ! $field['show_admin_table_option'] ) {
441 $html = '<input type="hidden" name="fields[' . esc_attr( $key ) . '][show_admin_table_option]" value="' . esc_attr( $field['show_admin_table_option'] ) . '">';
442 return $html;
443 }
444
445 $html = '<tr class="field-admin-table">' . "\n";
446 $html .= '<th>' . esc_html__( 'Admin List', 'strong-testimonials' ) . '</th>' . "\n";
447 $html .= '<td>' . "\n";
448 if ( $field['admin_table_option'] ) {
449 $html .= '<label><input type="checkbox" class="field-admin-table" name="fields[' . esc_attr( $key ) . '][admin_table]" ' . checked( $field['admin_table'], 1, false ) . '>';
450 } else {
451 $html .= '<input type="checkbox" ' . checked( $field['admin_table'], 1, false ) . ' disabled="disabled"> <em>' . esc_html__( 'required', 'strong-testimonials' ) . '</em>';
452 $html .= '<input type="hidden" name="fields[' . esc_attr( $key ) . '][admin_table]" value="' . esc_attr( $field['admin_table'] ) . '">';
453 }
454 $html .= '<span class="help inline">' . esc_html__( 'Show this field in the admin list table.', 'strong-testimonials' ) . '</span>';
455 $html .= '</label>';
456 $html .= '</td>' . "\n";
457 $html .= '</tr>' . "\n";
458
459 return $html;
460 }
461
462
463 /**
464 * Add type-specific select options field
465 */
466 function wpmtst_show_field_select_options( $key, $field ) {
467
468 if( $field['input_type'] !== 'select' ) {
469 return;
470 }
471
472 ob_start();
473 include 'partials/fields/field-select-options.php';
474 return ob_get_clean();
475 }
476
477
478 /**
479 * Add hidden fields to form.
480 *
481 * @param $key
482 * @param $field
483 *
484 * @return string
485 */
486 function wpmtst_show_field_hidden( $key, $field ) {
487 $pattern = '<input type="hidden" name="fields[%s][%s]" value="%s">';
488
489 $html = sprintf( $pattern, $key, 'record_type', $field['record_type'] ) . "\n";
490 $html .= sprintf( $pattern, $key, 'input_type', $field['input_type'] ) . "\n";
491 if ( isset( $field['action_input'] ) ) {
492 $html .= sprintf( $pattern, $key, 'action_input', $field['action_input'] ) . "\n";
493 }
494 if ( isset( $field['action_output'] ) ) {
495 $html .= sprintf( $pattern, $key, 'action_output', $field['action_output'] ) . "\n";
496 }
497 $html .= sprintf( $pattern, $key, 'name_mutable', $field['name_mutable'] ) . "\n";
498 $html .= sprintf( $pattern, $key, 'show_text_option', $field['show_text_option'] ) . "\n";
499 $html .= sprintf( $pattern, $key, 'show_placeholder_option', $field['show_placeholder_option'] ) . "\n";
500 $html .= sprintf( $pattern, $key, 'show_default_options', $field['show_default_options'] ) . "\n";
501 $html .= sprintf( $pattern, $key, 'admin_table_option', $field['admin_table_option'] ) . "\n";
502 $html .= sprintf( $pattern, $key, 'show_admin_table_option', $field['show_admin_table_option'] ) . "\n";
503 $html .= sprintf( $pattern, $key, 'show_shortcode_options', $field['show_shortcode_options'] ) . "\n";
504
505 if ( isset( $field['map'] ) ) {
506 $html .= sprintf( $pattern, $key, 'map', $field['map'] ) . "\n";
507 }
508
509 if ( isset( $field['core'] ) ) {
510 $html .= sprintf( $pattern, $key, 'core', $field['core'] ) . "\n";
511 }
512
513 return $html;
514 }
515