PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.8.3
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.8.3
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / admin / classes / class-merchant-admin-options.php

class-merchant-admin-options.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.8.3, at admin/classes/class-merchant-admin-options.php

1,636 lines 52.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Merchant_Admin_Options Class.
4 */
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly
8 }
9
10 if ( ! class_exists( 'Merchant_Admin_Options' ) ) {
11 class Merchant_Admin_Options {
12
13 /**
14 * The single class instance.
15 */
16 private static $instance = null;
17
18 /**
19 * Instance.
20 */
21 public static function instance() {
22 if ( is_null( self::$instance ) ) {
23 self::$instance = new self();
24 }
25
26 return self::$instance;
27 }
28
29 /**
30 * Constructor.
31 */
32 public function __construct() {
33 // Enqueue hooks.
34 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
35
36 // Ajax callbacks.
37 add_action( 'wp_ajax_merchant_create_page_control', array( $this, 'create_page_control_ajax_callback' ) );
38 add_action( 'wp_ajax_merchant_admin_options_select_ajax', array( $this, 'select_content_ajax' ) );
39 }
40
41 /**
42 * Enqueue scripts.
43 */
44 public function enqueue_scripts() {
45 if (
46 isset( $_GET['page'] ) && 'merchant' === $_GET['page'] // phpcs:ignore WordPress.Security.NonceVerification.Recommended
47 && isset( $_GET['module'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
48 ) {
49 wp_enqueue_script( 'merchant-select2', MERCHANT_URI . 'assets/vendor/select2/select2.full.min.js', array( 'jquery' ), '4.0.13', true );
50 wp_enqueue_style( 'merchant-select2', MERCHANT_URI . 'assets/vendor/select2/select2.min.css', array(), '4.0.13', 'all' );
51
52 wp_localize_script( 'merchant-select2', 'merchant_admin_options', array(
53 'ajaxurl' => admin_url( 'admin-ajax.php' ),
54 'ajaxnonce' => wp_create_nonce( 'merchant_admin_options' ),
55 ) );
56 }
57 }
58
59 /**
60 * Ajax callbacks.
61 */
62 public function create_page_control_ajax_callback() {
63 check_ajax_referer( 'customize-create-page-control-nonce', 'nonce' );
64
65 // Check current user capabilities
66 if ( ! current_user_can( 'manage_options' ) ) {
67 wp_send_json_error( 'You are not allowed to do this.' );
68 }
69
70 $page_title = isset( $_POST['page_title'] ) ? sanitize_text_field( $_POST['page_title'] ) : '';
71 $page_meta_key = isset( $_POST['page_meta_key'] ) ? sanitize_text_field( $_POST['page_meta_key'] ) : '';
72 $page_meta_value = isset( $_POST['page_meta_value'] ) ? sanitize_text_field( $_POST['page_meta_value'] ) : '';
73 $option_name = isset( $_POST['option_name'] ) ? sanitize_text_field( $_POST['option_name'] ) : '';
74
75 $meta_input = array();
76 if ( $page_meta_key && $page_meta_value ) {
77 $meta_input = array(
78 $page_meta_key => $page_meta_value,
79 );
80 }
81
82 $postarr = array(
83 'post_type' => 'page',
84 'post_status' => 'publish',
85 'post_title' => $page_title,
86 'post_content' => '',
87 'meta_input' => $meta_input,
88 );
89
90 $page_id = wp_insert_post( $postarr );
91
92 if ( ! is_wp_error( $page_id ) ) {
93 if ( $option_name ) {
94 update_option( $option_name, $page_id );
95 }
96
97 wp_send_json( array(
98 'status' => 'success',
99 'page_id' => $page_id,
100 ) );
101 } else {
102 wp_send_json( array(
103 'status' => 'error',
104 ) );
105 }
106 }
107
108 /**
109 * Select content ajax callback.
110 *
111 */
112 public function select_content_ajax() {
113 $term = ( isset( $_GET['term'] ) ) ? sanitize_text_field( wp_unslash( $_GET['term'] ) ) : '';
114 $nonce = ( isset( $_GET['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : '';
115 $source = ( isset( $_GET['source'] ) ) ? sanitize_text_field( wp_unslash( $_GET['source'] ) ) : '';
116
117 // Check current user capabilities
118 if ( ! current_user_can( 'manage_options' ) ) {
119 wp_send_json_error( 'You are not allowed to do this.' );
120 }
121
122 if ( ! empty( $term ) && ! empty( $source ) && ! empty( $nonce ) && wp_verify_nonce( $nonce, 'merchant_admin_options' ) ) {
123 $options = array();
124
125 switch ( $source ) {
126 case 'post':
127 case 'product':
128 $query = new WP_Query( array(
129 's' => $term,
130 'post_type' => $source,
131 'post_status' => 'publish',
132 'posts_per_page' => 25,
133 'order' => 'DESC',
134 ) );
135
136 if ( ! empty( $query->posts ) ) {
137 foreach ( $query->posts as $post ) {
138 $options[] = array(
139 'id' => $post->ID,
140 'text' => $post->post_title,
141 );
142 }
143 }
144
145 break;
146 }
147
148 wp_send_json_success( $options );
149 } else {
150 wp_send_json_error();
151 }
152 }
153
154 /**
155 * Get option.
156 */
157 public static function get( $module, $setting, $default_val ) {
158 $options = get_option( 'merchant', array() );
159
160 $value = $default_val;
161
162 if ( isset( $options[ $module ] ) && isset( $options[ $module ][ $setting ] ) ) {
163 $value = $options[ $module ][ $setting ];
164 }
165
166 return $value;
167 }
168
169 /**
170 * Get all options.
171 */
172 public static function get_all( $module ) {
173 $options = get_option( 'merchant', array() );
174 $value = array();
175
176 if ( isset( $options[ $module ] ) ) {
177 $value = $options[ $module ];
178 }
179
180 return $value;
181 }
182
183 /**
184 * Create options.
185 */
186 public static function create( $settings ) {
187 /**
188 * Hook: merchant_module_settings
189 *
190 * @since 1.0
191 */
192 $settings = apply_filters( 'merchant_module_settings', $settings );
193
194 self::save_options( $settings );
195
196 $options = get_option( 'merchant', array() );
197
198 ?>
199 <div class="merchant-module-page-settings">
200 <div class="merchant-module-page-setting-box">
201 <?php
202 if ( ! empty( $settings['title'] ) ) : ?>
203 <div class="merchant-module-page-setting-title">
204 <?php
205 echo esc_html( $settings['title'] ); ?>
206 <?php
207 if ( ! empty( $settings['subtitle'] ) ) : ?>
208 <div class="merchant-module-page-setting-subtitle"><?php
209 echo esc_html( $settings['subtitle'] ); ?></div>
210 <?php
211 endif; ?>
212 </div>
213 <?php
214 endif; ?>
215 <div class="merchant-module-page-setting-fields">
216 <?php
217
218 if ( ! empty( $settings['fields'] ) ) {
219 foreach ( $settings['fields'] as $field ) {
220 $value = null;
221
222 if ( isset( $field['default'] ) ) {
223 $value = $field['default'];
224 }
225
226 if ( isset( $field['id'] ) && isset( $options[ $settings['module'] ] ) && isset( $options[ $settings['module'] ][ $field['id'] ] ) ) {
227 $value = $options[ $settings['module'] ][ $field['id'] ];
228 }
229
230 $module_info = Merchant_Admin_Modules::get_module_info( $settings['module'] );
231 if ( ( $module_info && $module_info['pro'] ) && ! defined( 'MERCHANT_PRO_DIR' ) ) {
232 self::disabled_field( $field, $value );
233 } else {
234 self::field( $field, $value );
235 }
236 }
237 }
238
239 ?>
240 </div>
241 </div>
242 </div>
243 <?php
244 }
245
246 /**
247 * Save options.
248 */
249 public static function save_options( $settings ) {
250 $save = ( isset( $_POST['merchant_save'] ) ) ? sanitize_text_field( wp_unslash( $_POST['merchant_save'] ) ) : '';
251 $reset = ( isset( $_POST['merchant_reset'] ) ) ? sanitize_text_field( wp_unslash( $_POST['merchant_reset'] ) ) : '';
252 $nonce = ( isset( $_POST['merchant_nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['merchant_nonce'] ) ) : '';
253
254 if ( ! wp_verify_nonce( $nonce, 'merchant_nonce' ) ) {
255 return;
256 }
257
258 if ( ! current_user_can( 'manage_options' ) ) {
259 return;
260 }
261
262 $options = get_option( 'merchant', array() );
263
264 if ( ! empty( $save ) ) {
265 if ( ! empty( $settings['fields'] ) ) {
266 foreach ( $settings['fields'] as $field ) {
267 if ( ! isset( $field['id'] ) ) {
268 continue;
269 }
270
271 $value = null;
272
273 if ( isset( $_POST['merchant'] ) && isset( $_POST['merchant'][ $field['id'] ] ) ) {
274 if ( 'textarea_code' === $field['type'] ) {
275 $value = wp_kses( $_POST['merchant'][ $field['id'] ], merchant_kses_allowed_tags_for_code_snippets() );
276 } elseif ( 'textarea_multiline' === $field['type'] ) {
277 $value = sanitize_textarea_field( $_POST['merchant'][ $field['id'] ] );
278 } elseif ( is_array( $_POST['merchant'][ $field['id'] ] ) ) {
279 $value = array_filter( map_deep( wp_unslash( $_POST['merchant'][ $field['id'] ] ), 'sanitize_text_field' ) );
280 } else {
281 $value = sanitize_text_field( wp_unslash( $_POST['merchant'][ $field['id'] ] ) );
282 }
283 }
284
285
286 $options[ $settings['module'] ][ $field['id'] ] = self::sanitize( $field, $value );
287 }
288 }
289 } elseif ( ! empty( $reset ) ) {
290 $options[ $settings['module'] ] = array();
291 }
292
293 update_option( 'merchant', $options );
294 }
295
296 /**
297 * Sanitize options.
298 */
299 public static function sanitize( $field, $value ) {
300 // Callback for custom sanitize methods.
301 if ( ! empty( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) {
302 return call_user_func( $field['sanitize'], $value );
303 }
304
305 switch ( $field['type'] ) {
306 case 'text':
307 case 'color':
308 case 'number':
309 case 'select_size_chart':
310 $value = sanitize_text_field( $value );
311 break;
312
313 case 'textarea':
314 $value = sanitize_textarea_field( $value );
315 break;
316
317 case 'textarea_code':
318 $value = $value;
319 break;
320
321 case 'checkbox':
322 case 'switcher':
323 $value = ( '1' === $value ) ? 1 : 0;
324 break;
325
326 case 'range':
327 case 'number':
328 $value = absint( $value );
329 break;
330 case 'select_ajax':
331 if ( is_array( $value ) && ! empty( $value ) ) {
332 $value = array_filter( array_map( 'sanitize_text_field', $value ) );
333 } elseif ( is_string( $value ) ) {
334 $value = sanitize_text_field( $value );
335 } else {
336 $value = isset( $field['multiple'] ) && $field['multiple'] === false ? '' : array();
337 }
338 break;
339 case 'radio':
340 case 'radio_alt':
341 case 'select':
342 case 'choices':
343 case 'buttons':
344 case 'buttons_alt':
345 $value = ( in_array( $value, array_keys( $field['options'] ), true ) ) ? sanitize_key( $value ) : '';
346 break;
347
348 case 'hook_select':
349 $value = is_array( $value ) ? $value : array();
350
351 foreach ( $value as $key => $val ) {
352 if ( $key === 'hook_name' ) {
353 $value[ $key ] = in_array( $val, array_keys( $field['options'] ), true ) ? sanitize_key( $val ) : '';
354 } else {
355 $value[ $key ] = (int) $val;
356 }
357 }
358
359 break;
360
361 case 'code-editor':
362 $value = wp_kses_post( $value );
363 break;
364
365 case 'sortable':
366 $values = json_decode( $value );
367 $value = array();
368
369 foreach ( $values as $val ) {
370 if ( in_array( $val, array_keys( $field['options'] ), true ) ) {
371 $value[] = sanitize_key( $val );
372 }
373 }
374 break;
375 case 'dimensions':
376 $values = is_array( $value ) ? $value : array();
377
378 foreach ( $values as $key => $val ) {
379 if ( $key === 'unit' ) {
380 $value[ $key ] = sanitize_key( $value[ $key ] );
381 } else {
382 $value[ $key ] = absint( $value[ $key ] );
383 }
384 }
385 break;
386 case 'responsive_dimensions':
387 $values = is_array( $value ) ? $value : array();
388
389 foreach ( $values as $device => $device_fields ) {
390 foreach ( $device_fields as $device_field => $device_field_val ) {
391 if ( $device_field === 'unit' ) {
392 $value[ $device ][ $device_field ] = sanitize_key( $device_field_val );
393 } else {
394 $value[ $device ][ $device_field ] = absint( $device_field_val );
395 }
396 }
397 }
398 break;
399
400 case 'sortable_repeater':
401 $values = json_decode( $value );
402 $value = array_map( 'sanitize_text_field', $values );
403 break;
404 case 'flexible_content':
405 $value = ! is_array( $value ) || empty( $value ) ? array() : $value;
406
407 $value = array_map( function ( $sub_fields ) use ( $field ) {
408 foreach ( $sub_fields as $sub_field => $value ) {
409 if ( $sub_field === 'layout' ) {
410 $sub_fields[ $sub_field ] = sanitize_text_field( $value );
411 } else {
412 $layout_field = array_filter( $field['layouts'][ $sub_fields['layout'] ]['fields'], function ( $layout_field ) use ( $sub_field ) {
413 return $layout_field['id'] === $sub_field;
414 } );
415
416
417 $sub_fields[ $sub_field ] = self::sanitize( reset( $layout_field ), $value );
418 }
419 }
420
421 return $sub_fields;
422 }, $value );
423
424 break;
425 }
426
427 return $value;
428 }
429
430 /**
431 * Field
432 */
433 public static function field( $settings, $value ) {
434 if ( ! empty( $settings['type'] ) ) {
435 $type = $settings['type'];
436
437 $id = ( ! empty( $settings['id'] ) ) ? $settings['id'] : '';
438 $class = ( ! empty( $settings['class'] ) ) ? ' ' . $settings['class'] : '';
439 $condition = ( ! empty( $settings['condition'] ) ) ? $settings['condition'] : array();
440 $default = ( ! empty( $settings['default'] ) ) ? $settings['default'] : null;
441
442 if ( ! $value && 0 !== $value ) {
443 $value = $default;
444 }
445
446 echo '<div class="merchant-module-page-setting-field merchant-module-page-setting-field-' . esc_attr( $type ) . '' . esc_attr( $class ) . '" data-id="'
447 . esc_attr( $id ) . '" data-type="' . esc_attr( $type ) . '" data-condition="' . esc_attr( wp_json_encode( $condition ) ) . '">';
448 if ( ! empty( $settings['title'] ) ) {
449 printf( '<div class="merchant-module-page-setting-field-title">%s</div>', esc_html( $settings['title'] ) );
450 }
451
452 echo '<div class="merchant-module-page-setting-field-inner">';
453 if ( method_exists( 'Merchant_Admin_Options', $type ) ) {
454 call_user_func( array( 'Merchant_Admin_Options', $type ), $settings, $value );
455 } else {
456 esc_html_e( 'Field not found!', 'merchant' );
457 }
458 echo '</div>';
459
460 if ( ! empty( $settings['desc'] ) ) {
461 printf( '<div class="merchant-module-page-setting-field-desc">%s</div>', wp_kses_post( $settings['desc'] ) );
462 }
463
464 echo '</div>';
465 }
466 }
467
468 /**
469 * Disabled field
470 *
471 * @param array $settings
472 * @param mixed $value
473 *
474 * @return void
475 */
476 public static function disabled_field( $settings, $value ) {
477 static::replace_field(
478 $settings,
479 $value,
480 array(
481 '<input ',
482 '<select ',
483 'merchant-module-page-setting-field-inner',
484 ),
485 array(
486 '<input disabled ',
487 '<select disabled ',
488 'merchant-module-page-setting-field-inner disabled',
489 )
490 );
491 }
492
493 /**
494 * Modified field.
495 *
496 * @param $settings
497 * @param $value
498 * @param $search
499 * @param $replace
500 *
501 * @return void
502 */
503 public static function replace_field( $settings, $value, $search, $replace ) {
504 ob_start();
505 self::field( $settings, $value );
506 $field = ob_get_clean();
507
508 echo wp_kses( str_replace( $search, $replace, $field ), merchant_kses_allowed_tags( array( 'all' ) ) );
509 }
510
511 /**
512 * Field: Text
513 */
514 public static function text( $settings, $value ) {
515 ?>
516 <input type="text" name="merchant[<?php
517 echo esc_attr( $settings['id'] ); ?>]" value="<?php
518 echo esc_attr( $value ); ?>"/>
519 <?php
520 }
521
522 /**
523 * Field: Text (readonly)
524 */
525 public static function text_readonly( $settings, $value ) {
526 ?>
527 <input type="text" value="<?php
528 echo esc_attr( $value ); ?>" readonly/>
529 <?php
530 }
531
532 /**
533 * Field: Number
534 */
535 public static function number( $settings, $value ) {
536 ?>
537 <input type="number" name="merchant[<?php
538 echo esc_attr( $settings['id'] ); ?>]" value="<?php
539 echo esc_attr( $value ); ?>"/>
540 <?php
541 }
542
543 /**
544 * Field: Textarea
545 */
546 public static function textarea( $settings, $value ) {
547 $value = ( $value ) ? $value : '';
548 ?>
549 <textarea name="merchant[<?php
550 echo esc_attr( $settings['id'] ); ?>]"><?php
551 echo wp_kses_post( $value ); ?></textarea>
552 <?php
553 }
554
555 /**
556 * Field: Textarea
557 */
558 public static function textarea_multiline( $settings, $value ) {
559 $value = ( $value ) ? $value : '';
560 ?>
561 <textarea name="merchant[<?php
562 echo esc_attr( $settings['id'] ); ?>]"><?php
563 echo wp_kses_post( $value ); ?></textarea>
564 <?php
565 }
566
567 /**
568 * Field: Textarea Code Snippet.
569 */
570 public static function textarea_code( $settings, $value ) {
571 $value = ( $value ) ? $value : '';
572 ?>
573 <textarea name="merchant[<?php
574 echo esc_attr( $settings['id'] ); ?>]"><?php
575 echo wp_kses( $value, merchant_kses_allowed_tags_for_code_snippets() ); ?></textarea>
576 <?php
577 }
578
579 /**
580 * Field: Checkbox
581 */
582 public static function checkbox( $settings, $value ) {
583 ?>
584 <div>
585 <label>
586 <input type="checkbox" name="merchant[<?php
587 echo esc_attr( $settings['id'] ); ?>]" value="1" <?php
588 checked( $value, 1, true ); ?> />
589 <?php
590 if ( ! empty( $settings['label'] ) ) : ?>
591 <span><?php
592 echo esc_html( $settings['label'] ); ?></span>
593 <?php
594 endif; ?>
595 </label>
596 </div>
597 <?php
598 }
599
600 /**
601 * Field: Switcher
602 */
603 public static function switcher( $settings, $value ) {
604 ?>
605 <div class="merchant-toggle-switch">
606 <input type="checkbox" id="<?php
607 echo esc_attr( $settings['id'] ); ?>" name="merchant[<?php
608 echo esc_attr( $settings['id'] ); ?>]" value="1" <?php
609 checked( $value, 1, true ); ?>
610 class="toggle-switch-checkbox"/>
611 <label class="toggle-switch-label" for="<?php
612 echo esc_attr( $settings['id'] ); ?>">
613 <span class="toggle-switch-inner"></span>
614 <span class="toggle-switch-switch"></span>
615 </label>
616 <?php
617 if ( ! empty( $settings['label'] ) ) : ?>
618 <span><?php
619 echo esc_html( $settings['label'] ); ?></span>
620 <?php
621 endif; ?>
622 </div>
623 <?php
624 }
625
626 /**
627 * Field: Radio
628 */
629 public static function radio( $settings, $value ) {
630 ?>
631 <?php
632 if ( ! empty( $settings['options'] ) ) : ?>
633 <?php
634 foreach ( $settings['options'] as $key => $option ) : ?>
635 <label>
636 <input type="radio" name="merchant[<?php
637 echo esc_attr( $settings['id'] ); ?>]" value="<?php
638 echo esc_attr( $key ); ?>" <?php
639 checked( $value, $key, true ); ?>/>
640 <span><?php
641 echo esc_html( $option ); ?></span>
642 </label>
643 <?php
644 endforeach; ?>
645 <?php
646 endif; ?>
647 <?php
648 }
649
650 /**
651 * Field: Radio Alt
652 */
653 public static function radio_alt( $settings, $value ) {
654 ?>
655 <?php
656 if ( ! empty( $settings['options'] ) ) : ?>
657 <?php
658 foreach ( $settings['options'] as $key => $option ) : ?>
659 <div>
660 <label>
661 <input type="radio" name="merchant[<?php
662 echo esc_attr( $settings['id'] ); ?>]" value="<?php
663 echo esc_attr( $key ); ?>" <?php
664 checked( $value, $key, true ); ?>/>
665 <span><?php
666 echo esc_html( $option['title'] ); ?></span>
667 </label>
668 <p><?php
669 echo esc_html( $option['desc'] ); ?></p>
670 </div>
671 <?php
672 endforeach; ?>
673 <?php
674 endif; ?>
675 <?php
676 }
677
678 /**
679 * Field: Choices
680 */
681 public static function choices( $settings, $value ) {
682 ?>
683 <div class="merchant-choices merchant-choices-<?php
684 echo esc_attr( $settings['id'] ) ?>">
685 <?php
686 if ( ! empty( $settings['options'] ) ) : ?>
687 <?php
688 foreach ( $settings['options'] as $key => $option ) : ?>
689 <label>
690 <input type="radio" name="merchant[<?php
691 echo esc_attr( $settings['id'] ); ?>]" value="<?php
692 echo esc_attr( $key ); ?>" <?php
693 checked( $value, $key, true ); ?>/>
694 <?php
695 if ( ! empty( $option['svg'] ) ) : ?>
696 <span class="merchant-svg">
697 <?php
698 echo wp_kses( Merchant_SVG_Icons::get_svg_icon( $option['svg'] ), merchant_kses_allowed_tags( array(), false ) ); ?>
699
700 <?php
701 if ( ! empty( $option['label'] ) ) : ?>
702 <span class="merchant-tooltip"><?php
703 echo esc_html( $option['label'] ); ?></span>
704 <?php
705 endif; ?>
706 </span>
707 <?php
708 else : ?>
709 <figure>
710 <?php
711 if ( ! empty( $option['image'] ) ) : ?>
712 <img src="<?php
713 echo esc_url( sprintf( $option['image'], MERCHANT_URI . 'assets/images' ) ); ?>"/>
714 <?php
715 else : ?>
716 <img src="<?php
717 echo esc_url( sprintf( $option, MERCHANT_URI . 'assets/images' ) ); ?>"/>
718 <?php
719 endif; ?>
720 <?php
721 if ( ! empty( $option['label'] ) ) : ?>
722 <span class="merchant-tooltip"><?php
723 echo esc_html( $option['label'] ); ?></span>
724 <?php
725 endif; ?>
726 </figure>
727 <?php
728 endif; ?>
729 </label>
730 <?php
731 endforeach; ?>
732 <?php
733 endif; ?>
734 </div>
735 <?php
736 }
737
738 /**
739 * Field: Select
740 */
741 public static function select( $settings, $value ) {
742 ?>
743 <?php
744 if ( ! empty( $settings['options'] ) ) : ?>
745 <select name="merchant[<?php
746 echo esc_attr( $settings['id'] ); ?>]">
747 <?php
748 foreach ( $settings['options'] as $key => $option ) : ?>
749 <option value="<?php
750 echo esc_attr( $key ); ?>" <?php
751 selected( $value, $key, true ); ?>><?php
752 echo esc_html( $option ); ?></option>
753 <?php
754 endforeach; ?>
755 </select>
756 <?php
757 endif; ?>
758 <?php
759 }
760
761 /**
762 * Field: Hook Select
763 */
764 public static function hook_select( $settings, $value ) {
765 $hook_name = isset( $value['hook_name'] ) ? $value['hook_name'] : '';
766 $hook_priority = isset( $value['hook_priority'] ) ? $value['hook_priority'] : '';
767
768 ?>
769 <div class="merchant-module-page-setting-field-hook_select-wrapper">
770 <div class="merchant-module-page-setting-field-select">
771 <select name="merchant[<?php
772 echo esc_attr( $settings['id'] ); ?>][hook_name]">
773 <?php
774 if ( ! empty( $settings['options'] ) ) : ?>
775 <?php
776 foreach ( $settings['options'] as $key => $option ) : ?>
777 <option value="<?php
778 echo esc_attr( $key ); ?>" <?php
779 selected( $hook_name, $key, true ); ?>><?php
780 echo esc_html( $option ); ?></option>
781 <?php
782 endforeach; ?>
783 <?php
784 endif; ?>
785 </select>
786 </div>
787 <?php
788
789 if ( isset( $settings['order'] ) && true === $settings['order'] ) {
790 ?>
791 <div class="merchant-module-page-setting-field-number">
792 <input type="number" name="merchant[<?php
793 echo esc_attr( $settings['id'] ); ?>][hook_priority]" value="<?php
794 echo esc_attr( $hook_priority ); ?>"/>
795 </div>
796 <?php
797 } ?>
798 </div>
799
800 <?php
801 }
802
803 /**
804 * Field: Select ajax
805 *
806 * @param $settings
807 * @param $value
808 *
809 * @return void
810 */
811 public static function select_ajax( $settings, $value ) {
812 $settings = wp_parse_args( $settings, array(
813 'source' => 'post',
814 ) );
815
816 $ids = ( is_array( $value ) && ! empty( $value ) ) ? $value : (array) $value;
817
818 if ( isset( $settings['multiple'] ) ) {
819 $multiple = $settings['multiple'] === true ? 'multiple' : '';
820 } else {
821 $multiple = 'multiple';
822 }
823
824 $placeholder = $settings['placeholder'] ?? '';
825 ?>
826 <select
827 name="merchant[<?php echo esc_attr( $settings['id'] ); ?>]<?php echo esc_attr( $multiple ? '[]' : '' ); ?>"
828 <?php echo esc_attr( $multiple ); ?>
829 data-source="<?php echo esc_attr( $settings['source'] ); ?>"
830 data-placeholder="<?php echo esc_attr( $placeholder ); ?>">
831 <?php
832 if ( ! empty( $ids ) ) {
833 foreach ( $ids as $id ) {
834 switch ( $settings['source'] ) {
835 case 'post':
836 case 'product':
837 $post = get_post( $id );
838
839 if ( ! empty( $post ) ) {
840 echo '<option value="' . esc_attr( $post->ID ) . '" selected>' . esc_html( $post->post_title ) . '</option>';
841 }
842 break;
843 case 'options':
844 }
845 }
846 }
847 if ( $settings['source'] === 'options' ) {
848 $value = ! empty( $value ) ? $value : '';
849
850 foreach ( $settings['options'] as $option ) {
851 if ( isset( $option['options'] ) ) {
852 echo '<optgroup label="' . esc_attr( $option['text'] ) . '">';
853
854 foreach ( $option['options'] as $child_option ) {
855 $selected_value = is_array( $value ) ? in_array( $child_option['id'], $value, true ) : $child_option['id'];
856 echo '<option value="' . esc_attr( $child_option['id'] ) . '" ' . selected( $selected_value, is_array( $value ) ? true : $value ) . '>' . esc_html( $child_option['text'] )
857 . '</option>';
858 }
859
860 echo '</optgroup>';
861 } else {
862 $selected_value = is_array( $value ) ? in_array( $option['id'], $value, true ) : $option['id'];
863 echo '<option value="' . esc_attr( $option['id'] ) . '" ' . selected( $selected_value, is_array( $value ) ? true : $value ) . '>' . esc_html( $option['text'] ) . '</option>';
864 }
865 }
866 } ?>
867 </select>
868 <?php
869 }
870
871 /**
872 * Field: Select Size Chart
873 */
874 public static function select_size_chart( $settings, $value ) {
875 $options = array(
876 '' => esc_html__( 'Default', 'merchant' ),
877 );
878
879 $posts = get_posts( array(
880 'post_type' => 'merchant_size_chart',
881 'posts_per_page' => - 1,
882 'post_status' => 'publish',
883 ) );
884
885 if ( ! is_wp_error( $posts ) && ! empty( $posts ) ) {
886 foreach ( $posts as $_post ) {
887 $options[ $_post->ID ] = $_post->post_title;
888 }
889 }
890
891 ?>
892 <?php
893 if ( ! empty( $options ) ) : ?>
894 <select name="merchant[<?php
895 echo esc_attr( $settings['id'] ); ?>]">
896 <?php
897 foreach ( $options as $key => $option ) : ?>
898 <option value="<?php
899 echo esc_attr( $key ); ?>" <?php
900 selected( $value, $key, true ); ?>><?php
901 echo esc_html( $option ); ?></option>
902 <?php
903 endforeach; ?>
904 </select>
905 <?php
906 endif; ?>
907 <?php
908 }
909
910 /**
911 * Field: Buttons
912 */
913 public static function buttons( $settings, $value ) {
914 ?>
915 <div class="merchant-buttons">
916 <?php
917 if ( ! empty( $settings['options'] ) ) : ?>
918 <?php
919 foreach ( $settings['options'] as $key => $option ) : ?>
920 <label class="merchant-button-<?php
921 echo esc_attr( $key ); ?>"">
922 <input type="radio" name="merchant[<?php
923 echo esc_attr( $settings['id'] ); ?>]" value="<?php
924 echo esc_attr( $key ); ?>" <?php
925 checked( $value, $key, true ); ?>/>
926 <span><?php
927 echo esc_html( $option ); ?></span>
928 </label>
929 <?php
930 endforeach; ?>
931 <?php
932 endif; ?>
933 </div>
934 <?php
935 }
936
937 /**
938 * Field: Buttons Alt
939 */
940 public static function buttons_alt( $settings, $value ) {
941 ?>
942 <div class="merchant-buttons">
943 <?php
944 if ( ! empty( $settings['options'] ) ) : ?>
945 <?php
946 foreach ( $settings['options'] as $key => $option ) : ?>
947 <label class="merchant-button-<?php
948 echo esc_attr( $key ); ?>">
949 <input type="radio" name="merchant[<?php
950 echo esc_attr( $settings['id'] ); ?>]" value="<?php
951 echo esc_attr( $key ); ?>" <?php
952 checked( $value, $key, true ); ?>/>
953 <span><?php
954 echo esc_html( $option ); ?></span>
955 </label>
956 <?php
957 endforeach; ?>
958 <?php
959 endif; ?>
960 </div>
961 <?php
962 }
963
964 /**
965 * Field: Range
966 */
967 public static function range( $settings, $value ) {
968 $settings = wp_parse_args( $settings, array(
969 'min' => '',
970 'max' => '',
971 'step' => '',
972 'unit' => '',
973 ) );
974
975 ?>
976 <div class="merchant-range">
977 <input type="range" class="merchant-range-input" name="" min="<?php
978 echo esc_attr( $settings['min'] ); ?>" max="<?php
979 echo esc_attr( $settings['max'] ); ?>"
980 step="<?php
981 echo esc_attr( $settings['step'] ); ?>" value="<?php
982 echo esc_attr( $value ); ?>"/>
983 <input type="number" class="merchant-range-number-input" name="merchant[<?php
984 echo esc_attr( $settings['id'] ); ?>]" min="<?php
985 echo esc_attr( $settings['min'] ); ?>"
986 max="<?php
987 echo esc_attr( $settings['max'] ); ?>" step="<?php
988 echo esc_attr( $settings['step'] ); ?>" value="<?php
989 echo esc_attr( $value ); ?>"/>
990 <?php
991 if ( ! empty( $settings['unit'] ) ) : ?>
992 <span class="merchant-range-unit"><?php
993 echo esc_html( $settings['unit'] ); ?></span>
994 <?php
995 endif; ?>
996 </div>
997 <?php
998 }
999
1000 /**
1001 * Field: Color
1002 */
1003 public static function color( $settings, $value ) {
1004 $settings = wp_parse_args( $settings, array(
1005 'default' => '#212121',
1006 ) );
1007
1008 ?>
1009 <div class="merchant-color">
1010 <div class="merchant-color-picker" data-default-color="<?php
1011 echo esc_attr( $settings['default'] ); ?>" style="background-color: <?php
1012 echo esc_attr( $value ); ?>;"></div>
1013 <input type="text" class="merchant-color-input" name="merchant[<?php
1014 echo esc_attr( $settings['id'] ); ?>]" value="<?php
1015 echo esc_attr( $value ); ?>"/>
1016 </div>
1017 <?php
1018 }
1019
1020 /**
1021 * Field: Gallery
1022 */
1023 public static function gallery( $settings, $value ) {
1024 $settings = wp_parse_args( $settings, array(
1025 'label' => esc_html__( 'Select Images', 'merchant' ),
1026 ) );
1027
1028 $images = ( ! empty( $value ) ) ? explode( ',', $value ) : array();
1029
1030
1031 echo '<div class="merchant-gallery-images">';
1032
1033 if ( ! empty( $images ) ) :
1034
1035 foreach ( $images as $image_id ) :
1036
1037 $image = wp_get_attachment_image_src( $image_id, 'thumbnail' );
1038
1039 if ( ! empty( $image ) && ! empty( $image[0] ) ) :
1040
1041 printf( '<div class="merchant-gallery-image" data-item-id="%s">', esc_attr( $image_id ) );
1042
1043 echo '<i class="merchant-gallery-remove dashicons dashicons-no-alt"></i>';
1044
1045 printf( '<img src="%s" />', esc_url( $image[0] ) );
1046
1047 echo '</div>';
1048
1049 endif;
1050
1051 endforeach;
1052
1053 endif;
1054
1055 echo '</div>';
1056
1057 ?>
1058 <a href="#" class="merchant-gallery-button"><?php
1059 echo esc_html( $settings['label'] ); ?></a>
1060 <input type="hidden" class="merchant-gallery-input" name="merchant[<?php
1061 echo esc_attr( $settings['id'] ); ?>]" value="<?php
1062 echo esc_attr( $value ); ?>"/>
1063 <?php
1064 }
1065
1066 /**
1067 * Field: Upload
1068 */
1069 public static function upload( $settings, $value ) {
1070 $settings = wp_parse_args( $settings, array(
1071 'label' => esc_html__( 'Select Image', 'merchant' ),
1072 ) );
1073
1074 echo '<div class="merchant-upload-wrapper">';
1075
1076 if ( ! empty( $value ) ) :
1077
1078 $image = wp_get_attachment_image_src( $value, 'thumbnail' );
1079
1080 if ( ! empty( $image ) && ! empty( $image[0] ) ) :
1081
1082 echo '<div class="merchant-upload-image">';
1083 echo '<i class="merchant-upload-remove dashicons dashicons-no-alt"></i>';
1084 printf( '<img src="%s" />', esc_url( $image[0] ) );
1085 echo '</div>';
1086
1087 endif;
1088
1089 endif;
1090
1091 echo '</div>';
1092
1093 ?>
1094 <a href="#" class="merchant-upload-button"><?php
1095 echo esc_html( $settings['label'] ); ?></a>
1096 <input type="hidden" class="merchant-upload-input" name="merchant[<?php
1097 echo esc_attr( $settings['id'] ); ?>]" value="<?php
1098 echo esc_attr( $value ); ?>"/>
1099 <?php
1100 }
1101
1102 /**
1103 * Field: Warning
1104 */
1105 public static function warning( $settings ) {
1106 echo wp_kses_post( $settings['content'] );
1107 }
1108
1109 /**
1110 * Field: Warning
1111 */
1112 public static function info( $settings ) {
1113 echo wp_kses_post( $settings['content'] );
1114 }
1115
1116 /**
1117 * Field: Divider
1118 */
1119 public static function divider() {
1120 }
1121
1122 /**
1123 * Field: Content
1124 */
1125 public static function content( $settings ) {
1126 echo wp_kses_post( $settings['content'] );
1127 }
1128
1129 /**
1130 * Field: Sortable
1131 */
1132 public static function sortable( $settings, $value ) {
1133 ?>
1134 <div class="merchant-sortable">
1135 <ul class="merchant-sortable-list ui-sortable">
1136 <?php
1137 foreach ( $value as $option_key ) :
1138 $option_val = $settings['options'][ $option_key ];
1139
1140 if ( in_array( $option_key, $value, true ) ) :
1141 ?>
1142 <li class="merchant-sortable-item" data-value="<?php
1143 echo esc_attr( $option_key ); ?>">
1144 <i class='dashicons dashicons-menu'></i>
1145 <i class="dashicons dashicons-visibility visibility"></i>
1146 <?php
1147 echo esc_html( $option_val ); ?>
1148 </li>
1149 <?php
1150 endif; ?>
1151 <?php
1152 endforeach; ?>
1153
1154 <?php
1155 foreach ( $settings['options'] as $option_key => $option_val ) :
1156 if ( ! in_array( $option_key, $value, true ) ) :
1157 $invisible = ! in_array( $option_key, $value, true ) ? ' invisible' : '';
1158
1159 ?>
1160 <li class="merchant-sortable-item<?php
1161 echo esc_attr( $invisible ); ?>" data-value="<?php
1162 echo esc_attr( $option_key ); ?>">
1163 <i class='dashicons dashicons-menu'></i>
1164 <i class="dashicons dashicons-visibility visibility"></i>
1165 <?php
1166 echo esc_html( $option_val ); ?>
1167 </li>
1168 <?php
1169 endif; ?>
1170 <?php
1171 endforeach; ?>
1172 </ul>
1173
1174 <input class="merchant-sortable-input" type="hidden" name="merchant[<?php
1175 echo esc_attr( $settings['id'] ); ?>]" value="<?php
1176 echo esc_attr( wp_json_encode( $value ) ); ?>"/>
1177 </div>
1178 <?php
1179 }
1180
1181 /**
1182 * Field: Sortable Repeater.
1183 */
1184 public static function sortable_repeater( $settings, $value ) {
1185 ?>
1186 <div class="merchant-sortable-repeater-control<?php
1187 echo isset( $settings['sorting'] ) && false === $settings['sorting'] ? ' disable-sorting' : ''; ?>">
1188 <div class="merchant-sortable-repeater sortable regular-field">
1189 <div class="repeater">
1190 <input type="text" value="" class="repeater-input"/><span class="dashicons dashicons-menu"></span><a class="customize-control-sortable-repeater-delete"
1191 href="#"><span
1192 class="dashicons dashicons-no-alt"></span></a>
1193 </div>
1194 </div>
1195 <button class="button customize-control-sortable-repeater-add" type="button"><?php
1196 echo esc_html( $settings['button_label'] ); ?></button>
1197 <input class="merchant-sortable-repeater-input" type="hidden" name="merchant[<?php
1198 echo esc_attr( $settings['id'] ); ?>]" value="<?php
1199 echo esc_attr( wp_json_encode( $value ) ); ?>"/>
1200 </div>
1201 <?php
1202 }
1203
1204 /**
1205 * Field: Flexible Content.
1206 *
1207 * @param array $settings
1208 * @param mixed $value
1209 *
1210 * @return void
1211 */
1212 public static function flexible_content( $settings, $value ) {
1213 $values = ( is_array( $value ) && ! empty( $value ) ) ? $value : array();
1214 $empty = empty( $values ) ? 'empty' : '';
1215
1216 $settings = wp_parse_args( $settings, array(
1217 'sorting' => false,
1218 'style' => 'default',
1219 ) );
1220
1221 $classes = array(
1222 'merchant-flexible-content-control',
1223 "{$settings['style']}-style",
1224 );
1225
1226 if ( $settings['sorting'] === false ) {
1227 $classes[] = 'disable-sorting';
1228 }
1229 ?>
1230 <div class="<?php
1231 echo esc_attr( implode( ' ', $classes ) ); ?>"
1232 data-id="<?php
1233 echo esc_attr( $settings['id'] ) ?>">
1234
1235 <div class="layouts" data-id="<?php
1236 echo esc_attr( $settings['id'] ) ?>">
1237
1238 <?php
1239 foreach ( $settings['layouts'] as $layout_type => $layout ) : ?>
1240
1241 <div class="layout" data-type="<?php
1242 echo esc_attr( $layout_type ) ?>">
1243 <div class="layout-header">
1244 <div class="layout-count">1</div>
1245 <div class="layout-title">
1246 <?php
1247 echo esc_html( $layout['title'] ) ?>
1248 </div>
1249 <div class="layout-actions">
1250 <span class="customize-control-flexible-content-move dashicons dashicons-menu"></span>
1251 <a class="customize-control-flexible-content-delete" href="#">
1252 <span class="dashicons dashicons-no-alt"></span>
1253 </a>
1254 </div>
1255 </div>
1256 <div class="layout-body">
1257 <?php
1258 foreach ( $layout['fields'] as $sub_field ) :
1259 $classes = array( 'layout-field' );
1260
1261 if ( isset( $sub_field['classes'] ) ) {
1262 $classes = array_merge( $classes, $sub_field['classes'] );
1263 } ?>
1264 <div class="<?php
1265 echo esc_attr( implode( ' ', $classes ) ); ?>">
1266 <?php
1267 static::replace_field( $sub_field,
1268 '',
1269 array(
1270 "name=\"merchant[{$sub_field['id']}]",
1271 'merchant-module-page-setting-field-upload',
1272 'merchant-module-page-setting-field-select_ajax',
1273 ),
1274 array(
1275 "data-name=\"merchant[{$settings['id']}][0][{$sub_field['id']}]",
1276 'merchant-module-page-setting-field-upload template',
1277 'merchant-module-page-setting-field-select_ajax template',
1278 ) ) ?>
1279 </div>
1280 <?php
1281 endforeach; ?>
1282 <input type="hidden" data-name="merchant[<?php
1283 echo esc_attr( $settings['id'] ) ?>][0][layout]" value="<?php
1284 echo esc_attr( $layout_type ) ?>">
1285 </div>
1286 </div>
1287
1288 <?php
1289 endforeach; ?>
1290
1291 </div>
1292
1293 <div class="merchant-flexible-content <?php
1294 echo esc_attr( $empty ); ?> sortable">
1295
1296 <?php
1297 foreach ( $values as $option_key => $option ) : ?>
1298 <div class="layout" data-type="<?php
1299 echo esc_attr( $option['layout'] ) ?>">
1300 <div class="layout-header">
1301 <div class="layout-count"><?php
1302 echo absint( $option_key + 1 ) ?></div>
1303 <div class="layout-title">
1304 <?php
1305 echo esc_html( $settings['layouts'][ $option['layout'] ]['title'] ) ?>
1306 </div>
1307 <div class="layout-actions">
1308 <span class="customize-control-flexible-content-move dashicons dashicons-menu"></span>
1309 <a class="customize-control-flexible-content-delete" href="#">
1310 <span class="dashicons dashicons-no-alt"></span>
1311 </a>
1312 </div>
1313 </div>
1314 <div class="layout-body">
1315 <?php
1316 foreach ( $settings['layouts'][ $option['layout'] ]['fields'] as $sub_field ) :
1317 $classes = array( 'layout-field' );
1318 if ( isset( $sub_field['classes'] ) ) {
1319 $classes = array_merge( $classes, $sub_field['classes'] );
1320 } ?>
1321 <div class="<?php
1322 echo esc_attr( implode( ' ', $classes ) ) ?>">
1323 <?php
1324 $value = null;
1325 if ( isset( $option[ $sub_field['id'] ] ) ) {
1326 $value = $option[ $sub_field['id'] ];
1327 } elseif ( isset( $sub_field['default'] ) ) {
1328 $value = $sub_field['default'];
1329 }
1330 static::replace_field( $sub_field,
1331 $value,
1332 "name=\"merchant[{$sub_field['id']}]",
1333 "name=\"merchant[{$settings['id']}][{$option_key}][{$sub_field['id']}]" ) ?>
1334 </div>
1335 <?php
1336 endforeach; ?>
1337 <input type="hidden" name="merchant[<?php
1338 echo esc_attr( $settings['id'] ) ?>][<?php
1339 echo absint( $option_key ) ?>][layout]"
1340 value="<?php
1341 echo esc_attr( $option['layout'] ) ?>">
1342 </div>
1343 </div>
1344
1345 <?php
1346 endforeach; ?>
1347
1348 </div>
1349
1350 <div class="customize-control-flexible-content-add-wrapper">
1351 <div class="customize-control-flexible-content-add-list">
1352 <?php
1353 foreach ( $settings['layouts'] as $layout_type => $layout ) : ?>
1354 <a href="#"
1355 class="customize-control-flexible-content-add"
1356 data-id="<?php
1357 echo esc_attr( $settings['id'] ) ?>"
1358 data-layout="<?php
1359 echo esc_attr( $layout_type ) ?>">
1360 <?php
1361 echo esc_attr( $layout['title'] ) ?>
1362 </a>
1363 <?php
1364 endforeach; ?>
1365 </div>
1366 <button class="button customize-control-flexible-content-add-button" type="button"><?php
1367 echo esc_html( $settings['button_label'] ); ?></button>
1368 </div>
1369 </div>
1370 <?php
1371 }
1372
1373 /**
1374 * Field: Create Page.
1375 */
1376 public static function create_page( $settings, $value ) {
1377 $page_id = get_option( $settings['option_name'] );
1378
1379 echo '<div class="merchant-create-page-control">';
1380
1381 if ( $page_id && post_exists( get_the_title( $page_id ) ) && 'publish' === get_post_status( $page_id ) ) {
1382 echo wp_kses_post(
1383 sprintf( /* translators: 1: link to edit page */
1384 __( '<p class="merchant-module-page-setting-field-desc mrc-mt-0">Your page is created!</p><p class="merchant-module-page-setting-field-desc">Click <a href="%1$s" target="_blank">here</a> if you want to edit the page.</p><p class="merchant-module-page-setting-field-desc mrc-mb-0">To display the page in your theme header area, assign the page to the primary menu by clicking <a href="%2$s" target="_blank">here</a></p>',
1385 'merchant' ),
1386 get_admin_url() . 'post.php?post=' . $page_id . '&action=edit',
1387 get_admin_url() . 'nav-menus.php'
1388 )
1389 );
1390 } else {
1391 echo '<div class="merchant-create-page-control-create-message">';
1392 echo wp_kses_post(
1393 '<p class="merchant-module-page-setting-field-desc mrc-mt-0">'.
1394 sprintf( /* translators: 1: page name */
1395 __( 'It looks like you haven\'t created a <strong>%1$s</strong> page yet. Click the below button to create the page.',
1396 'merchant' ),
1397 $settings['page_title']
1398 ). '</p>'
1399 );
1400 echo '</div>';
1401 echo '<div class="merchant-create-page-control-success-message" style="display: none;">';
1402 echo wp_kses_post(
1403 sprintf( /* translators: 1: link to edit page */
1404 __( '<p class="merchant-module-page-setting-field-desc">Page created with success!</p><p class="merchant-module-page-setting-field-desc">Click <a href="%1$s" target="_blank">here</a> if you want to edit the page.</p><p class="merchant-module-page-setting-field-desc mrc-mb-0">To display the page in your theme header area, assign the page to the primary menu by clicking <a href="%2$s" target="_blank">here</a></p>',
1405 'merchant' ),
1406 get_admin_url() . 'post.php?post=&action=edit',
1407 get_admin_url() . 'nav-menus.php'
1408 )
1409 );
1410 echo '</div>';
1411 echo wp_kses_post(
1412 sprintf( /* translators: 1: page title, 2: page meta key, 3: page meta value, 4: option name, 5: nonce, 6: loading text, 7: success text */
1413 __( '<a href="#" class="merchant-create-page-control-button button-tertiary" data-page-title="%2$s" data-page-meta-key="%3$s" data-page-meta-value="%4$s" data-option-name="%5$s" data-nonce="%6$s" data-creating-text="%7$s" data-created-text="%8$s">%1$s</a>',
1414 'merchant' ),
1415 __( 'Create Page', 'merchant' ),
1416 $settings['page_title'],
1417 $settings['page_meta_key'],
1418 $settings['page_meta_value'],
1419 $settings['option_name'],
1420 wp_create_nonce( 'customize-create-page-control-nonce' ),
1421 __( 'Creating...', 'merchant' ),
1422 __( 'Created!', 'merchant' )
1423 )
1424 );
1425 }
1426
1427 echo '</div>';
1428 }
1429
1430 public static function dimensions( $settings, $value ) {
1431 $settings = wp_parse_args( $settings, array(
1432 'units' => array(
1433 'px' => 'px',
1434 'rem' => 'rem',
1435 'em' => 'em',
1436 'vw' => 'vw',
1437 'vh' => 'vh',
1438 '%' => '%',
1439 ),
1440 'dimensions' => array(
1441 'top',
1442 'right',
1443 'bottom',
1444 'left',
1445 ),
1446 ) );
1447 $default_value = array(
1448 'unit' => reset( $settings['units'] ),
1449 );
1450 foreach ( $settings['dimensions'] as $dimension ) {
1451 $default_value[ $dimension ] = 0;
1452 }
1453 $value = wp_parse_args( $value, $default_value );
1454 ?>
1455 <div class="merchant-module-page-settings-unit">
1456 <select name="merchant[<?php
1457 echo esc_attr( $settings['id'] ); ?>][unit]">
1458 <?php
1459 foreach ( $settings['units'] as $key => $option ) : ?>
1460 <option value="<?php
1461 echo esc_attr( $key ); ?>" <?php
1462 selected( $value['unit'], $key, true ); ?>><?php
1463 echo esc_html( $option ); ?></option>
1464 <?php
1465 endforeach; ?>
1466 </select>
1467 </div>
1468 <div class="merchant-module-page-settings-dimensions">
1469 <?php
1470 foreach ( $settings['dimensions'] as $dimension ) : ?>
1471 <div>
1472 <input id="merchant-<?php
1473 echo esc_attr( $settings['id'] ); ?>-<?php
1474 echo esc_attr( $dimension ) ?>"
1475 type="number"
1476 name="merchant[<?php
1477 echo esc_attr( $settings['id'] ); ?>][<?php
1478 echo esc_attr( $dimension ) ?>]"
1479 value="<?php
1480 echo esc_attr( $value[ $dimension ] ); ?>"/>
1481 <label for="merchant-<?php
1482 echo esc_attr( $settings['id'] ); ?>-<?php
1483 echo esc_attr( $dimension ) ?>">
1484 <?php
1485 echo esc_html( ucfirst( $dimension ) ); ?>
1486 </label>
1487 </div>
1488 <?php
1489 endforeach; ?>
1490 </div>
1491 <?php
1492 }
1493
1494 public static function responsive_dimensions( $settings, $value ) {
1495 $settings = wp_parse_args( $settings, array(
1496 'units' => array(
1497 'px' => 'px',
1498 'rem' => 'rem',
1499 'em' => 'em',
1500 'vw' => 'vw',
1501 'vh' => 'vh',
1502 '%' => '%',
1503 ),
1504 'dimensions' => array(
1505 'top',
1506 'right',
1507 'bottom',
1508 'left',
1509 ),
1510 'devices' => array(
1511 'desktop' => 'dashicons-desktop',
1512 'tablet' => 'dashicons-tablet',
1513 'mobile' => 'dashicons-smartphone',
1514 ),
1515 ) );
1516 $default_values = array();
1517 foreach ( $settings['devices'] as $device => $icon ) {
1518 $default_values[ $device ]['unit'] = reset( $settings['units'] );
1519
1520 foreach ( $settings['dimensions'] as $dimension ) {
1521 $default_values[ $device ][ $dimension ] = 0;
1522 }
1523 }
1524 $value = wp_parse_args( $value, $default_values );
1525 ?>
1526 <div class="merchant-module-page-settings-responsive">
1527 <ul class="merchant-module-page-settings-devices">
1528 <?php
1529 foreach ( $settings['devices'] as $device => $icon ) : ?>
1530 <li class="<?php
1531 echo esc_attr( $device ); ?>">
1532 <button type="button" class="preview-<?php
1533 echo esc_attr( $device ); ?> <?php
1534 echo $device === key( $settings['devices'] ) ? 'active' : '' ?>"
1535 data-device="<?php
1536 echo esc_attr( $device ); ?>">
1537 <i class="dashicons <?php
1538 echo esc_attr( $icon ); ?>"></i>
1539 </button>
1540 </li>
1541 <?php
1542 endforeach; ?>
1543 </ul>
1544 <?php
1545 foreach ( $settings['devices'] as $device => $icon ) : ?>
1546 <div class="merchant-module-page-settings-device-container <?php
1547 echo $device === key( $settings['devices'] ) ? 'active' : '' ?>" data-device="<?php
1548 echo esc_attr( $device ); ?>">
1549 <div class="merchant-module-page-settings-unit">
1550 <select name="merchant[<?php
1551 echo esc_attr( $settings['id'] ); ?>][<?php
1552 echo esc_attr( $device ) ?>][unit]">
1553 <?php
1554 foreach ( $settings['units'] as $key => $option ) : ?>
1555 <option value="<?php
1556 echo esc_attr( $key ); ?>" <?php
1557 selected( $value[ esc_attr( $device ) ]['unit'], $key, true ); ?>><?php
1558 echo esc_html( $option ); ?></option>
1559 <?php
1560 endforeach; ?>
1561 </select>
1562 </div>
1563 <div class="merchant-module-page-settings-dimensions">
1564 <?php
1565 foreach ( $settings['dimensions'] as $dimension ) : ?>
1566 <div>
1567 <input id="merchant-<?php
1568 echo esc_attr( $settings['id'] ); ?>-<?php
1569 echo esc_attr( $device ) ?>-<?php
1570 echo esc_attr( $dimension ) ?>"
1571 type="number"
1572 name="merchant[<?php
1573 echo esc_attr( $settings['id'] ); ?>][<?php
1574 echo esc_attr( $device ) ?>][<?php
1575 echo esc_attr( $dimension ) ?>]"
1576 value="<?php
1577 echo esc_attr( $value[ $device ][ $dimension ] ); ?>"/>
1578 <label for="merchant-<?php
1579 echo esc_attr( $settings['id'] ); ?>-<?php
1580 echo esc_attr( $device ) ?>-<?php
1581 echo esc_attr( $dimension ) ?>">
1582 <?php
1583 echo esc_html( ucfirst( $dimension ) ); ?>
1584 </label>
1585 </div>
1586 <?php
1587 endforeach; ?>
1588 </div>
1589 </div>
1590 <?php
1591 endforeach; ?>
1592 </div>
1593
1594 <?php
1595 }
1596
1597 /**
1598 * Field: Custom callback.
1599 */
1600 public static function custom_callback( $settings, $value ) {
1601 if ( ! empty( $settings['class_name'] ) && ! empty( $settings['callback_name'] ) ) {
1602 return call_user_func( array( $settings['class_name'], $settings['callback_name'] ), $settings, $value );
1603 }
1604
1605 if ( ! empty( $settings['callback_name'] ) ) {
1606 return call_user_func( $settings['callback_name'], $settings, $value );
1607 }
1608
1609 return false;
1610 }
1611
1612 /**
1613 * Get category choices for select2
1614 *
1615 * @return array
1616 */
1617 public static function get_category_select2_choices() {
1618 $choices = array();
1619 $cats = merchant_get_product_categories();
1620
1621 if ( is_array( $cats ) && ! empty( $cats ) ) {
1622 foreach ( $cats as $slug => $name ) {
1623 $choices[] = array(
1624 'id' => esc_attr( $slug ),
1625 'text' => esc_html( $name ),
1626 );
1627 }
1628 }
1629
1630 return $choices;
1631 }
1632 }
1633
1634 Merchant_Admin_Options::instance();
1635 }
1636