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