PluginProbe
Ocean Modal Window / trunk
Ocean Modal Window vtrunk
2.3.5 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.4.1 1.0.5 1.0.6 1.0.6.1 1.0.6.2 1.0.7 1.0.8 1.0.9 1.1.0 2.0.9 2.1.0 2.2.0 2.2.1 All 32 releases
ocean-modal-window / ocean-modal-window.php

ocean-modal-window.php in Ocean Modal Window trunk, at ocean-modal-window.php

3,178 lines 93.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Ocean Modal Window
4 * Plugin URI: https://oceanwp.org/extension/ocean-modal-window/
5 * Description: Create the good kind of popups with ease. Display any content in a modal, anywhere on your website.
6 * Version: 2.3.5
7 * Author: OceanWP
8 * Author URI: https://oceanwp.org/
9 * Requires at least: 5.6
10 * Tested up to: 7.1
11 * License: GPLv2 or later
12 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
13 *
14 * Text Domain: ocean-modal-window
15 * Domain Path: /languages
16 *
17 * @package Ocean_Modal_Window
18 * @category Core
19 * @author OceanWP
20 */
21
22 // Exit if accessed directly.
23 if ( ! defined( 'ABSPATH' ) ) {
24 exit;
25 }
26
27 /**
28 * Returns the main instance of Ocean_Modal_Window to prevent the need to use globals.
29 *
30 * @since 1.0.0
31 * @return object Ocean_Modal_Window
32 */
33 function Ocean_Modal_Window() {
34 return Ocean_Modal_Window::instance();
35 } // End Ocean_Modal_Window()
36
37 Ocean_Modal_Window();
38
39 /**
40 * Main Ocean_Modal_Window Class
41 *
42 * @class Ocean_Modal_Window
43 * @version 1.0.0
44 * @since 1.0.0
45 * @package Ocean_Modal_Window
46 */
47 final class Ocean_Modal_Window {
48 /**
49 * Ocean_Modal_Window The single instance of Ocean_Modal_Window.
50 *
51 * @var object
52 * @access private
53 * @since 1.0.0
54 */
55 private static $_instance = null;
56
57 /**
58 * The token.
59 *
60 * @var string
61 * @access public
62 * @since 1.0.0
63 */
64 public $token;
65
66 /**
67 * The version number.
68 *
69 * @var string
70 * @access public
71 * @since 1.0.0
72 */
73 public $version;
74
75 /**
76 * The plugin url.
77 *
78 * @var string
79 * @access public
80 */
81 public $plugin_url;
82
83 /**
84 * The plugin path.
85 *
86 * @var string
87 * @access public
88 */
89 public $plugin_path;
90
91 /**
92 * The plugin data.
93 *
94 * @var array
95 * @access public
96 */
97 public $plugin_data;
98
99 // Admin - Start
100 /**
101 * The admin object.
102 *
103 * @var object
104 * @access public
105 * @since 1.0.0
106 */
107 public $admin;
108
109 /**
110 * Constructor function.
111 *
112 * @access public
113 * @since 1.0.0
114 * @return void
115 */
116 public function __construct( $widget_areas = array() ) {
117 $this->token = 'ocean-modal-window';
118 $this->plugin_url = plugin_dir_url( __FILE__ );
119 $this->plugin_path = plugin_dir_path( __FILE__ );
120 $this->plugin_data = get_file_data( __FILE__, array( 'Version' => 'Version' ), false );
121 $this->version = $this->plugin_data['Version'];
122
123 register_activation_hook( __FILE__, array( $this, 'install' ) );
124
125 add_action( 'init', array( $this, 'omw_load_plugin_textdomain' ) );
126
127 add_action( 'init', array( $this, 'omw_setup' ) );
128
129 add_action( 'init', array( $this, 'register_post_type' ), 0 );
130
131 add_filter( 'oceanwp_theme_strings', array( $this, 'register_omw_strings' ) );
132 }
133
134 /**
135 * Main Ocean_Modal_Window Instance
136 *
137 * Ensures only one instance of Ocean_Modal_Window is loaded or can be loaded.
138 *
139 * @since 1.0.0
140 * @static
141 * @see Ocean_Modal_Window()
142 * @return Main Ocean_Modal_Window instance
143 */
144 public static function instance() {
145 if ( is_null( self::$_instance ) ) {
146 self::$_instance = new self();
147 }
148 return self::$_instance;
149 } // End instance()
150
151 /**
152 * Load the localisation file.
153 *
154 * @access public
155 * @since 1.0.0
156 * @return void
157 */
158 public function omw_load_plugin_textdomain() {
159 load_plugin_textdomain( 'ocean-modal-window', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
160 }
161
162 /**
163 * Cloning is forbidden.
164 *
165 * @since 1.0.0
166 */
167 public function __clone() {
168 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'ocean-modal-window' ), '1.0.0' );
169 }
170
171 /**
172 * Unserializing instances of this class is forbidden.
173 *
174 * @since 1.0.0
175 */
176 public function __wakeup() {
177 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'ocean-modal-window' ), '1.0.0' );
178 }
179
180 /**
181 * Installation.
182 * Runs on activation. Logs the version number and assigns a notice message to a WordPress option.
183 *
184 * @access public
185 * @since 1.0.0
186 * @return void
187 */
188 public function install() {
189 $this->_log_version_number();
190 }
191
192 /**
193 * Log the plugin version number.
194 *
195 * @access private
196 * @since 1.0.0
197 * @return void
198 */
199 private function _log_version_number() {
200 // Log the version number.
201 update_option( $this->token . '-version', $this->version );
202 }
203
204 /**
205 * Setup all the things.
206 * Only executes if OceanWP or a child theme using OceanWP as a parent is active and the extension specific filter returns true.
207 *
208 * @return void
209 */
210 public function omw_setup() {
211 $theme = wp_get_theme();
212
213 if ( 'OceanWP' == $theme->name || 'oceanwp' == $theme->template ) {
214
215 require_once $this->plugin_path . '/includes/helper.php';
216
217 add_action( 'customize_preview_init', array( $this, 'customize_preview_js' ) );
218 add_filter( 'ocean_customize_options_data', array( $this, 'register_customize_options') );
219 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 999 );
220 add_filter( 'ocean_metaboxes_post_types_scripts', array( $this, 'post_type' ) );
221 add_action( 'butterbean_register', array( $this, 'metabox' ), 10, 2 );
222 add_action( 'add_meta_boxes_ocean_modal_window', array( $this, 'add_meta_box' ) );
223 add_action( 'wp_enqueue_scripts', array( $this, 'load_fonts' ) );
224 add_action( 'wp_ajax_get_mw_conditional_rules', array( $this, 'omw_conditional_rules_callback' ) );
225 add_action( 'wp_footer', array( $this, 'modal_display' ) );
226 add_action( 'admin_enqueue_scripts', array( $this, 'mw_enqueue_admin_assets' ) );
227 add_action( 'save_post', array( $this, 'save_mw_conditions_rules' ), 200 );
228 add_filter( 'ocean_head_css', array( $this, 'head_css' ) );
229 add_filter( 'oe_theme_panels', array( $this, 'oe_theme_panels' ) );
230 add_filter( 'ocean_post_setting_meta', array( $this, 'omw_post_meta_args' ) );
231 $capabilities = apply_filters( 'ocean_main_metaboxes_capabilities', 'manage_options' );
232 if ( current_user_can( $capabilities ) ) {
233 add_action( 'butterbean_register', array( $this, 'new_tab' ), 10, 2 );
234 add_action( 'enqueue_block_editor_assets', array( $this, 'metabox_assets' ) );
235 }
236
237 $theme_version = $theme->version;
238
239 $current_theme_version = $theme_version;
240
241 if ( get_template_directory() == get_stylesheet_directory() ) {
242 $current_theme_version = $theme_version;
243 } else {
244 $parent = wp_get_theme()->parent();
245 if ( ! empty( $parent) ) {
246 $current_theme_version = $parent->Version;
247 }
248 }
249
250 if ( version_compare( $current_theme_version, '3.6.1', '<=' ) ) {
251
252 $is_ocean_extra_active = class_exists( 'Ocean_Extra' );
253 $is_ocean_extra_version_valid = defined( 'OE_VERSION' ) && version_compare( OE_VERSION, '2.3.1', '<=' );
254
255 if ( ! $is_ocean_extra_active || $is_ocean_extra_version_valid ) {
256 include_once $this->plugin_path . '/includes/update-message.php';
257 }
258 }
259 }
260 }
261
262 /**
263 * Register custom post type
264 *
265 * @since 1.0.0
266 */
267 public function register_post_type() {
268 register_post_type(
269 'ocean_modal_window',
270 apply_filters(
271 'ocean_modal_window_args',
272 array(
273 'labels' => array(
274 'name' => esc_html__( 'Modal', 'ocean-modal-window' ),
275 'singular_name' => esc_html__( 'Modal Item', 'ocean-modal-window' ),
276 'add_new' => esc_html__( 'Add New', 'ocean-modal-window' ),
277 'add_new_item' => esc_html__( 'Add New Item', 'ocean-modal-window' ),
278 'edit_item' => esc_html__( 'Edit Item', 'ocean-modal-window' ),
279 'new_item' => esc_html__( 'Add New Item', 'ocean-modal-window' ),
280 'view_item' => esc_html__( 'View Item', 'ocean-modal-window' ),
281 'search_items' => esc_html__( 'Search Items', 'ocean-modal-window' ),
282 'not_found' => esc_html__( 'No Items Found', 'ocean-modal-window' ),
283 'not_found_in_trash' => esc_html__( 'No Items Found In Trash', 'ocean-modal-window' ),
284 ),
285 'public' => false,
286 'has_archive' => false,
287 'hierarchical' => false,
288 'show_ui' => true,
289 'show_in_menu' => true,
290 'show_in_admin_bar' => false,
291 'show_in_nav_menus' => false,
292 'show_in_rest' => true,
293 'can_export' => true,
294 'exclude_from_search' => true,
295 'publicly_queryable' => false,
296 'capability_type' => 'page',
297 'menu_icon' => 'dashicons-editor-expand',
298 'menu_position' => 20,
299 'supports' => array( 'title', 'editor', 'custom-fields' ),
300 )
301 )
302 );
303 }
304
305 /**
306 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
307 *
308 * @since 1.0.0
309 */
310 public function customize_preview_js() {
311 wp_enqueue_script( 'omw-customizer', plugins_url( '/assets/js/customizer.min.js', __FILE__ ), array( 'customize-preview' ), '1.0', true );
312 }
313
314 /**
315 * Add hook scripts
316 *
317 * @since 2.1.0
318 */
319 public function mw_enqueue_admin_assets( $hook ) {
320 $screen = get_current_screen();
321
322 if ( ( $hook == 'edit.php' || $hook == 'post.php' || $hook == 'post-new.php' ) && $screen->post_type == 'ocean_modal_window' ) {
323
324 wp_enqueue_script( 'omw-script', plugins_url( '/assets/js/metabox.min.js', __FILE__ ), array( 'jquery', 'wp-util' ), $this->version, true );
325
326 wp_enqueue_style( 'omw-style', plugins_url( '/assets/css/metabox.min.css', __FILE__ ) );
327
328 }
329 }
330
331 /**
332 * Added localize in customizer js
333 */
334 public function register_customize_options($options) {
335
336 if ( OCEAN_EXTRA_ACTIVE
337 && class_exists( 'Ocean_Extra_Theme_Panel' ) ) {
338
339 if ( empty( Ocean_Extra_Theme_Panel::get_setting( 'ocean_modal_window_panel' ) ) ) {
340 return $options;
341 }
342
343 }
344
345 include_once $this->plugin_path . '/includes/options.php';
346
347 $options['ocean_modal_window_settings'] = omw_customizer_options();
348
349 return $options;
350 }
351
352 /**
353 * Enqueue scripts.
354 *
355 * @since 1.0.0
356 */
357 public function enqueue_scripts() {
358
359 $meta_modal = get_post_meta( oceanwp_post_id(), 'omw_enable_modal_window', true );
360
361 // If Modal Window disabled
362 if ( 'disable' === $meta_modal ) {
363 return;
364 }
365
366 // Load Vendors Scripts.
367 wp_enqueue_style( 'ow-perfect-scrollbar', plugins_url( '/assets/vendors/perfect-scrollbar/perfect-scrollbar.css', __FILE__ ) );
368 wp_enqueue_script( 'ow-perfect-scrollbar', plugins_url( '/assets/vendors/perfect-scrollbar/perfect-scrollbar.min.js', __FILE__ ), array(), null, true );
369
370 // Load Ocean Modal Window Scripts.
371 wp_enqueue_style( 'omw-styles', plugins_url( '/assets/css/style.min.css', __FILE__ ) );
372 wp_enqueue_script( 'omw-js-scripts', plugins_url( '/assets/js/modal-window.min.js', __FILE__ ), array( 'oceanwp-main', 'ow-perfect-scrollbar' ), $this->version, true );
373
374 }
375
376 /**
377 * Add post type
378 *
379 * @since 1.0.0
380 */
381 public function post_type( $post_type ) {
382 $post_type[] = 'ocean_modal_window';
383 return $post_type;
384 }
385
386 /**
387 * Registration callback
388 *
389 * @since 1.0.0
390 */
391 public function metabox( $butterbean, $post_type ) {
392
393 if ( 'ocean_modal_window' !== $post_type ) {
394 return;
395 }
396
397 // Register managers, sections, controls, and settings here.
398 $butterbean->register_manager(
399 'oceanwp_mw_settings',
400 array(
401 'label' => esc_html__( 'Modal Settings', 'ocean-modal-window' ),
402 'post_type' => 'ocean_modal_window',
403 'context' => 'normal',
404 'priority' => 'high',
405 )
406 );
407
408 $manager = $butterbean->get_manager( 'oceanwp_mw_settings' );
409
410 $manager->register_section(
411 'oceanwp_mw_general',
412 array(
413 'label' => esc_html__( 'General', 'ocean-modal-window' ),
414 'icon' => 'dashicons-admin-tools',
415 )
416 );
417
418 $manager->register_control(
419 'oceanwp_mw_template', // Same as setting name.
420 array(
421 'section' => 'oceanwp_mw_general',
422 'type' => 'select',
423 'label' => esc_html__( 'Select A Template', 'ocean-modal-window' ),
424 'description' => esc_html__( 'Select your template created in Theme Panel > My Library.', 'ocean-modal-window' ),
425 'choices' => $this->helpers( 'template' ),
426 )
427 );
428
429 $manager->register_setting(
430 'oceanwp_mw_template', // Same as control name.
431 array(
432 'sanitize_callback' => 'sanitize_key',
433 )
434 );
435
436 $manager->register_control(
437 'oceanwp_mw_title', // Same as setting name.
438 array(
439 'section' => 'oceanwp_mw_general',
440 'type' => 'buttonset',
441 'label' => esc_html__( 'Display Title', 'ocean-modal-window' ),
442 'description' => esc_html__( 'Enable or disable the title.', 'ocean-modal-window' ),
443 'choices' => array(
444 'on' => esc_html__( 'Enable', 'ocean-modal-window' ),
445 'off' => esc_html__( 'Disable', 'ocean-modal-window' ),
446 ),
447 )
448 );
449
450 $manager->register_setting(
451 'oceanwp_mw_title', // Same as control name.
452 array(
453 'sanitize_callback' => 'sanitize_key',
454 'default' => 'off',
455 )
456 );
457
458 $manager->register_control(
459 'oceanwp_mw_title_tag', // Same as setting name.
460 array(
461 'section' => 'oceanwp_mw_general',
462 'type' => 'select',
463 'label' => esc_html__( 'Title Tag', 'ocean-modal-window' ),
464 'description' => esc_html__( 'Select title tag for this modal.', 'ocean-modal-window' ),
465 'choices' => array(
466 'h1' => 'H1',
467 'h2' => 'H2',
468 'h3' => 'H3',
469 'h4' => 'H4',
470 'h5' => 'H5',
471 'h6' => 'H6',
472 'p' => 'p',
473 'span' => 'span',
474 'div' => 'div'
475 ),
476 )
477 );
478
479 $manager->register_setting(
480 'oceanwp_mw_title_tag', // Same as control name.
481 array(
482 'sanitize_callback' => 'sanitize_key',
483 'default' => 'h2',
484 )
485 );
486
487 $manager->register_control(
488 'oceanwp_mw_close_btn', // Same as setting name.
489 array(
490 'section' => 'oceanwp_mw_general',
491 'type' => 'buttonset',
492 'label' => esc_html__( 'Display Close Button', 'ocean-modal-window' ),
493 'description' => esc_html__( 'Enable or disable the close button.', 'ocean-modal-window' ),
494 'choices' => array(
495 'on' => esc_html__( 'Enable', 'ocean-modal-window' ),
496 'off' => esc_html__( 'Disable', 'ocean-modal-window' ),
497 ),
498 )
499 );
500
501 $manager->register_setting(
502 'oceanwp_mw_close_btn', // Same as control name.
503 array(
504 'sanitize_callback' => 'sanitize_key',
505 'default' => 'on',
506 )
507 );
508
509 $manager->register_control(
510 'oceanwp_mw_cond_logic',
511 array(
512 'section' => 'oceanwp_mw_general',
513 'type' => 'checkbox',
514 'label' => esc_html__( 'Conditional Logic', 'ocean-modal-window' ),
515 'description' => esc_html__( 'Enable Conditional Logic for this Modal.', 'ocean-modal-window' ),
516 )
517 );
518
519 $manager->register_setting(
520 'oceanwp_mw_cond_logic',
521 array(
522 'sanitize_callback' => 'butterbean_validate_boolean',
523 )
524 );
525
526 $manager->register_control(
527 'oceanwp_mw_width', // Same as setting name.
528 array(
529 'section' => 'oceanwp_mw_general',
530 'type' => 'range',
531 'label' => esc_html__( 'Custom Width', 'ocean-modal-window' ),
532 'description' => esc_html__( 'Enter your custom width for the modal. Default is 700px.', 'ocean-modal-window' ),
533 'attr' => array(
534 'min' => '200',
535 'max' => '1200',
536 'step' => '1',
537 ),
538 )
539 );
540
541 $manager->register_setting(
542 'oceanwp_mw_width', // Same as control name.
543 array(
544 'sanitize_callback' => array( $this, 'sanitize_absint' ),
545 'default' => '700',
546 )
547 );
548
549 $manager->register_control(
550 'oceanwp_mw_height', // Same as setting name.
551 array(
552 'section' => 'oceanwp_mw_general',
553 'type' => 'range',
554 'label' => esc_html__( 'Custom Height', 'ocean-modal-window' ),
555 'description' => esc_html__( 'Enter your custom height for the modal. 0 equal auto height.', 'ocean-modal-window' ),
556 'attr' => array(
557 'min' => '0',
558 'max' => '1200',
559 'step' => '1',
560 ),
561 )
562 );
563
564 $manager->register_setting(
565 'oceanwp_mw_height', // Same as control name.
566 array(
567 'sanitize_callback' => array( $this, 'sanitize_absint' ),
568 'default' => '0',
569 )
570 );
571
572 $manager->register_control(
573 'oceanwp_mw_background_image', // Same as setting name.
574 array(
575 'section' => 'oceanwp_mw_general',
576 'type' => 'image',
577 'label' => esc_html__( 'Background Image', 'ocean-modal-window' ),
578 'description' => esc_html__( 'Select a custom image for your modal.', 'ocean-modal-window' ),
579 )
580 );
581
582 $manager->register_setting(
583 'oceanwp_mw_background_image', // Same as control name.
584 array(
585 'sanitize_callback' => 'sanitize_key',
586 )
587 );
588
589 $manager->register_section(
590 'oceanwp_mw_styling',
591 array(
592 'label' => esc_html__( 'Styling', 'ocean-modal-window' ),
593 'icon' => 'dashicons-hammer',
594 )
595 );
596
597 $manager->register_control(
598 'oceanwp_mw_padding', // Same as setting name.
599 array(
600 'section' => 'oceanwp_mw_styling',
601 'type' => 'text',
602 'label' => esc_html__( 'Padding', 'ocean-modal-window' ),
603 'description' => esc_html__( 'Enter your custom padding for the modal. ex: 20px 30px 20px 30px (Top Right Bottom Left). Default is 50px.', 'ocean-modal-window' ),
604 )
605 );
606
607 $manager->register_setting(
608 'oceanwp_mw_padding', // Same as control name.
609 array(
610 'sanitize_callback' => 'sanitize_text_field',
611 )
612 );
613
614 $manager->register_control(
615 'oceanwp_mw_border', // Same as setting name.
616 array(
617 'section' => 'oceanwp_mw_styling',
618 'type' => 'text',
619 'label' => esc_html__( 'Border Width', 'ocean-modal-window' ),
620 'description' => esc_html__( 'Enter your custom border width for the modal. ex: 2px 1px 2px 1px (Top Right Bottom Left). Default is 0.', 'ocean-modal-window' ),
621 )
622 );
623
624 $manager->register_setting(
625 'oceanwp_mw_border', // Same as control name.
626 array(
627 'sanitize_callback' => 'sanitize_text_field',
628 )
629 );
630
631 $manager->register_control(
632 'oceanwp_mw_border_style', // Same as setting name.
633 array(
634 'section' => 'oceanwp_mw_styling',
635 'type' => 'select',
636 'label' => esc_html__( 'Border Type', 'ocean-modal-window' ),
637 'description' => esc_html__( 'Select your border type if a border width is defined.', 'ocean-modal-window' ),
638 'choices' => array(
639 'solid' => esc_html__( 'Solid', 'ocean-modal-window' ),
640 'double' => esc_html__( 'Double', 'ocean-modal-window' ),
641 'dotted' => esc_html__( 'Dotted', 'ocean-modal-window' ),
642 'dashed' => esc_html__( 'Dashed', 'ocean-modal-window' ),
643 ),
644 )
645 );
646
647 $manager->register_setting(
648 'oceanwp_mw_border_style', // Same as control name.
649 array(
650 'sanitize_callback' => 'sanitize_key',
651 )
652 );
653
654 $manager->register_control(
655 'oceanwp_mw_border_radius', // Same as setting name.
656 array(
657 'section' => 'oceanwp_mw_styling',
658 'type' => 'text',
659 'label' => esc_html__( 'Border Radius', 'ocean-modal-window' ),
660 'description' => esc_html__( 'Enter your custom border radius for the modal. ex: 2px 1px 2px 1px (Top Right Bottom Left). Default is 0.', 'ocean-modal-window' ),
661 )
662 );
663
664 $manager->register_setting(
665 'oceanwp_mw_border_radius', // Same as control name.
666 array(
667 'sanitize_callback' => 'sanitize_text_field',
668 )
669 );
670
671 $manager->register_section(
672 'oceanwp_mw_colors',
673 array(
674 'label' => esc_html__( 'Colors', 'ocean-modal-window' ),
675 'icon' => 'dashicons-admin-customizer',
676 )
677 );
678
679 $manager->register_control(
680 'oceanwp_mw_overlay_bg_color', // Same as setting name.
681 array(
682 'section' => 'oceanwp_mw_colors',
683 'type' => 'color',
684 'label' => esc_html__( 'Overlay Background Color', 'ocean-modal-window' ),
685 'description' => esc_html__( 'Select a hex color code for the modal overlay, ex: #333', 'ocean-modal-window' ),
686 )
687 );
688
689 $manager->register_setting(
690 'oceanwp_mw_overlay_bg_color', // Same as control name.
691 array(
692 'sanitize_callback' => 'butterbean_maybe_hash_hex_color',
693 'default' => '#000000',
694 )
695 );
696
697 $manager->register_control(
698 'oceanwp_mw_overlay_opacity', // Same as setting name.
699 array(
700 'section' => 'oceanwp_mw_colors',
701 'type' => 'range',
702 'label' => esc_html__( 'Overlay Opacity', 'ocean-modal-window' ),
703 'description' => esc_html__( 'Enter your custom opacity for the overlay. Default is 0.9.', 'ocean-modal-window' ),
704 'attr' => array(
705 'min' => '0.1',
706 'max' => '1',
707 'step' => '0.1',
708 ),
709 )
710 );
711
712 $manager->register_setting(
713 'oceanwp_mw_overlay_opacity', // Same as control name.
714 array(
715 'sanitize_callback' => 'sanitize_text_field',
716 'default' => '0.9',
717 )
718 );
719
720 $manager->register_control(
721 'oceanwp_mw_bg_color', // Same as setting name.
722 array(
723 'section' => 'oceanwp_mw_colors',
724 'type' => 'color',
725 'label' => esc_html__( 'Background Color', 'ocean-modal-window' ),
726 'description' => esc_html__( 'Select a hex color code for the modal background, ex: #333', 'ocean-modal-window' ),
727 )
728 );
729
730 $manager->register_setting(
731 'oceanwp_mw_bg_color', // Same as control name.
732 array(
733 'sanitize_callback' => 'butterbean_maybe_hash_hex_color',
734 'default' => '#ffffff',
735 )
736 );
737
738 $manager->register_control(
739 'oceanwp_mw_border_color', // Same as setting name.
740 array(
741 'section' => 'oceanwp_mw_colors',
742 'type' => 'color',
743 'label' => esc_html__( 'Border Color', 'ocean-modal-window' ),
744 'description' => esc_html__( 'Select a hex color code, ex: #333', 'ocean-modal-window' ),
745 )
746 );
747
748 $manager->register_setting(
749 'oceanwp_mw_border_color', // Same as control name.
750 array(
751 'sanitize_callback' => 'butterbean_maybe_hash_hex_color',
752 )
753 );
754
755 $manager->register_control(
756 'oceanwp_mw_text_color', // Same as setting name.
757 array(
758 'section' => 'oceanwp_mw_colors',
759 'type' => 'color',
760 'label' => esc_html__( 'Text Color', 'ocean-modal-window' ),
761 'description' => esc_html__( 'Select a hex color code, ex: #fff', 'ocean-modal-window' ),
762 )
763 );
764
765 $manager->register_setting(
766 'oceanwp_mw_text_color', // Same as control name.
767 array(
768 'sanitize_callback' => 'butterbean_maybe_hash_hex_color',
769 )
770 );
771
772 $manager->register_control(
773 'oceanwp_mw_title_color', // Same as setting name.
774 array(
775 'section' => 'oceanwp_mw_colors',
776 'type' => 'color',
777 'label' => esc_html__( 'Title Color', 'ocean-modal-window' ),
778 'description' => esc_html__( 'Select a hex color code, ex: #fff', 'ocean-modal-window' ),
779 )
780 );
781
782 $manager->register_setting(
783 'oceanwp_mw_title_color', // Same as control name.
784 array(
785 'sanitize_callback' => 'butterbean_maybe_hash_hex_color',
786 'default' => '#333333',
787 )
788 );
789
790 $manager->register_control(
791 'oceanwp_mw_close_btn_bg', // Same as setting name.
792 array(
793 'section' => 'oceanwp_mw_colors',
794 'type' => 'color',
795 'label' => esc_html__( 'Close Button Background', 'ocean-modal-window' ),
796 'description' => esc_html__( 'Select a hex color code, ex: #fe5252', 'ocean-modal-window' ),
797 )
798 );
799
800 $manager->register_setting(
801 'oceanwp_mw_close_btn_bg', // Same as control name.
802 array(
803 'sanitize_callback' => 'butterbean_maybe_hash_hex_color',
804 )
805 );
806
807 $manager->register_control(
808 'oceanwp_mw_close_btn_hover_bg', // Same as setting name.
809 array(
810 'section' => 'oceanwp_mw_colors',
811 'type' => 'color',
812 'label' => esc_html__( 'Close Button Hover Background', 'ocean-modal-window' ),
813 'description' => esc_html__( 'Select a hex color code, ex: #222', 'ocean-modal-window' ),
814 )
815 );
816
817 $manager->register_setting(
818 'oceanwp_mw_close_btn_hover_bg', // Same as control name.
819 array(
820 'sanitize_callback' => 'butterbean_maybe_hash_hex_color',
821 )
822 );
823
824 $manager->register_control(
825 'oceanwp_mw_close_btn_color', // Same as setting name.
826 array(
827 'section' => 'oceanwp_mw_colors',
828 'type' => 'color',
829 'label' => esc_html__( 'Close Button Color', 'ocean-modal-window' ),
830 'description' => esc_html__( 'Select a hex color code, ex: #fff', 'ocean-modal-window' ),
831 )
832 );
833
834 $manager->register_setting(
835 'oceanwp_mw_close_btn_color', // Same as control name.
836 array(
837 'sanitize_callback' => 'butterbean_maybe_hash_hex_color',
838 )
839 );
840
841 $manager->register_control(
842 'oceanwp_mw_close_btn_hover_color', // Same as setting name.
843 array(
844 'section' => 'oceanwp_mw_colors',
845 'type' => 'color',
846 'label' => esc_html__( 'Close Button Hover Color', 'ocean-modal-window' ),
847 'description' => esc_html__( 'Select a hex color code, ex: #fff', 'ocean-modal-window' ),
848 )
849 );
850
851 $manager->register_setting(
852 'oceanwp_mw_close_btn_hover_color', // Same as control name.
853 array(
854 'sanitize_callback' => 'butterbean_maybe_hash_hex_color',
855 )
856 );
857
858 $manager->register_section(
859 'oceanwp_mw_typography',
860 array(
861 'label' => esc_html__( 'Typography', 'ocean-modal-window' ),
862 'icon' => 'dashicons-edit',
863 )
864 );
865
866 $manager->register_control(
867 'oceanwp_mw_font_size', // Same as setting name.
868 array(
869 'section' => 'oceanwp_mw_typography',
870 'type' => 'text',
871 'label' => esc_html__( 'Font Size', 'ocean-modal-window' ),
872 'description' => esc_html__( 'Enter your custom font size (px - em - rem).', 'ocean-modal-window' ),
873 )
874 );
875
876 $manager->register_setting(
877 'oceanwp_mw_font_size', // Same as control name.
878 array(
879 'sanitize_callback' => 'sanitize_text_field',
880 )
881 );
882
883 $manager->register_control(
884 'oceanwp_mw_font_family', // Same as setting name.
885 array(
886 'section' => 'oceanwp_mw_typography',
887 'type' => 'select',
888 'label' => esc_html__( 'Font Family', 'ocean-modal-window' ),
889 'description' => esc_html__( 'Select your custom font.', 'ocean-modal-window' ),
890 'choices' => $this->helpers( 'typo' ),
891 )
892 );
893
894 $manager->register_setting(
895 'oceanwp_mw_font_family', // Same as control name.
896 array(
897 'sanitize_callback' => 'sanitize_text_field',
898 )
899 );
900
901 $manager->register_control(
902 'oceanwp_mw_font_weight', // Same as setting name.
903 array(
904 'section' => 'oceanwp_mw_typography',
905 'type' => 'select',
906 'label' => esc_html__( 'Font Weight', 'ocean-modal-window' ),
907 'description' => esc_html__( 'Important: Not all fonts support every font weight.', 'ocean-modal-window' ),
908 'choices' => array(
909 '' => esc_html__( 'Default', 'ocean-modal-window' ),
910 '100' => esc_html__( 'Extra Light: 100', 'ocean-modal-window' ),
911 '200' => esc_html__( 'Light: 200', 'ocean-modal-window' ),
912 '300' => esc_html__( 'Book: 300', 'ocean-modal-window' ),
913 '400' => esc_html__( 'Normal: 400', 'ocean-modal-window' ),
914 '600' => esc_html__( 'Semibold: 600', 'ocean-modal-window' ),
915 '700' => esc_html__( 'Bold: 700', 'ocean-modal-window' ),
916 '800' => esc_html__( 'Extra Bold: 800', 'ocean-modal-window' ),
917 ),
918 )
919 );
920
921 $manager->register_setting(
922 'oceanwp_mw_font_weight', // Same as control name.
923 array(
924 'sanitize_callback' => 'sanitize_key',
925 )
926 );
927
928 $manager->register_control(
929 'oceanwp_mw_font_style', // Same as setting name.
930 array(
931 'section' => 'oceanwp_mw_typography',
932 'type' => 'select',
933 'label' => esc_html__( 'Font Style', 'ocean-modal-window' ),
934 'description' => esc_html__( 'Select your custom font style.', 'ocean-modal-window' ),
935 'choices' => array(
936 '' => esc_html__( 'Default', 'ocean-modal-window' ),
937 'normal' => esc_html__( 'Normal', 'ocean-modal-window' ),
938 'italic' => esc_html__( 'Italic', 'ocean-modal-window' ),
939 ),
940 )
941 );
942
943 $manager->register_setting(
944 'oceanwp_mw_font_style', // Same as control name.
945 array(
946 'sanitize_callback' => 'sanitize_key',
947 )
948 );
949
950 $manager->register_control(
951 'oceanwp_mw_text_transform', // Same as setting name.
952 array(
953 'section' => 'oceanwp_mw_typography',
954 'type' => 'select',
955 'label' => esc_html__( 'Text Transform', 'ocean-modal-window' ),
956 'description' => esc_html__( 'Select your custom text transform.', 'ocean-modal-window' ),
957 'choices' => array(
958 '' => esc_html__( 'Default', 'ocean-modal-window' ),
959 'capitalize' => esc_html__( 'Capitalize', 'ocean-modal-window' ),
960 'lowercase' => esc_html__( 'Lowercase', 'ocean-modal-window' ),
961 'uppercase' => esc_html__( 'Uppercase', 'ocean-modal-window' ),
962 ),
963 )
964 );
965
966 $manager->register_setting(
967 'oceanwp_mw_text_transform', // Same as control name.
968 array(
969 'sanitize_callback' => 'sanitize_key',
970 )
971 );
972
973 $manager->register_control(
974 'oceanwp_mw_line_height', // Same as setting name.
975 array(
976 'section' => 'oceanwp_mw_typography',
977 'type' => 'text',
978 'label' => esc_html__( 'Line Height', 'ocean-modal-window' ),
979 'description' => esc_html__( 'Enter your custom line height (px - em - rem).', 'ocean-modal-window' ),
980 )
981 );
982
983 $manager->register_setting(
984 'oceanwp_mw_line_height', // Same as control name.
985 array(
986 'sanitize_callback' => 'sanitize_text_field',
987 )
988 );
989
990 $manager->register_control(
991 'oceanwp_mw_letter_spacing', // Same as setting name.
992 array(
993 'section' => 'oceanwp_mw_typography',
994 'type' => 'text',
995 'label' => esc_html__( 'Letter Spacing', 'ocean-modal-window' ),
996 'description' => esc_html__( 'Enter your custom letter spacing (px - em - rem).', 'ocean-modal-window' ),
997 )
998 );
999
1000 $manager->register_setting(
1001 'oceanwp_mw_letter_spacing', // Same as control name.
1002 array(
1003 'sanitize_callback' => 'sanitize_text_field',
1004 )
1005 );
1006
1007 $manager->register_section(
1008 'oceanwp_mw_tablet_device',
1009 array(
1010 'label' => esc_html__( 'Tablet Device', 'ocean-modal-window' ),
1011 'icon' => 'dashicons-tablet',
1012 )
1013 );
1014
1015 $manager->register_control(
1016 'oceanwp_mw_tablet_width', // Same as setting name.
1017 array(
1018 'section' => 'oceanwp_mw_tablet_device',
1019 'type' => 'range',
1020 'label' => esc_html__( 'Custom Width', 'ocean-modal-window' ),
1021 'description' => esc_html__( 'Enter your custom width for the modal. Default is 700px.', 'ocean-modal-window' ),
1022 'attr' => array(
1023 'min' => '200',
1024 'max' => '1200',
1025 'step' => '1',
1026 ),
1027 )
1028 );
1029
1030 $manager->register_setting(
1031 'oceanwp_mw_tablet_width', // Same as control name.
1032 array(
1033 'sanitize_callback' => array( $this, 'sanitize_absint' ),
1034 'default' => '700',
1035 )
1036 );
1037
1038 $manager->register_control(
1039 'oceanwp_mw_tablet_height', // Same as setting name.
1040 array(
1041 'section' => 'oceanwp_mw_tablet_device',
1042 'type' => 'range',
1043 'label' => esc_html__( 'Custom Height', 'ocean-modal-window' ),
1044 'description' => esc_html__( 'Enter your custom height for the modal. 0 equal auto height.', 'ocean-modal-window' ),
1045 'attr' => array(
1046 'min' => '0',
1047 'max' => '1200',
1048 'step' => '1',
1049 ),
1050 )
1051 );
1052
1053 $manager->register_setting(
1054 'oceanwp_mw_tablet_height', // Same as control name.
1055 array(
1056 'sanitize_callback' => 'sanitize_key',
1057 'default' => '0',
1058 )
1059 );
1060
1061 $manager->register_control(
1062 'oceanwp_mw_tablet_padding', // Same as setting name.
1063 array(
1064 'section' => 'oceanwp_mw_tablet_device',
1065 'type' => 'text',
1066 'label' => esc_html__( 'Padding', 'ocean-modal-window' ),
1067 'description' => esc_html__( 'Enter your custom padding for the modal. ex: 20px 30px 20px 30px (Top Right Bottom Left). Default is 50px.', 'ocean-modal-window' ),
1068 )
1069 );
1070
1071 $manager->register_setting(
1072 'oceanwp_mw_tablet_padding', // Same as control name.
1073 array(
1074 'sanitize_callback' => 'sanitize_text_field',
1075 )
1076 );
1077
1078 $manager->register_control(
1079 'oceanwp_mw_tablet_font_size', // Same as setting name.
1080 array(
1081 'section' => 'oceanwp_mw_tablet_device',
1082 'type' => 'text',
1083 'label' => esc_html__( 'Font Size', 'ocean-modal-window' ),
1084 'description' => esc_html__( 'Enter your custom font size (px - em - rem).', 'ocean-modal-window' ),
1085 )
1086 );
1087
1088 $manager->register_setting(
1089 'oceanwp_mw_tablet_font_size', // Same as control name.
1090 array(
1091 'sanitize_callback' => 'sanitize_text_field',
1092 )
1093 );
1094
1095 $manager->register_control(
1096 'oceanwp_mw_tablet_line_height', // Same as setting name.
1097 array(
1098 'section' => 'oceanwp_mw_tablet_device',
1099 'type' => 'text',
1100 'label' => esc_html__( 'Line Height', 'ocean-modal-window' ),
1101 'description' => esc_html__( 'Enter your custom line height (px - em - rem).', 'ocean-modal-window' ),
1102 )
1103 );
1104
1105 $manager->register_setting(
1106 'oceanwp_mw_tablet_line_height', // Same as control name.
1107 array(
1108 'sanitize_callback' => 'sanitize_text_field',
1109 )
1110 );
1111
1112 $manager->register_control(
1113 'oceanwp_mw_tablet_letter_spacing', // Same as setting name.
1114 array(
1115 'section' => 'oceanwp_mw_tablet_device',
1116 'type' => 'text',
1117 'label' => esc_html__( 'Letter Spacing', 'ocean-modal-window' ),
1118 'description' => esc_html__( 'Enter your custom letter spacing (px - em - rem).', 'ocean-modal-window' ),
1119 )
1120 );
1121
1122 $manager->register_setting(
1123 'oceanwp_mw_tablet_letter_spacing', // Same as control name.
1124 array(
1125 'sanitize_callback' => 'sanitize_text_field',
1126 )
1127 );
1128
1129 $manager->register_section(
1130 'oceanwp_mw_mobile_device',
1131 array(
1132 'label' => esc_html__( 'Mobile Device', 'ocean-modal-window' ),
1133 'icon' => 'dashicons-smartphone',
1134 )
1135 );
1136
1137 $manager->register_control(
1138 'oceanwp_mw_mobile_width', // Same as setting name.
1139 array(
1140 'section' => 'oceanwp_mw_mobile_device',
1141 'type' => 'range',
1142 'label' => esc_html__( 'Custom Width', 'ocean-modal-window' ),
1143 'description' => esc_html__( 'Enter your custom width for the modal. Default is 700px.', 'ocean-modal-window' ),
1144 'attr' => array(
1145 'min' => '200',
1146 'max' => '1200',
1147 'step' => '1',
1148 ),
1149 )
1150 );
1151
1152 $manager->register_setting(
1153 'oceanwp_mw_mobile_width', // Same as control name.
1154 array(
1155 'sanitize_callback' => array( $this, 'sanitize_absint' ),
1156 'default' => '700',
1157 )
1158 );
1159
1160 $manager->register_control(
1161 'oceanwp_mw_mobile_height', // Same as setting name.
1162 array(
1163 'section' => 'oceanwp_mw_mobile_device',
1164 'type' => 'range',
1165 'label' => esc_html__( 'Custom Height', 'ocean-modal-window' ),
1166 'description' => esc_html__( 'Enter your custom height for the modal. 0 equal auto height.', 'ocean-modal-window' ),
1167 'attr' => array(
1168 'min' => '0',
1169 'max' => '1200',
1170 'step' => '1',
1171 ),
1172 )
1173 );
1174
1175 $manager->register_setting(
1176 'oceanwp_mw_mobile_height', // Same as control name.
1177 array(
1178 'sanitize_callback' => 'sanitize_key',
1179 'default' => '0',
1180 )
1181 );
1182
1183 $manager->register_control(
1184 'oceanwp_mw_mobile_padding', // Same as setting name.
1185 array(
1186 'section' => 'oceanwp_mw_mobile_device',
1187 'type' => 'text',
1188 'label' => esc_html__( 'Padding', 'ocean-modal-window' ),
1189 'description' => esc_html__( 'Enter your custom padding for the modal. ex: 20px 30px 20px 30px (Top Right Bottom Left). Default is 50px.', 'ocean-modal-window' ),
1190 )
1191 );
1192
1193 $manager->register_setting(
1194 'oceanwp_mw_mobile_padding', // Same as control name.
1195 array(
1196 'sanitize_callback' => 'sanitize_text_field',
1197 )
1198 );
1199
1200 $manager->register_control(
1201 'oceanwp_mw_mobile_font_size', // Same as setting name.
1202 array(
1203 'section' => 'oceanwp_mw_mobile_device',
1204 'type' => 'text',
1205 'label' => esc_html__( 'Font Size', 'ocean-modal-window' ),
1206 'description' => esc_html__( 'Enter your custom font size (px - em - rem).', 'ocean-modal-window' ),
1207 )
1208 );
1209
1210 $manager->register_setting(
1211 'oceanwp_mw_mobile_font_size', // Same as control name.
1212 array(
1213 'sanitize_callback' => 'sanitize_text_field',
1214 )
1215 );
1216
1217 $manager->register_control(
1218 'oceanwp_mw_mobile_line_height', // Same as setting name.
1219 array(
1220 'section' => 'oceanwp_mw_mobile_device',
1221 'type' => 'text',
1222 'label' => esc_html__( 'Line Height', 'ocean-modal-window' ),
1223 'description' => esc_html__( 'Enter your custom line height (px - em - rem).', 'ocean-modal-window' ),
1224 )
1225 );
1226
1227 $manager->register_setting(
1228 'oceanwp_mw_mobile_line_height', // Same as control name.
1229 array(
1230 'sanitize_callback' => 'sanitize_text_field',
1231 )
1232 );
1233
1234 $manager->register_control(
1235 'oceanwp_mw_mobile_letter_spacing', // Same as setting name.
1236 array(
1237 'section' => 'oceanwp_mw_mobile_device',
1238 'type' => 'text',
1239 'label' => esc_html__( 'Letter Spacing', 'ocean-modal-window' ),
1240 'description' => esc_html__( 'Enter your custom letter spacing (px - em - rem).', 'ocean-modal-window' ),
1241 )
1242 );
1243
1244 $manager->register_setting(
1245 'oceanwp_mw_mobile_letter_spacing', // Same as control name.
1246 array(
1247 'sanitize_callback' => 'sanitize_text_field',
1248 )
1249 );
1250
1251 }
1252
1253 /**
1254 * Add new tab in metabox.
1255 *
1256 * @since 1.0.0
1257 */
1258 public function new_tab( $butterbean, $post_type ) {
1259
1260 // Gets the manager object we want to add sections to.
1261 $manager = $butterbean->get_manager( 'oceanwp_mb_settings' );
1262
1263 $manager->register_section(
1264 'oceanwp_mb_modal_window',
1265 array(
1266 'label' => esc_html__( 'Modal Window', 'ocean-modal-window' ),
1267 'icon' => 'dashicons-editor-expand',
1268 )
1269 );
1270
1271 $manager->register_control(
1272 'omw_enable_modal_window', // Same as setting name.
1273 array(
1274 'section' => 'oceanwp_mb_modal_window',
1275 'type' => 'buttonset',
1276 'label' => esc_html__( 'Enable Modal Window For This Page', 'ocean-modal-window' ),
1277 'description' => esc_html__( 'Enable or disable the modal window for this page.', 'ocean-modal-window' ),
1278 'choices' => array(
1279 'enable' => esc_html__( 'Enable', 'ocean-modal-window' ),
1280 'disable' => esc_html__( 'Disable', 'ocean-modal-window' ),
1281 ),
1282 )
1283 );
1284
1285 $manager->register_setting(
1286 'omw_enable_modal_window', // Same as control name.
1287 array(
1288 'default' => 'enable',
1289 'sanitize_callback' => 'sanitize_key',
1290 )
1291 );
1292 }
1293
1294 /**
1295 * Sanitize function for decimal
1296 */
1297 public function omw_sanitize_decimal( $value ) {
1298 if (is_numeric($value)) {
1299 return round((float) $value, 2);
1300 } else {
1301 return '';
1302 }
1303 }
1304
1305 /**
1306 * Sanitize function for array
1307 */
1308 public function omw_sanitize_array($meta_value) {
1309
1310 if ( ! is_array( $meta_value ) ) {
1311 return array();
1312 }
1313
1314 foreach ($meta_value as $key => $value) {
1315 $meta_value[$key] = wp_kses_post($value);
1316 }
1317
1318 return $meta_value;
1319 }
1320
1321 public function omw_sanitize_conditions( $meta_value ) {
1322
1323 if ( ! is_array( $meta_value ) ) {
1324 return array();
1325 }
1326
1327 // Get allowed values from your choices system
1328 $allowed = [];
1329 if ( function_exists( 'oe_get_allowed_condition_values' ) ) {
1330 $allowed = oe_get_allowed_condition_values();
1331 }
1332 $allowed = array_map( 'sanitize_text_field', (array) $allowed );
1333
1334 $clean = array();
1335
1336 foreach ( $meta_value as $key => $value ) {
1337
1338 // Always sanitize raw text first
1339 $value = sanitize_text_field( $value );
1340
1341 // Allow ONLY values from the allowed list
1342 if ( in_array( $value, $allowed, true ) ) {
1343 $clean[$key] = $value;
1344 }
1345 }
1346
1347 return $clean;
1348 }
1349
1350 /**
1351 * Post setting arguments
1352 */
1353 public function omw_post_meta_args( $defaults ) {
1354
1355 $defaults['omw_enable_modal_window'] = array(
1356 'type' => 'string',
1357 'single' => true,
1358 'rest' => true,
1359 'subType' => '',
1360 'value' => 'enable',
1361 'sanitize' => 'sanitize_key'
1362 );
1363
1364 $defaults['oceanwp_mw_template'] = array(
1365 'type' => 'string',
1366 'single' => true,
1367 'rest' => true,
1368 'subType' => 'ocean_modal_window',
1369 'value' => '',
1370 'sanitize' => 'sanitize_key'
1371 );
1372
1373 $defaults['oceanwp_mw_title'] = array(
1374 'type' => 'string',
1375 'single' => true,
1376 'rest' => true,
1377 'subType' => 'ocean_modal_window',
1378 'value' => 'off',
1379 'sanitize' => 'sanitize_key'
1380 );
1381
1382 $defaults['oceanwp_mw_title_tag'] = array(
1383 'type' => 'string',
1384 'single' => true,
1385 'rest' => true,
1386 'subType' => 'ocean_modal_window',
1387 'value' => 'h2',
1388 'sanitize' => 'sanitize_key'
1389 );
1390
1391 $defaults['oceanwp_mw_close_btn'] = array(
1392 'type' => 'string',
1393 'single' => true,
1394 'rest' => true,
1395 'subType' => 'ocean_modal_window',
1396 'value' => 'on',
1397 'sanitize' => 'sanitize_key'
1398 );
1399
1400 $defaults['oceanwp_mw_cond_logic'] = array(
1401 'type' => 'boolean',
1402 'single' => true,
1403 'rest' => true,
1404 'subType' => 'ocean_modal_window',
1405 'value' => false
1406 );
1407
1408 $defaults['oceanwp_mw_width'] = array(
1409 'type' => 'number',
1410 'single' => true,
1411 'rest' => true,
1412 'subType' => 'ocean_modal_window',
1413 'value' => 700,
1414 'sanitize' => 'sanitize_absint'
1415 );
1416
1417 $defaults['oceanwp_mw_tablet_width'] = array(
1418 'type' => 'number',
1419 'single' => true,
1420 'rest' => true,
1421 'subType' => 'ocean_modal_window',
1422 'value' => 700,
1423 'sanitize' => 'sanitize_absint'
1424 );
1425
1426 $defaults['oceanwp_mw_mobile_width'] = array(
1427 'type' => 'number',
1428 'single' => true,
1429 'rest' => true,
1430 'subType' => 'ocean_modal_window',
1431 'value' => 700,
1432 'sanitize' => 'sanitize_absint'
1433 );
1434
1435 $defaults['oceanwp_mw_height'] = array(
1436 'type' => 'number',
1437 'single' => true,
1438 'rest' => true,
1439 'subType' => 'ocean_modal_window',
1440 'value' => 0,
1441 'sanitize' => 'sanitize_absint'
1442 );
1443
1444 $defaults['oceanwp_mw_tablet_height'] = array(
1445 'type' => 'number',
1446 'single' => true,
1447 'rest' => true,
1448 'subType' => 'ocean_modal_window',
1449 'value' => 0,
1450 'sanitize' => 'sanitize_absint'
1451 );
1452
1453 $defaults['oceanwp_mw_mobile_height'] = array(
1454 'type' => 'number',
1455 'single' => true,
1456 'rest' => true,
1457 'subType' => 'ocean_modal_window',
1458 'value' => 0,
1459 'sanitize' => 'sanitize_absint'
1460 );
1461
1462 $defaults['oceanwp_mw_background_image'] = array(
1463 'type' => 'number',
1464 'single' => true,
1465 'rest' => true,
1466 'subType' => 'ocean_modal_window',
1467 'value' => 0,
1468 'sanitize' => 'sanitize_absint'
1469 );
1470
1471 $defaults['oceanwp_mw_padding'] = array(
1472 'type' => 'string',
1473 'single' => true,
1474 'rest' => true,
1475 'subType' => 'ocean_modal_window',
1476 'value' => '',
1477 'sanitize' => 'sanitize_key',
1478 );
1479
1480 $defaults['oceanwp_mw_tablet_padding'] = array(
1481 'type' => 'string',
1482 'single' => true,
1483 'rest' => true,
1484 'subType' => 'ocean_modal_window',
1485 'value' => '',
1486 'sanitize' => 'sanitize_key',
1487 );
1488
1489 $defaults['oceanwp_mw_mobile_padding'] = array(
1490 'type' => 'string',
1491 'single' => true,
1492 'rest' => true,
1493 'subType' => 'ocean_modal_window',
1494 'value' => '',
1495 'sanitize' => 'sanitize_key',
1496 );
1497
1498 $defaults['oceanwp_mw_border'] = array(
1499 'type' => 'string',
1500 'single' => true,
1501 'rest' => true,
1502 'subType' => 'ocean_modal_window',
1503 'value' => '',
1504 'sanitize' => 'sanitize_key',
1505 );
1506
1507 $defaults['oceanwp_mw_border_style'] = array(
1508 'type' => 'string',
1509 'single' => true,
1510 'rest' => true,
1511 'subType' => 'ocean_modal_window',
1512 'value' => '',
1513 'sanitize' => 'sanitize_key',
1514 );
1515
1516 $defaults['oceanwp_mw_border_radius'] = array(
1517 'type' => 'string',
1518 'single' => true,
1519 'rest' => true,
1520 'subType' => 'ocean_modal_window',
1521 'value' => '',
1522 'sanitize' => 'sanitize_key',
1523 );
1524
1525 $defaults['oceanwp_mw_overlay_bg_color'] = array(
1526 'type' => 'string',
1527 'single' => true,
1528 'rest' => true,
1529 'subType' => 'ocean_modal_window',
1530 'value' => '#000000',
1531 'sanitize' => 'wp_kses_post',
1532 );
1533
1534 $defaults['oceanwp_mw_overlay_opacity'] = array(
1535 'type' => 'number',
1536 'single' => true,
1537 'rest' => true,
1538 'subType' => 'ocean_modal_window',
1539 'value' => 0.9,
1540 'sanitize' => array( $this, 'omw_sanitize_decimal' ),
1541 );
1542
1543 $defaults['oceanwp_mw_bg_color'] = array(
1544 'type' => 'string',
1545 'single' => true,
1546 'rest' => true,
1547 'subType' => 'ocean_modal_window',
1548 'value' => '#ffffff',
1549 'sanitize' => 'wp_kses_post',
1550 );
1551
1552 $defaults['oceanwp_mw_border_color'] = array(
1553 'type' => 'string',
1554 'single' => true,
1555 'rest' => true,
1556 'subType' => 'ocean_modal_window',
1557 'value' => '',
1558 'sanitize' => 'wp_kses_post',
1559 );
1560
1561 $defaults['oceanwp_mw_text_color'] = array(
1562 'type' => 'string',
1563 'single' => true,
1564 'rest' => true,
1565 'subType' => 'ocean_modal_window',
1566 'value' => '',
1567 'sanitize' => 'wp_kses_post',
1568 );
1569
1570 $defaults['oceanwp_mw_title_color'] = array(
1571 'type' => 'string',
1572 'single' => true,
1573 'rest' => true,
1574 'subType' => 'ocean_modal_window',
1575 'value' => '#333333',
1576 'sanitize' => 'wp_kses_post',
1577 );
1578
1579 $defaults['oceanwp_mw_close_btn_bg'] = array(
1580 'type' => 'string',
1581 'single' => true,
1582 'rest' => true,
1583 'subType' => 'ocean_modal_window',
1584 'value' => '',
1585 'sanitize' => 'wp_kses_post',
1586 );
1587
1588 $defaults['oceanwp_mw_close_btn_hover_bg'] = array(
1589 'type' => 'string',
1590 'single' => true,
1591 'rest' => true,
1592 'subType' => 'ocean_modal_window',
1593 'value' => '',
1594 'sanitize' => 'wp_kses_post',
1595 );
1596
1597 $defaults['oceanwp_mw_close_btn_color'] = array(
1598 'type' => 'string',
1599 'single' => true,
1600 'rest' => true,
1601 'subType' => 'ocean_modal_window',
1602 'value' => '',
1603 'sanitize' => 'wp_kses_post',
1604 );
1605
1606 $defaults['oceanwp_mw_close_btn_hover_color'] = array(
1607 'type' => 'string',
1608 'single' => true,
1609 'rest' => true,
1610 'subType' => 'ocean_modal_window',
1611 'value' => '',
1612 'sanitize' => 'wp_kses_post',
1613 );
1614
1615 $defaults['oceanwp_mw_font_family'] = array(
1616 'type' => 'string',
1617 'single' => true,
1618 'rest' => true,
1619 'subType' => 'ocean_modal_window',
1620 'value' => '',
1621 'sanitize' => 'sanitize_text_field',
1622 );
1623
1624 $defaults['oceanwp_mw_font_size'] = array(
1625 'type' => 'number',
1626 'single' => true,
1627 'rest' => true,
1628 'subType' => 'ocean_modal_window',
1629 'value' => 0,
1630 'sanitize' => 'sanitize_absint',
1631 );
1632
1633 $defaults['oceanwp_mw_tablet_font_size'] = array(
1634 'type' => 'number',
1635 'single' => true,
1636 'rest' => true,
1637 'subType' => 'ocean_modal_window',
1638 'value' => 0,
1639 'sanitize' => 'sanitize_absint',
1640 );
1641
1642 $defaults['oceanwp_mw_mobile_font_size'] = array(
1643 'type' => 'number',
1644 'single' => true,
1645 'rest' => true,
1646 'subType' => 'ocean_modal_window',
1647 'value' => 0,
1648 'sanitize' => 'sanitize_absint',
1649 );
1650
1651 $defaults['oceanwp_mw_font_size_unit'] = array(
1652 'type' => 'string',
1653 'single' => true,
1654 'rest' => true,
1655 'subType' => 'ocean_modal_window',
1656 'value' => 'px',
1657 'sanitize' => 'sanitize_key',
1658 );
1659
1660 $defaults['oceanwp_mw_font_weight'] = array(
1661 'type' => 'string',
1662 'single' => true,
1663 'rest' => true,
1664 'subType' => 'ocean_modal_window',
1665 'value' => '',
1666 'sanitize' => 'sanitize_text_field',
1667 );
1668
1669 $defaults['oceanwp_mw_font_weight_tablet'] = array(
1670 'type' => 'string',
1671 'single' => true,
1672 'rest' => true,
1673 'subType' => 'ocean_modal_window',
1674 'value' => '',
1675 'sanitize' => 'sanitize_text_field',
1676 );
1677
1678 $defaults['oceanwp_mw_font_weight_mobile'] = array(
1679 'type' => 'string',
1680 'single' => true,
1681 'rest' => true,
1682 'subType' => 'ocean_modal_window',
1683 'value' => '',
1684 'sanitize' => 'sanitize_text_field',
1685 );
1686
1687 $defaults['oceanwp_mw_font_subset'] = array(
1688 'type' => 'string',
1689 'single' => true,
1690 'rest' => true,
1691 'subType' => 'ocean_modal_window',
1692 'value' => '',
1693 'sanitize' => 'sanitize_text_field',
1694 );
1695
1696 $defaults['oceanwp_mw_text_transform'] = array(
1697 'type' => 'string',
1698 'single' => true,
1699 'rest' => true,
1700 'subType' => 'ocean_modal_window',
1701 'value' => '',
1702 'sanitize' => 'sanitize_key',
1703 );
1704
1705 $defaults['oceanwp_mw_text_transform_tablet'] = array(
1706 'type' => 'string',
1707 'single' => true,
1708 'rest' => true,
1709 'subType' => 'ocean_modal_window',
1710 'value' => '',
1711 'sanitize' => 'sanitize_key',
1712 );
1713
1714 $defaults['oceanwp_mw_text_transform_mobile'] = array(
1715 'type' => 'string',
1716 'single' => true,
1717 'rest' => true,
1718 'subType' => 'ocean_modal_window',
1719 'value' => '',
1720 'sanitize' => 'sanitize_key',
1721 );
1722
1723 $defaults['oceanwp_mw_line_height'] = array(
1724 'type' => 'number',
1725 'single' => true,
1726 'rest' => true,
1727 'subType' => 'ocean_modal_window',
1728 'value' => 0,
1729 'sanitize' => 'sanitize_absint',
1730 );
1731
1732 $defaults['oceanwp_mw_tablet_line_height'] = array(
1733 'type' => 'number',
1734 'single' => true,
1735 'rest' => true,
1736 'subType' => 'ocean_modal_window',
1737 'value' => 0,
1738 'sanitize' => 'sanitize_absint',
1739 );
1740
1741 $defaults['oceanwp_mw_mobile_line_height'] = array(
1742 'type' => 'number',
1743 'single' => true,
1744 'rest' => true,
1745 'subType' => 'ocean_modal_window',
1746 'value' => 0,
1747 'sanitize' => 'sanitize_absint',
1748 );
1749
1750 $defaults['oceanwp_mw_line_height_unit'] = array(
1751 'type' => 'string',
1752 'single' => true,
1753 'rest' => true,
1754 'subType' => 'ocean_modal_window',
1755 'value' => '',
1756 'sanitize' => 'sanitize_key'
1757 );
1758
1759 $defaults['oceanwp_mw_letter_spacing'] = array(
1760 'type' => 'number',
1761 'single' => true,
1762 'rest' => true,
1763 'subType' => 'ocean_modal_window',
1764 'value' => 0,
1765 'sanitize' => 'sanitize_absint',
1766 );
1767
1768 $defaults['oceanwp_mw_tablet_letter_spacing'] = array(
1769 'type' => 'number',
1770 'single' => true,
1771 'rest' => true,
1772 'subType' => 'ocean_modal_window',
1773 'value' => 0,
1774 'sanitize' => 'sanitize_absint',
1775 );
1776
1777 $defaults['oceanwp_mw_mobile_letter_spacing'] = array(
1778 'type' => 'number',
1779 'single' => true,
1780 'rest' => true,
1781 'subType' => 'ocean_modal_window',
1782 'value' => 0,
1783 'sanitize' => 'sanitize_absint',
1784 );
1785
1786 $defaults['oceanwp_mw_letter_spacing_unit'] = array(
1787 'type' => 'string',
1788 'single' => true,
1789 'rest' => true,
1790 'subType' => 'ocean_modal_window',
1791 'value' => '',
1792 'sanitize' => 'sanitize_key',
1793 );
1794
1795 $defaults['mw_display_on'] = array(
1796 'type' => 'array',
1797 'single' => true,
1798 'rest' => array(
1799 'schema' => array(
1800 'type' => 'array',
1801 'items' => array(
1802 'type' => 'string'
1803 )
1804 )
1805 ),
1806 'subType' => 'ocean_modal_window',
1807 'value' => '',
1808 'sanitize' => array( $this, 'omw_sanitize_conditions' ),
1809 );
1810
1811 $defaults['mw_hide_on'] = array(
1812 'type' => 'array',
1813 'single' => true,
1814 'rest' => array(
1815 'schema' => array(
1816 'type' => 'array',
1817 'items' => array(
1818 'type' => 'string'
1819 )
1820 )
1821 ),
1822 'subType' => 'ocean_modal_window',
1823 'value' => '',
1824 'sanitize' => array( $this, 'omw_sanitize_conditions' ),
1825 );
1826
1827 return apply_filters( 'omw_post_meta_args', $defaults );
1828 }
1829
1830 /**
1831 * Enqueque Editor Scripts
1832 */
1833 public function metabox_assets() {
1834
1835 $uri = $this->plugin_url . 'assets/dist/';
1836 $asset = require $this->plugin_path . 'assets/dist/modal-settings.asset.php';
1837 $deps = $asset['dependencies'];
1838 array_push( $deps, 'updates' );
1839
1840 wp_register_script(
1841 'omw-meta-modal-settings',
1842 $uri . 'modal-settings.js',
1843 $deps,
1844 filemtime( $this->plugin_path . 'assets/dist/modal-settings.js' ),
1845 true
1846 );
1847
1848 wp_enqueue_script( 'omw-meta-modal-settings' );
1849
1850 wp_enqueue_style(
1851 'omw-meta-modal-settings',
1852 $uri . 'style-modal-settings.css',
1853 array( 'wp-components' ),
1854 filemtime( $this->plugin_path . 'assets/dist/style-modal-settings.css' )
1855 );
1856
1857 if ( function_exists( 'oe_check_post_types_settings' ) ) {
1858 if ( false === oe_check_post_types_settings() ) {
1859 return;
1860 }
1861 } else {
1862 return;
1863 }
1864
1865 $asset = require $this->plugin_path . 'assets/dist/metabox.asset.php';
1866 $deps = $asset['dependencies'];
1867 array_push( $deps, 'updates' );
1868
1869 wp_register_script(
1870 'omw-metabox-settings',
1871 $uri . 'metabox.js',
1872 $deps,
1873 filemtime( $this->plugin_path . 'assets/dist/metabox.js' ),
1874 true
1875 );
1876
1877 wp_enqueue_script( 'omw-metabox-settings' );
1878
1879 if ( function_exists( 'wp_set_script_translations' ) ) {
1880 wp_set_script_translations( 'omw-metabox-settings', 'ocean-modal-window' );
1881 }
1882
1883 wp_localize_script(
1884 'omw-metabox-settings',
1885 'omw_metabox_params',
1886 array(
1887 'ConditionsChoices' => omw_get_condition_choices()
1888 )
1889 );
1890 }
1891
1892 /**
1893 * Sanitize function for integers
1894 *
1895 * @since 1.0.0
1896 */
1897 public function sanitize_absint( $value ) {
1898 return $value && is_numeric( $value ) ? absint( $value ) : '';
1899 }
1900
1901 /**
1902 * Helpers
1903 *
1904 * @since 1.0.0
1905 */
1906 public static function helpers( $return = null ) {
1907
1908 // Return fonts array
1909 if ( 'typo' == $return ) {
1910 $fonts = array( esc_html__( 'Default', 'ocean-modal-window' ) );
1911 $id = '';
1912 // Add custom fonts from child themes
1913 if ( function_exists( 'ocean_add_custom_fonts' ) ) {
1914 $get_fonts = ocean_add_custom_fonts();
1915 if ( $get_fonts && is_array( $get_fonts ) ) {
1916 foreach ( $get_fonts as $font ) {
1917 $fonts[ $font ] = $font;
1918 }
1919 }
1920 }
1921
1922 // Get Standard font options
1923 if ( $std_fonts = oceanwp_standard_fonts() ) {
1924 foreach ( $std_fonts as $font ) {
1925 $fonts[ $font ] = $font;
1926 }
1927 }
1928
1929 // Google font options
1930 if ( $google_fonts = oceanwp_google_fonts_array() ) {
1931 foreach ( $google_fonts as $font ) {
1932 $fonts[ $font ] = $font;
1933 }
1934 }
1935
1936 return $fonts;
1937 }
1938
1939 // Return template array
1940 elseif ( 'template' == $return ) {
1941 $templates = array( esc_html__( 'Default', 'ocean-modal-window' ) );
1942 $get_templates = get_posts(
1943 array(
1944 'post_type' => 'oceanwp_library',
1945 'numberposts' => -1,
1946 'post_status' => 'publish',
1947 )
1948 );
1949
1950 if ( ! empty( $get_templates ) ) {
1951 foreach ( $get_templates as $template ) {
1952 $templates[ $template->ID ] = $template->post_title;
1953 }
1954 }
1955
1956 return $templates;
1957 }
1958
1959 }
1960
1961 /**
1962 * Ajax function to add conditional rules section.
1963 *
1964 * @since 2.1.0
1965 */
1966 public function omw_conditional_rules_callback() {
1967 $activeCond = boolval( $_POST['activeCond'] );
1968 $mwId = intval( $_POST['mwId'] );
1969
1970 // get conditional logic section \\\
1971 // Hide on selected options
1972 $hide_on = ! empty( get_post_meta( $mwId, 'mw_hide_on', true ) ) && $activeCond ? get_post_meta( $mwId, 'mw_hide_on', true ) : '';
1973
1974 // Display on selected options
1975 $display_on = ! empty( get_post_meta( $mwId, 'mw_display_on', true ) ) && $activeCond ? get_post_meta( $mwId, 'mw_display_on', true ) : '';
1976
1977 $condHTML = '';
1978 $condHTML .= '<div class="options options-cond boxes"';
1979 if ( ! $activeCond ) {
1980 $condHTML .= ' style="display: none"';
1981 }
1982 $condHTML .= '>';
1983 $condHTML .= '<div class="condition-container dispaly-on container-wrap">';
1984 $condHTML .= '<div class="display-on-fields display-on-field">';
1985 if ( empty( $display_on ) ) {
1986 $condHTML .= '<div class="dispaly-on field-wrap">';
1987 $condHTML .= $this->get_conditional_select_for_mw( 'mw_display_on', esc_html__( 'Show on', 'ocean-modal-window' ), false );
1988 $condHTML .= '</div>';
1989 }
1990 if ( ! empty( $display_on ) ) {
1991 foreach ( $display_on as $index => $dis_on ) {
1992 $condHTML .= '<div class="dispaly-on field-wrap">';
1993 $condHTML .= $this->get_conditional_select_for_mw( 'mw_display_on', esc_html__( 'Show on', 'ocean-modal-window' ), true, $dis_on, $index );
1994 $condHTML .= '</div>';
1995 }
1996 }
1997 $condHTML .= '</div>';
1998 $condHTML .= '<button type="button" class="display-on-add omw-btn" onClick="add_mw_display_on();"; >' . esc_html__( 'Add new row', 'ocean-modal-window' ) . '</button>';
1999 $condHTML .= '</div>';
2000 $condHTML .= '<script type="text/html" id="tmpl-dispaly-on-field">';
2001 $condHTML .= '<div class="dispaly-on field-wrap">';
2002 $condHTML .= $this->get_conditional_select_for_mw( 'mw_display_on', esc_html__( 'Show on', 'ocean-modal-window' ), true );
2003 $condHTML .= '</div>';
2004 $condHTML .= '</script>';
2005 $condHTML .= '<div class="condition-container hide-on container-wrap">';
2006 $condHTML .= '<div class="hide-on-fields hide-on-field">';
2007 if ( empty( $hide_on ) ) {
2008 $condHTML .= '<div class="hide-on field-wrap">';
2009 $condHTML .= $this->get_conditional_select_for_mw( 'mw_hide_on', esc_html__( 'Hide on', 'ocean-modal-window' ), false );
2010 $condHTML .= '</div>';
2011 }
2012
2013 if ( ! empty( $hide_on ) ) {
2014 foreach ( $hide_on as $index => $hid_on ) {
2015 $condHTML .= '<div class="hide-on field-wrap">';
2016 $condHTML .= $this->get_conditional_select_for_mw( 'mw_hide_on', esc_html__( 'Hide on', 'ocean-modal-window' ), true, $hid_on, $index );
2017 $condHTML .= '</div>';
2018 }
2019 }
2020 $condHTML .= '</div>';
2021 $condHTML .= '<button type="button" class="hide-on-add omw-btn" onClick="add_mw_hide_on();"; >' . esc_html__( 'Add new row', 'ocean-modal-window' ) . '</button>';
2022 $condHTML .= '</div>';
2023
2024 $condHTML .= '<script type="text/html" id="tmpl-hide-on-field">';
2025 $condHTML .= '<div class="hide-on field-wrap">';
2026 $condHTML .= $this->get_conditional_select_for_mw( 'mw_hide_on', esc_html__( 'Hide on', 'ocean-modal-window' ), true );
2027 $condHTML .= '</div>';
2028 $condHTML .= '</script>';
2029 $condHTML .= '</div>';
2030
2031 print_r(
2032 json_encode(
2033 array(
2034 'status' => true,
2035 'condHTML' => $condHTML,
2036 )
2037 )
2038 );
2039
2040 wp_die(); // this is required to terminate immediately and return a proper response
2041 }
2042
2043 /**
2044 * Get the conditional select.
2045 *
2046 * @since 2.1.0
2047 */
2048 public function get_conditional_select_for_mw( $condition_type, $label, $template = false, $selected_value = '', $show_remove_btn = true ) {
2049 ob_start(); ?>
2050
2051 <div class="label-wrap div-wrap">
2052 <span class="condition-arrow"></span>
2053 <label for="omw_rules[<?php echo $condition_type; ?>][]"><?php esc_html_e( $label, 'ocean-modal-window' ); ?></label>
2054 </div>
2055
2056 <div class="select-wrap div-wrap">
2057 <select name="omw_rules[<?php echo $condition_type; ?>][]" class="omw-select">
2058
2059 <option value="0"><?php esc_html_e( 'Please Select', 'ocean-modal-window' ); ?></option>
2060
2061 <optgroup label="Pages"></optgroup>
2062 <?php
2063 $pg_templates = $this->omw_get_page_templates();
2064 foreach ( $pg_templates['pages'] as $pg_funcs => $pg_template ) :
2065 ?>
2066 <option value="<?php echo $pg_funcs; ?>" <?php selected( $selected_value, $pg_funcs ); ?>>
2067 <?php echo $pg_template; ?>
2068 </option>
2069 <?php endforeach; ?>
2070
2071 <?php if ( isset( $pg_templates['shop'] ) ) : ?>
2072 <optgroup label="Shop"></optgroup>
2073 <?php
2074 foreach ( $pg_templates['shop'] as $pg_funcs => $pg_template ) :
2075 ?>
2076 <option value="<?php echo $pg_funcs; ?>" <?php selected( $selected_value, $pg_funcs ); ?>>
2077 <?php echo $pg_template; ?>
2078 </option>
2079 <?php endforeach; ?>
2080 <?php endif; ?>
2081
2082 <optgroup label="Other"></optgroup>
2083 <?php
2084 foreach ( $pg_templates['others'] as $pg_funcs => $pg_template ) :
2085 ?>
2086 <option value="<?php echo $pg_funcs; ?>" <?php selected( $selected_value, $pg_funcs ); ?>>
2087 <?php echo $pg_template; ?>
2088 </option>
2089 <?php endforeach; ?>
2090
2091 </select>
2092 </div>
2093
2094 <?php
2095 if ( $condition_type == 'mw_display_on' && $template && $show_remove_btn ) :
2096 ?>
2097 <div class="close-wrap div-wrap"><span class="dashicons dashicons-dismiss display-on-remove"></span></div>
2098 <?php
2099 endif;
2100 ?>
2101 <?php
2102 if ( $condition_type == 'mw_hide_on' && $template && $show_remove_btn ) :
2103 ?>
2104 <div class="close-wrap div-wrap"><span class="dashicons dashicons-dismiss hide-on-remove"></span></div>
2105 <?php
2106 endif;
2107
2108 return ob_get_clean();
2109 }
2110
2111 /**
2112 * Return WooCommerce specific pages
2113 *
2114 * @since 2.1.0
2115 */
2116 public function omw_get_woocommerce_pages() {
2117
2118 $shop_page_id = get_option( 'woocommerce_shop_page_id' );
2119 if ( $shop_page_id ) {
2120 $pg_templates['is_shop()'] = get_the_title( $shop_page_id );
2121 }
2122
2123 $pg_templates['is_product_category()'] = esc_html__( 'Product Category', 'ocean-modal-window' );
2124
2125 $pg_templates['is_product_tag()'] = esc_html__( 'Product Tag', 'ocean-modal-window' );
2126
2127 $pg_templates['is_product()'] = esc_html__( 'Single Product', 'ocean-modal-window' );
2128
2129 $shop_page_id = get_option( 'woocommerce_cart_page_id' );
2130 if ( $shop_page_id ) {
2131 $pg_templates[ 'is_page(' . $shop_page_id . ')' ] = get_the_title( $shop_page_id );
2132 }
2133
2134 $shop_page_id = get_option( 'woocommerce_checkout_page_id' );
2135 if ( $shop_page_id ) {
2136 $pg_templates[ 'is_page(' . $shop_page_id . ')' ] = get_the_title( $shop_page_id );
2137 }
2138
2139 $shop_page_id = get_option( 'woocommerce_pay_page_id' );
2140 if ( $shop_page_id ) {
2141 $pg_templates[ 'is_page(' . $shop_page_id . ')' ] = get_the_title( $shop_page_id );
2142 }
2143
2144 $shop_page_id = get_option( 'woocommerce_thanks_page_id' );
2145 if ( $shop_page_id ) {
2146 $pg_templates[ 'is_page(' . $shop_page_id . ')' ] = get_the_title( $shop_page_id );
2147 }
2148
2149 $shop_page_id = get_option( 'woocommerce_myaccount_page_id' );
2150 if ( $shop_page_id ) {
2151 $pg_templates[ 'is_page(' . $shop_page_id . ')' ] = get_the_title( $shop_page_id );
2152 }
2153
2154 $shop_page_id = get_option( 'woocommerce_edit_address_page_id' );
2155 if ( $shop_page_id ) {
2156 $pg_templates[ 'is_page(' . $shop_page_id . ')' ] = get_the_title( $shop_page_id );
2157 }
2158
2159 $shop_page_id = get_option( 'woocommerce_view_order_page_id' );
2160 if ( $shop_page_id ) {
2161 $pg_templates[ 'is_page(' . $shop_page_id . ')' ] = get_the_title( $shop_page_id );
2162 }
2163
2164 $shop_page_id = get_option( 'woocommerce_terms_page_id' );
2165 if ( $shop_page_id ) {
2166 $pg_templates[ 'is_page(' . $shop_page_id . ')' ] = get_the_title( $shop_page_id );
2167 }
2168
2169 return $pg_templates;
2170 }
2171
2172 /**
2173 * Get Templates
2174 *
2175 * @since 2.1.0
2176 */
2177 public function omw_get_page_templates() {
2178 $pg_templates['pages'] = array(
2179 'is_page()' => esc_html__( 'All Pages', 'ocean-modal-window' ),
2180 'is_home()' => esc_html__( 'Home Page ( is_home() )', 'ocean-modal-window' ),
2181 'is_front_page()' => esc_html__( 'Front Page ( is_front_page() )', 'ocean-modal-window' ),
2182 );
2183
2184 $pages = get_pages();
2185
2186 if ( ! empty( $pages ) ) {
2187 foreach ( $pages as $page ) {
2188 $pg_templates['pages'][ 'is_page(' . $page->ID . ')' ] = $page->post_title;
2189 }
2190 }
2191 $pg_templates['others'] = array(
2192 'is_single()' => esc_html__( 'Single Post', 'ocean-modal-window' ),
2193 'is_category()' => esc_html__( 'Category Page', 'ocean-modal-window' ),
2194 'is_archive()' => esc_html__( 'Archive Page', 'ocean-modal-window' ),
2195 'is_user_logged_in()' => esc_html__( 'Logged In User', 'ocean-modal-window' ),
2196 '!is_user_logged_in()' => esc_html__( 'Logged Out User', 'ocean-modal-window' ),
2197 );
2198
2199 // Getting Wocommerce specidic pages
2200 if ( class_exists( 'WooCommerce' ) ) {
2201 $pg_templates['shop'] = $this->omw_get_woocommerce_pages();
2202 }
2203
2204 return $pg_templates;
2205 }
2206
2207 /**
2208 * Save conditional rules added to modal window.
2209 */
2210 public function save_mw_conditions_rules( $mw_id ) {
2211 $post_type = get_post_type( $mw_id );
2212
2213 if ( 'ocean_modal_window' != $post_type ) {
2214 return;
2215 }
2216
2217 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
2218 return;
2219 }
2220
2221 // check if elementor
2222 $elementor = false;
2223 if ( isset( $_POST['action'] ) && $_POST['action'] == 'elementor_ajax' ) {
2224 $elementor = true;
2225 }
2226
2227 if ( isset( $_POST['butterbean_oceanwp_mw_settings_setting_oceanwp_mw_cond_logic'] ) && $_POST['butterbean_oceanwp_mw_settings_setting_oceanwp_mw_cond_logic'] ) {
2228 $display = array();
2229 $hide = array();
2230
2231 if ( isset( $_POST['omw_rules']['mw_display_on'] ) ) {
2232 foreach ( $_POST['omw_rules']['mw_display_on'] as $key => $displayCond ) {
2233 if ( $displayCond != '0' ) {
2234 $display[] = $displayCond;
2235 }
2236 }
2237 }
2238
2239 if ( isset( $_POST['omw_rules']['mw_hide_on'] ) ) {
2240 foreach ( $_POST['omw_rules']['mw_hide_on'] as $key => $hideCond ) {
2241 if ( $hideCond != '0' ) {
2242 $hide[] = $hideCond;
2243 }
2244 }
2245 }
2246
2247 update_post_meta( $mw_id, 'mw_display_on', $display );
2248 update_post_meta( $mw_id, 'mw_hide_on', $hide );
2249 }
2250 }
2251
2252 /**
2253 * Display open modal link in metabox
2254 *
2255 * @since 1.0.0
2256 */
2257 public function add_meta_box( $post ) {
2258
2259 add_meta_box(
2260 'oceanwp-mw-open-link-metabox',
2261 esc_html__( 'Modal Link', 'ocean-modal-window' ),
2262 array( $this, 'display_meta_box' ),
2263 'ocean_modal_window',
2264 'side',
2265 'low'
2266 );
2267
2268 }
2269
2270 /**
2271 * Display modal ID
2272 *
2273 * @since 1.0.0
2274 */
2275 public function display_meta_box( $post ) { ?>
2276
2277 <p><?php esc_html_e( 'This is the ID, class and the full link to open your modal.', 'ocean-modal-window' ); ?></p>
2278
2279 <h4 style="margin-bottom:5px;"><?php esc_html_e( 'Modal ID:', 'ocean-modal-window' ); ?></h4>
2280 <input type="text" class="widefat" value='#omw-<?php echo $post->ID; ?>' readonly />
2281
2282 <h4 style="margin-bottom:5px;"><?php esc_html_e( 'Link Class:', 'ocean-modal-window' ); ?></h4>
2283 <input type="text" class="widefat" value='omw-open-modal' readonly />
2284
2285 <h4 style="margin-bottom:5px;"><?php esc_html_e( 'Full Link:', 'ocean-modal-window' ); ?></h4>
2286 <input type="text" class="widefat" value='<a href="#omw-<?php echo $post->ID; ?>" class="omw-open-modal">Open Modal</a>' readonly />
2287
2288 <?php
2289 }
2290
2291 /**
2292 * Loads Google fonts
2293 *
2294 * @since 1.0.0
2295 */
2296 public function load_fonts() {
2297
2298 $query = new WP_Query(
2299 array(
2300 'post_type' => 'ocean_modal_window',
2301 'posts_per_page' => -1,
2302 )
2303 );
2304
2305 if ( $query->have_posts() ) :
2306
2307 while ( $query->have_posts() ) :
2308 $query->the_post();
2309
2310 // Get fonts
2311 $fonts = array();
2312 $val = get_theme_mod( 'omw_font_family' );
2313 if ( $meta = get_post_meta( get_the_ID(), 'oceanwp_mw_font_family', true ) ) {
2314 $val = $meta;
2315 }
2316
2317 // If there is a value lets do something
2318 if ( $val ) {
2319
2320 // Sanitize
2321 $val = str_replace( '"', '', $val );
2322
2323 $fonts[] = $val;
2324
2325 }
2326
2327 // Loop through and enqueue fonts
2328 if ( ! empty( $fonts ) && is_array( $fonts ) ) {
2329 foreach ( $fonts as $font ) {
2330 oceanwp_enqueue_google_font( $font );
2331 }
2332 }
2333
2334 endwhile;
2335
2336 wp_reset_postdata();
2337
2338 endif;
2339
2340 }
2341
2342 /**
2343 * Register translation strings
2344 *
2345 * @param string $strings Plugin strings.
2346 */
2347 public static function register_omw_strings( $strings ) {
2348
2349 $strings['omw-close-button-anchor'] = apply_filters( 'omw_close_button_anchor',_x( 'modal-window-close', 'Used for creation of SEO friendly anchor links. Do not use spaces or pound keys.', 'ocean-modal-window' ) );
2350
2351 return $strings;
2352
2353 }
2354
2355 /**
2356 * Return SEO-friendly (crawlable) and accessibility-friendly (not redundant) links
2357 *
2358 * @since 2.2.1
2359 */
2360 public function omw_get_site_name_anchors( $content = '' ) {
2361 $result = '';
2362 $site_url = esc_url( home_url( '/#' ) );
2363
2364 if ( $content && ! is_customize_preview() ) {
2365 $result = $site_url . $content;
2366 } else {
2367 $result = '#';
2368 }
2369
2370 $result = apply_filters( 'omw_get_site_name_anchors', $result );
2371
2372 return $result;
2373 }
2374
2375 /**
2376 * Display the modal in the footer
2377 *
2378 * @since 1.0.0
2379 */
2380 public function modal_display() {
2381
2382 if (is_admin()) {
2383 return;
2384 }
2385
2386 $meta_modal = get_post_meta( oceanwp_post_id(), 'omw_enable_modal_window', true );
2387
2388 // If Modal Window disabled
2389 if ( 'disable' === $meta_modal ) {
2390 return;
2391 }
2392
2393 $query = new WP_Query(
2394 array(
2395 'post_type' => 'ocean_modal_window',
2396 'posts_per_page' => -1,
2397 )
2398 );
2399
2400 // SEO link txt.
2401 $anchorlink_text = esc_html( oceanwp_theme_strings( 'omw-close-button-anchor', false ) );
2402
2403 if ( $query->have_posts() ) :
2404
2405 while ( $query->have_posts() ) :
2406 $query->the_post();
2407
2408 $status = true;
2409
2410 // Get the template
2411 $templates = get_post_meta( get_the_ID(), 'oceanwp_mw_template', true );
2412 $templates = $templates ? $templates : '';
2413
2414 // Vars
2415 $title = get_post_meta( get_the_ID(), 'oceanwp_mw_title', true );
2416 $title = $title ? $title : 'off';
2417 $title_tag = get_post_meta( get_the_ID(), 'oceanwp_mw_title_tag', true );
2418 $title_tag = $title_tag ? $title_tag : 'h2';
2419 $close_btn = get_post_meta( get_the_ID(), 'oceanwp_mw_close_btn', true );
2420 $close_btn = $close_btn ? $close_btn : 'on';
2421
2422 $is_conds_logic = get_post_meta( get_the_ID(), 'oceanwp_mw_cond_logic', true );
2423 $display_conds = get_post_meta( get_the_ID(), 'mw_display_on', true );
2424 $hide_conds = get_post_meta( get_the_ID(), 'mw_hide_on', true );
2425
2426 if ( ! empty( $is_conds_logic ) && ! empty( $display_conds ) && is_array( $display_conds ) ) {
2427 $display_pages_cond = implode( ' || ', $display_conds );
2428 $is_template_matched = false;
2429 if ( function_exists( 'omw_match_conditions' ) ) {
2430 $is_template_matched = omw_match_conditions( $display_pages_cond );
2431 }
2432
2433 if ( ! $is_template_matched ) {
2434 $status = false;
2435 }
2436 }
2437
2438 if ( ! empty( $is_conds_logic ) && ! empty( $hide_conds ) && is_array( $hide_conds ) ) {
2439 $hidden_pages_cond = implode( ' || ', $hide_conds );
2440 $is_template_matched = false;
2441 if ( function_exists( 'omw_match_conditions' ) ) {
2442 $is_template_matched = omw_match_conditions( $hidden_pages_cond );
2443 }
2444
2445 if ( $is_template_matched ) {
2446 $status = false;
2447 }
2448 }
2449
2450 if ( $status === false ) {
2451 continue;
2452 }
2453
2454 ?>
2455
2456 <div id="omw-<?php echo esc_attr( get_the_ID() ); ?>" class="omw-modal">
2457
2458 <?php
2459 // Title
2460 if ( 'on' == $title ) {
2461 ?>
2462 <<?php echo esc_attr( $title_tag ); ?> class="omw-modal-title"><?php the_title(); ?></<?php echo esc_attr( $title_tag ); ?>>
2463 <?php
2464 }
2465
2466 // Close button
2467 if ( 'on' == $close_btn ) {
2468 ?>
2469 <a href="<?php echo esc_url( $this->omw_get_site_name_anchors( $anchorlink_text ) ); ?>" class="omw-close-modal"></a>
2470 <?php } ?>
2471
2472 <div class="omw-modal-inner clr">
2473 <?php
2474 // Display content
2475 if ( ! empty( $templates ) ) {
2476 include $this->plugin_path . 'template/template.php';
2477 } else {
2478 the_content();
2479 }
2480 ?>
2481 </div>
2482 </div>
2483
2484 <?php
2485 // Styling vars
2486 $modal_width = get_post_meta( get_the_ID(), 'oceanwp_mw_width', true );
2487 $modal_height = get_post_meta( get_the_ID(), 'oceanwp_mw_height', true );
2488 $modal_img = get_post_meta( get_the_ID(), 'oceanwp_mw_background_image', true );
2489 $modal_padding = get_post_meta( get_the_ID(), 'oceanwp_mw_padding', true );
2490 $modal_border = get_post_meta( get_the_ID(), 'oceanwp_mw_border', true );
2491 $modal_border_style = get_post_meta( get_the_ID(), 'oceanwp_mw_border_style', true );
2492 $modal_border_color = get_post_meta( get_the_ID(), 'oceanwp_mw_border_color', true );
2493 $modal_border_radius = get_post_meta( get_the_ID(), 'oceanwp_mw_border_radius', true );
2494 $overlay_bg = get_post_meta( get_the_ID(), 'oceanwp_mw_overlay_bg_color', true );
2495 $overlay_opacity = get_post_meta( get_the_ID(), 'oceanwp_mw_overlay_opacity', true );
2496 $modal_bg = get_post_meta( get_the_ID(), 'oceanwp_mw_bg_color', true );
2497 $modal_color = get_post_meta( get_the_ID(), 'oceanwp_mw_text_color', true );
2498 $title_color = get_post_meta( get_the_ID(), 'oceanwp_mw_title_color', true );
2499 $close_btn_bg = get_post_meta( get_the_ID(), 'oceanwp_mw_close_btn_bg', true );
2500 $close_btn_hover_bg = get_post_meta( get_the_ID(), 'oceanwp_mw_close_btn_hover_bg', true );
2501 $close_btn_color = get_post_meta( get_the_ID(), 'oceanwp_mw_close_btn_color', true );
2502 $close_btn_hover_color = get_post_meta( get_the_ID(), 'oceanwp_mw_close_btn_hover_color', true );
2503 $font_size = get_post_meta( get_the_ID(), 'oceanwp_mw_font_size', true );
2504 $font_size_unit = get_post_meta( get_the_ID(), 'oceanwp_mw_font_size_unit', true );
2505 $font_family = get_post_meta( get_the_ID(), 'oceanwp_mw_font_family', true );
2506 $font_weight = get_post_meta( get_the_ID(), 'oceanwp_mw_font_weight', true );
2507 $text_transform = get_post_meta( get_the_ID(), 'oceanwp_mw_text_transform', true );
2508 $line_height = get_post_meta( get_the_ID(), 'oceanwp_mw_line_height', true );
2509 $line_height_unit = get_post_meta( get_the_ID(), 'oceanwp_mw_line_height_unit', true );
2510 $letter_spacing = get_post_meta( get_the_ID(), 'oceanwp_mw_letter_spacing', true );
2511 $letter_spacing_unit = get_post_meta( get_the_ID(), 'oceanwp_mw_letter_spacing_unit', true );
2512
2513 // Responsive
2514 $tablet_modal_width = get_post_meta( get_the_ID(), 'oceanwp_mw_tablet_width', true );
2515 $tablet_modal_height = get_post_meta( get_the_ID(), 'oceanwp_mw_tablet_height', true );
2516 $tablet_modal_padding = get_post_meta( get_the_ID(), 'oceanwp_mw_tablet_padding', true );
2517 $tablet_font_size = get_post_meta( get_the_ID(), 'oceanwp_mw_tablet_font_size', true );
2518 $tablet_font_weight = get_post_meta( get_the_ID(), 'oceanwp_mw_font_weight_tablet', true );
2519 $tablet_text_transform = get_post_meta( get_the_ID(), 'oceanwp_mw_text_transform_tablet', true );
2520 $tablet_line_height = get_post_meta( get_the_ID(), 'oceanwp_mw_tablet_line_height', true );
2521 $tablet_letter_spacing = get_post_meta( get_the_ID(), 'oceanwp_mw_tablet_letter_spacing', true );
2522 $mobile_modal_width = get_post_meta( get_the_ID(), 'oceanwp_mw_mobile_width', true );
2523 $mobile_modal_height = get_post_meta( get_the_ID(), 'oceanwp_mw_mobile_height', true );
2524 $mobile_modal_padding = get_post_meta( get_the_ID(), 'oceanwp_mw_mobile_padding', true );
2525 $mobile_font_size = get_post_meta( get_the_ID(), 'oceanwp_mw_mobile_font_size', true );
2526 $tablet_font_weight = get_post_meta( get_the_ID(), 'oceanwp_mw_font_weight_mobile'. true );
2527 $mobile_text_transform = get_post_meta( get_the_ID(), 'oceanwp_mw_text_transform_mobile', true );
2528 $mobile_line_height = get_post_meta( get_the_ID(), 'oceanwp_mw_mobile_line_height', true );
2529 $mobile_letter_spacing = get_post_meta( get_the_ID(), 'oceanwp_mw_mobile_letter_spacing', true );
2530
2531 // Define css var
2532 $css = '';
2533 $main_css = '';
2534 $typo_css = '';
2535 $overlay_css = '';
2536 $tablet_css = '';
2537 $mobile_css = '';
2538
2539 // Add modal width
2540 if ( ! empty( $modal_width ) && '700' != $modal_width ) {
2541 $main_css .= 'width:' . $modal_width . 'px;';
2542 }
2543
2544 // Add modal height
2545 if ( ! empty( $modal_height ) && '0' != $modal_height ) {
2546 $main_css .= 'height:' . $modal_height . 'px;';
2547 }
2548
2549 // Add modal background image
2550 if ( ! empty( $modal_img ) ) {
2551
2552 // Generate image URL from ID
2553 if ( is_numeric( $modal_img ) ) {
2554 $modal_img = wp_get_attachment_image_src( $modal_img, 'full' );
2555 $modal_img = $modal_img[0];
2556 }
2557
2558 $modal_img = $modal_img ? $modal_img : null;
2559
2560 $main_css .= 'background-image: url(' . $modal_img . '); background-position: center center; background-repeat: no-repeat; background-size: cover;';
2561 }
2562
2563 // Add modal padding
2564 if ( ! empty( $modal_padding ) ) {
2565 $main_css .= 'padding:' . $modal_padding . ';';
2566 }
2567
2568 // Add modal border
2569 if ( ! empty( $modal_border ) ) {
2570
2571 // Add modal border width
2572 $main_css .= 'border-width:' . $modal_border . ';';
2573
2574 // Add modal border style if border is defined
2575 if ( ! empty( $modal_border_style ) ) {
2576 $main_css .= 'border-style:' . $modal_border_style . ';';
2577 }
2578
2579 // Add modal border color if border is defined
2580 if ( ! empty( $modal_border_color ) ) {
2581 $main_css .= 'border-color:' . $modal_border_color . ';';
2582 }
2583 }
2584
2585 // Add modal border radius
2586 if ( ! empty( $modal_border_radius ) ) {
2587 $main_css .= 'border-radius:' . $modal_border_radius . ';';
2588 }
2589
2590 // Add modal background
2591 if ( ! empty( $modal_bg ) && '#ffffff' != $modal_bg ) {
2592 $main_css .= 'background-color:' . $modal_bg . ';';
2593 }
2594
2595 // Add modal text color
2596 if ( ! empty( $modal_color ) ) {
2597 $main_css .= 'color:' . $modal_color . ';';
2598 }
2599
2600 // Main css
2601 if ( ! empty( $modal_width ) && '700' != $modal_width
2602 || ! empty( $modal_height ) && '0' != $modal_height
2603 || ! empty( $modal_img )
2604 || ! empty( $modal_padding )
2605 || ! empty( $modal_border )
2606 || ! empty( $modal_border ) && ! empty( $modal_border_style )
2607 || ! empty( $modal_border ) && ! empty( $modal_border_color )
2608 || ! empty( $modal_border_radius )
2609 || ! empty( $modal_bg ) && '#ffffff' != $modal_bg
2610 || ! empty( $modal_color ) ) {
2611 $css .= '#omw-' . esc_attr( get_the_ID() ) . '{' . $main_css . '}';
2612 }
2613
2614 // Add modal font size
2615 if ( ! empty( $font_size && '0' != $font_size ) ) {
2616 $typo_css .= 'font-size:' . $font_size . $font_size_unit . ';';
2617 }
2618
2619 // Add modal font family
2620 if ( ! empty( $font_family ) ) {
2621 $typo_css .= 'font-family:' . $font_family . ';';
2622 }
2623
2624 // Add modal font weight
2625 if ( ! empty( $font_weight ) ) {
2626 $typo_css .= 'font-weight:' . $font_weight . ';';
2627 }
2628
2629 // Add modal text transform
2630 if ( ! empty( $text_transform ) ) {
2631 $typo_css .= 'text-transform:' . $text_transform . ';';
2632 }
2633
2634 // Add modal line height
2635 if ( ! empty( $line_height && '0' != $line_height ) ) {
2636 $typo_css .= 'line-height:' . $line_height . $line_height_unit . ';';
2637 }
2638
2639 // Add modal letter spacing
2640 if ( ! empty( $letter_spacing && '0' != $letter_spacing ) ) {
2641 $typo_css .= 'letter-spacing:' . $letter_spacing . $letter_spacing_unit . ';';
2642 }
2643
2644 // Typography css
2645 if ( ! empty( $font_size )
2646 || ! empty( $font_family )
2647 || ! empty( $font_weight )
2648 || ! empty( $font_style )
2649 || ! empty( $text_transform )
2650 || ! empty( $line_height )
2651 || ! empty( $letter_spacing ) ) {
2652 $css .= '#omw-' . esc_attr( get_the_ID() ) . '{' . $typo_css . '}';
2653 }
2654
2655 // Add overlay background
2656 if ( ! empty( $overlay_bg ) && '#000000' != $overlay_bg ) {
2657 $overlay_css .= 'background-color:' . $overlay_bg . '!important;';
2658 }
2659
2660 // Add overlay opacity
2661 if ( ! empty( $overlay_opacity ) && '0.9' != $overlay_opacity ) {
2662 $overlay_css .= 'opacity:' . $overlay_opacity . ' !important;';
2663 }
2664
2665 // Overlay css
2666 if ( ! empty( $overlay_bg ) && '#000000' != $overlay_bg
2667 || ! empty( $overlay_opacity ) && '0.9' != $overlay_opacity ) {
2668 $css .= 'body.omw-' . esc_attr( get_the_ID() ) . ' .omw-modal-overlay{' . $overlay_css . '}';
2669 }
2670
2671 // Add title color
2672 if ( ! empty( $title_color ) && '#333333' != $title_color ) {
2673 $css .= '#omw-' . esc_attr( get_the_ID() ) . ' .omw-modal-title{color:' . $title_color . ';}';
2674 }
2675
2676 // Add close button background color
2677 if ( ! empty( $close_btn_bg ) ) {
2678 $css .= '#omw-' . esc_attr( get_the_ID() ) . ' .omw-close-modal{background-color:' . $close_btn_bg . ';}';
2679 }
2680
2681 // Add close button hover background color
2682 if ( ! empty( $close_btn_hover_bg ) ) {
2683 $css .= '#omw-' . esc_attr( get_the_ID() ) . ' .omw-close-modal:hover{background-color:' . $close_btn_hover_bg . ';}';
2684 }
2685
2686 // Add close button color
2687 if ( ! empty( $close_btn_color ) ) {
2688 $css .= '#omw-' . esc_attr( get_the_ID() ) . ' .omw-close-modal:before,#omw-' . esc_attr( get_the_ID() ) . ' .omw-close-modal:after{background-color:' . $close_btn_color . ';}';
2689 }
2690
2691 // Add close button hover color
2692 if ( ! empty( $close_btn_hover_color ) ) {
2693 $css .= '#omw-' . esc_attr( get_the_ID() ) . ' .omw-close-modal:hover:before,#omw-' . esc_attr( get_the_ID() ) . ' .omw-close-modal:hover:after{background-color:' . $close_btn_hover_color . ';}';
2694 }
2695
2696 // Tablet modal width
2697 if ( ! empty( $tablet_modal_width ) && '700' != $tablet_modal_width ) {
2698 $tablet_css .= 'width:' . $tablet_modal_width . 'px;';
2699 }
2700
2701 // Tablet modal height
2702 if ( ! empty( $tablet_modal_height ) && '0' != $tablet_modal_height ) {
2703 $tablet_css .= 'height:' . $tablet_modal_height . 'px;';
2704 }
2705
2706 // Tablet modal padding
2707 if ( ! empty( $tablet_modal_padding ) ) {
2708 $tablet_css .= 'padding:' . $tablet_modal_padding . ';';
2709 }
2710
2711 // Tablet modal font size
2712 if ( ! empty( $tablet_font_size && '0' != $tablet_font_size ) ) {
2713 $tablet_css .= 'font-size:' . $tablet_font_size . $font_size_unit . ';';
2714 }
2715
2716 // Tablet modal text transform
2717 if ( ! empty( $tablet_text_transform ) ) {
2718 $tablet_css .= 'text-transform:' . $tablet_text_transform . ';';
2719 }
2720
2721 // Tablet modal line height
2722 if ( ! empty( $tablet_line_height && '0' != $tablet_line_height ) ) {
2723 $tablet_css .= 'line-height:' . $tablet_line_height . $line_height_unit . ';';
2724 }
2725
2726 // Tablet modal letter spacing
2727 if ( ! empty( $tablet_letter_spacing && '0' != $tablet_letter_spacing ) ) {
2728 $tablet_css .= 'letter-spacing:' . $tablet_letter_spacing . $letter_spacing_unit . ';';
2729 }
2730
2731 // Responsive tablet
2732 if ( ! empty( $tablet_modal_width ) && '700' != $tablet_modal_width
2733 || ! empty( $tablet_modal_height ) && '0' != $tablet_modal_height
2734 || ! empty( $tablet_modal_padding )
2735 || ! empty( $tablet_font_size )
2736 || ! empty( $tablet_line_height )
2737 || ! empty( $tablet_letter_spacing ) ) {
2738 $css .= '@media (max-width: 1023px) {#omw-' . esc_attr( get_the_ID() ) . '{' . $tablet_css . '}}';
2739 }
2740
2741 // Mobile modal width
2742 if ( ! empty( $mobile_modal_width ) && '700' != $mobile_modal_width ) {
2743 $mobile_css .= 'width:' . $mobile_modal_width . 'px;';
2744 }
2745
2746 // Mobile modal height
2747 if ( ! empty( $mobile_modal_height ) && '0' != $mobile_modal_height ) {
2748 $mobile_css .= 'height:' . $mobile_modal_height . 'px;';
2749 }
2750
2751 // Mobile modal padding
2752 if ( ! empty( $mobile_modal_padding ) ) {
2753 $mobile_css .= 'padding:' . $mobile_modal_padding . ';';
2754 }
2755
2756 // Mobile modal font size
2757 if ( ! empty( $mobile_font_size ) && '0' != $mobile_font_size ) {
2758 $mobile_css .= 'font-size:' . $mobile_font_size . $font_size_unit . ';';
2759 }
2760
2761 // Mobile modal text transform
2762 if ( ! empty( $mobile_text_transform ) ) {
2763 $mobile_css .= 'text-transform:' . $mobile_text_transform . ';';
2764 }
2765
2766 // Mobile modal line height
2767 if ( ! empty( $mobile_line_height ) && '0' != $mobile_line_height ) {
2768 $mobile_css .= 'line-height:' . $mobile_line_height . $line_height_unit . ';';
2769 }
2770
2771 // Mobile modal letter spacing
2772 if ( ! empty( $mobile_letter_spacing ) && '0' != $mobile_letter_spacing ) {
2773 $mobile_css .= 'letter-spacing:' . $mobile_letter_spacing . $letter_spacing_unit . ';';
2774 }
2775
2776 // Responsive mobile
2777 if ( ! empty( $mobile_modal_width ) && '700' != $mobile_modal_width
2778 || ! empty( $mobile_modal_height ) && '0' != $mobile_modal_height
2779 || ! empty( $mobile_modal_padding )
2780 || ! empty( $mobile_font_size )
2781 || ! empty( $mobile_line_height )
2782 || ! empty( $mobile_letter_spacing ) ) {
2783 $css .= '@media (max-width: 767px) {#omw-' . esc_attr( get_the_ID() ) . '{' . $mobile_css . '}}';
2784 }
2785
2786 if ( ! empty( $css ) ) {
2787 ?>
2788
2789 <style type="text/css"><?php echo wp_strip_all_tags( oceanwp_minify_css( $css ) ); ?></style>
2790
2791 <?php
2792 }
2793
2794 endwhile;
2795
2796 // Overlay
2797 ?>
2798 <div class="omw-modal-overlay"></div>
2799
2800 <?php
2801 wp_reset_postdata();
2802
2803 endif;
2804
2805 }
2806
2807 /**
2808 * Add css in head tag.
2809 *
2810 * @since 1.0.0
2811 */
2812 public function head_css( $output ) {
2813
2814 // Styling vars
2815 $modal_width = get_theme_mod( 'omw_custom_width', '700' );
2816 $modal_width_unit = get_theme_mod( 'omw_custom_width_unit', 'px' );
2817 $modal_height = get_theme_mod( 'omw_custom_height', '0' );
2818 $modal_height_unit = get_theme_mod( 'omw_custom_height_unit', 'px' );
2819 $modal_img = get_theme_mod( 'omw_background_image' );
2820 $modal_padding = get_theme_mod( 'omw_padding' );
2821 $modal_border = get_theme_mod( 'omw_border_width' );
2822 $modal_border_style = get_theme_mod( 'omw_border_type' );
2823 $modal_border_color = get_theme_mod( 'omw_modal_border_color' );
2824 $modal_border_radius = get_theme_mod( 'omw_border_radius' );
2825 $overlay_bg = get_theme_mod( 'omw_overlay_bg', '#000000' );
2826 $overlay_opacity = get_theme_mod( 'omw_overlay_opacity', '0.9' );
2827 $modal_bg = get_theme_mod( 'omw_modal_bg', '#ffffff' );
2828 $modal_color = get_theme_mod( 'omw_modal_text_color' );
2829 $title_color = get_theme_mod( 'omw_modal_title_color', '#333333' );
2830 $close_btn_bg = get_theme_mod( 'omw_modal_close_btn_bg' );
2831 $close_btn_hover_bg = get_theme_mod( 'omw_modal_close_btn_hover_bg' );
2832 $close_btn_color = get_theme_mod( 'omw_modal_close_btn_color' );
2833 $close_btn_hover_color = get_theme_mod( 'omw_modal_close_btn_hover_color' );
2834 $font_size = get_theme_mod( 'omw_font_size' );
2835 $font_family = get_theme_mod( 'omw_font_family' );
2836 $font_weight = get_theme_mod( 'omw_font_weight' );
2837 $font_style = get_theme_mod( 'omw_font_style' );
2838 $text_transform = get_theme_mod( 'omw_text_transform' );
2839 $line_height = get_theme_mod( 'omw_line_height' );
2840 $letter_spacing = get_theme_mod( 'omw_letter_spacing' );
2841
2842 // Responsive
2843 $tablet_modal_width = get_theme_mod( 'omw_tablet_custom_width', '700' );
2844 $tablet_modal_height = get_theme_mod( 'omw_tablet_custom_height', '0' );
2845 $tablet_modal_padding = get_theme_mod( 'omw_tablet_padding' );
2846 $tablet_font_size = get_theme_mod( 'omw_tablet_font_size' );
2847 $tablet_line_height = get_theme_mod( 'omw_tablet_line_height' );
2848 $tablet_letter_spacing = get_theme_mod( 'omw_tablet_letter_spacing' );
2849 $mobile_modal_width = get_theme_mod( 'omw_mobile_custom_width', '700' );
2850 $mobile_modal_height = get_theme_mod( 'omw_mobile_custom_height', '0' );
2851 $mobile_modal_padding = get_theme_mod( 'omw_mobile_padding' );
2852 $mobile_font_size = get_theme_mod( 'omw_mobile_font_size' );
2853 $mobile_line_height = get_theme_mod( 'omw_mobile_line_height' );
2854 $mobile_letter_spacing = get_theme_mod( 'omw_mobile_letter_spacing' );
2855
2856 // Define css var
2857 $css = '';
2858 $main_css = '';
2859 $typo_css = '';
2860 $overlay_css = '';
2861 $tablet_css = '';
2862 $mobile_css = '';
2863
2864 // Add modal width
2865 if ( ! empty( $modal_width ) && 700 != $modal_width ) {
2866 $main_css .= 'width:' . $modal_width . $modal_width_unit . ';';
2867 }
2868
2869 // Add modal height
2870 if ( ! empty( $modal_height ) && 0 != $modal_height ) {
2871 $main_css .= 'height:' . $modal_height . $modal_height_unit . ';';
2872 }
2873
2874 // Add modal background image
2875 if ( ! empty( $modal_img ) ) {
2876
2877 // Generate image URL from ID
2878 if ( is_numeric( $modal_img ) ) {
2879 $modal_img = wp_get_attachment_image_src( $modal_img, 'full' );
2880 $modal_img = $modal_img[0];
2881 }
2882
2883 $modal_img = $modal_img ? $modal_img : null;
2884
2885 $main_css .= 'background-image: url(' . $modal_img . '); background-position: center center; background-repeat: no-repeat; background-size: cover;';
2886 }
2887
2888 // Add modal padding
2889 if ( ! empty( $modal_padding ) ) {
2890 $main_css .= 'padding:' . $modal_padding . ';';
2891 }
2892
2893 // Add modal border
2894 if ( ! empty( $modal_border ) ) {
2895
2896 // Add modal border width
2897 $main_css .= 'border-width:' . $modal_border . ';';
2898
2899 // Add modal border style if border is defined
2900 if ( ! empty( $modal_border_style ) ) {
2901 $main_css .= 'border-style:' . $modal_border_style . ';';
2902 }
2903
2904 // Add modal border color if border is defined
2905 if ( ! empty( $modal_border_color ) ) {
2906 $main_css .= 'border-color:' . $modal_border_color . ';';
2907 }
2908 }
2909
2910 // Add modal border radius
2911 if ( ! empty( $modal_border_radius ) ) {
2912 $main_css .= 'border-radius:' . $modal_border_radius . ';';
2913 }
2914
2915 // Add modal background
2916 if ( ! empty( $modal_bg ) && '#ffffff' != $modal_bg ) {
2917 $main_css .= 'background-color:' . $modal_bg . ';';
2918 }
2919
2920 // Add modal text color
2921 if ( ! empty( $modal_color ) ) {
2922 $main_css .= 'color:' . $modal_color . ';';
2923 }
2924
2925 // Main css
2926 if ( ! empty( $modal_width ) && '700' != $modal_width
2927 || ! empty( $modal_height ) && '0' != $modal_height
2928 || ! empty( $modal_img )
2929 || ! empty( $modal_padding )
2930 || ! empty( $modal_border )
2931 || ! empty( $modal_border ) && ! empty( $modal_border_style )
2932 || ! empty( $modal_border ) && ! empty( $modal_border_color )
2933 || ! empty( $modal_border_radius )
2934 || ! empty( $modal_bg ) && '#ffffff' != $modal_bg
2935 || ! empty( $modal_color ) ) {
2936 $css .= '.omw-modal{' . $main_css . '}';
2937 }
2938
2939 // Add modal font size
2940 if ( ! empty( $font_size ) ) {
2941 $typo_css .= 'font-size:' . $font_size . ';';
2942 }
2943
2944 // Add modal font family
2945 if ( ! empty( $font_family ) ) {
2946 $typo_css .= 'font-family:' . $font_family . ';';
2947 }
2948
2949 // Add modal font weight
2950 if ( ! empty( $font_weight ) ) {
2951 $typo_css .= 'font-weight:' . $font_weight . ';';
2952 }
2953
2954 // Add modal font style
2955 if ( ! empty( $font_style ) ) {
2956 $typo_css .= 'font-style:' . $font_style . ';';
2957 }
2958
2959 // Add modal text transform
2960 if ( ! empty( $text_transform ) ) {
2961 $typo_css .= 'text-transform:' . $text_transform . ';';
2962 }
2963
2964 // Add modal line height
2965 if ( ! empty( $line_height ) ) {
2966 $typo_css .= 'line-height:' . $line_height . ';';
2967 }
2968
2969 // Add modal letter spacing
2970 if ( ! empty( $letter_spacing ) ) {
2971 $typo_css .= 'letter-spacing:' . $letter_spacing . ';';
2972 }
2973
2974 // Typography css
2975 if ( ! empty( $font_size )
2976 || ! empty( $font_family )
2977 || ! empty( $font_weight )
2978 || ! empty( $font_style )
2979 || ! empty( $text_transform )
2980 || ! empty( $line_height )
2981 || ! empty( $letter_spacing ) ) {
2982 $css .= '.omw-modal{' . $typo_css . '}';
2983 }
2984
2985 // Add overlay background
2986 if ( ! empty( $overlay_bg ) && '#000000' != $overlay_bg ) {
2987 $overlay_css .= 'background-color:' . $overlay_bg . ';';
2988 }
2989
2990 // Add overlay opacity
2991 if ( ! empty( $overlay_opacity ) && '0.9' != $overlay_opacity ) {
2992 $overlay_css .= 'opacity:' . $overlay_opacity . ';';
2993 }
2994
2995 // Overlay css
2996 if ( ! empty( $overlay_bg ) && '#000000' != $overlay_bg
2997 || ! empty( $overlay_opacity ) && '0.9' != $overlay_opacity ) {
2998 $css .= '.omw-modal-overlay{' . $overlay_css . '}';
2999 }
3000
3001 // Add title color
3002 if ( ! empty( $title_color ) && '#333333' != $title_color ) {
3003 $css .= '.omw-modal .omw-modal-title{color:' . $title_color . ';}';
3004 }
3005
3006 // Add close button background color
3007 if ( ! empty( $close_btn_bg ) ) {
3008 $css .= '.omw-modal .omw-close-modal{background-color:' . $close_btn_bg . ';}';
3009 }
3010
3011 // Add close button hover background color
3012 if ( ! empty( $close_btn_hover_bg ) ) {
3013 $css .= '.omw-modal .omw-close-modal:hover{background-color:' . $close_btn_hover_bg . ';}';
3014 }
3015
3016 // Add close button color
3017 if ( ! empty( $close_btn_color ) ) {
3018 $css .= '.omw-modal .omw-close-modal:before,.omw-modal .omw-close-modal:after{background-color:' . $close_btn_color . ';}';
3019 }
3020
3021 // Add close button hover color
3022 if ( ! empty( $close_btn_hover_color ) ) {
3023 $css .= '.omw-modal .omw-close-modal:hover:before,.omw-modal .omw-close-modal:hover:after{background-color:' . $close_btn_hover_color . ';}';
3024 }
3025
3026 // Tablet modal width
3027 if ( ! empty( $tablet_modal_width ) && '700' != $tablet_modal_width ) {
3028 $tablet_css .= 'width:' . $tablet_modal_width . 'px;';
3029 }
3030
3031 // Tablet modal height
3032 if ( ! empty( $tablet_modal_height ) && '0' != $tablet_modal_height ) {
3033 $tablet_css .= 'height:' . $tablet_modal_height . 'px;';
3034 }
3035
3036 // Tablet modal padding
3037 if ( ! empty( $tablet_modal_padding ) ) {
3038 $tablet_css .= 'padding:' . $tablet_modal_padding . ';';
3039 }
3040
3041 // Tablet modal font size
3042 if ( ! empty( $tablet_font_size ) ) {
3043 $tablet_css .= 'font-size:' . $tablet_font_size . ';';
3044 }
3045
3046 // Tablet modal line height
3047 if ( ! empty( $tablet_line_height ) ) {
3048 $tablet_css .= 'line-height:' . $tablet_line_height . ';';
3049 }
3050
3051 // Tablet modal letter spacing
3052 if ( ! empty( $tablet_letter_spacing ) ) {
3053 $tablet_css .= 'letter-spacing:' . $tablet_letter_spacing . ';';
3054 }
3055
3056 // Responsive tablet
3057 if ( ! empty( $tablet_modal_width ) && '700' != $tablet_modal_width
3058 || ! empty( $tablet_modal_height ) && '0' != $tablet_modal_height
3059 || ! empty( $tablet_modal_padding )
3060 || ! empty( $tablet_font_size )
3061 || ! empty( $tablet_line_height )
3062 || ! empty( $tablet_letter_spacing ) ) {
3063 $css .= '@media (max-width: 1023px) {.omw-modal{' . $tablet_css . '}}';
3064 }
3065
3066 // Mobile modal width
3067 if ( ! empty( $mobile_modal_width ) && '700' != $mobile_modal_width ) {
3068 $mobile_css .= 'width:' . $mobile_modal_width . 'px;';
3069 }
3070
3071 // Mobile modal height
3072 if ( ! empty( $mobile_modal_height ) && '0' != $mobile_modal_height ) {
3073 $mobile_css .= 'height:' . $mobile_modal_height . 'px;';
3074 }
3075
3076 // Mobile modal padding
3077 if ( ! empty( $mobile_modal_padding ) ) {
3078 $mobile_css .= 'padding:' . $mobile_modal_padding . ';';
3079 }
3080
3081 // Mobile modal font size
3082 if ( ! empty( $mobile_font_size ) ) {
3083 $mobile_css .= 'font-size:' . $mobile_font_size . ';';
3084 }
3085
3086 // Mobile modal line height
3087 if ( ! empty( $mobile_line_height ) ) {
3088 $mobile_css .= 'line-height:' . $mobile_line_height . ';';
3089 }
3090
3091 // Mobile modal letter spacing
3092 if ( ! empty( $mobile_letter_spacing ) ) {
3093 $mobile_css .= 'letter-spacing:' . $mobile_letter_spacing . ';';
3094 }
3095
3096 // Responsive mobile
3097 if ( ! empty( $mobile_modal_width ) && '700' != $mobile_modal_width
3098 || ! empty( $mobile_modal_height ) && '0' != $mobile_modal_height
3099 || ! empty( $mobile_modal_padding )
3100 || ! empty( $mobile_font_size )
3101 || ! empty( $mobile_line_height )
3102 || ! empty( $mobile_letter_spacing ) ) {
3103 $css .= '@media (max-width: 767px) {.omw-modal{' . $mobile_css . '}}';
3104 }
3105
3106 // Return CSS
3107 if ( ! empty( $css ) ) {
3108 $output .= '/* Modals CSS */' . $css;
3109 }
3110
3111 // Return output css
3112 return $output;
3113
3114 }
3115
3116 /**
3117 * Add modal window switcher.
3118 *
3119 * @since 1.0.0
3120 */
3121 public function oe_theme_panels( $panels ) {
3122
3123 $panels['ocean_modal_window_panel'] = [
3124 'label' => esc_html__( 'Modal Window', 'ocean-modal-window' ),
3125 ];
3126
3127 // Return panels list
3128 return $panels;
3129 }
3130 } // End Class
3131
3132 // --------------------------------------------------------------------------------
3133 // region Freemius
3134 // --------------------------------------------------------------------------------
3135
3136 if ( ! function_exists( 'ocean_modal_window_fs' ) ) {
3137 // Create a helper function for easy SDK access.
3138 function ocean_modal_window_fs() {
3139 global $ocean_modal_window_fs;
3140
3141 if ( ! isset( $ocean_modal_window_fs ) ) {
3142 $ocean_modal_window_fs = OceanWP_EDD_Addon_Migration::instance( 'ocean_modal_window_fs' )->init_sdk(
3143 array(
3144 'id' => '3814',
3145 'slug' => 'ocean-modal-window',
3146 'public_key' => 'pk_7e254472063a1abd3b7e342930210',
3147 'is_premium' => false,
3148 'is_premium_only' => false,
3149 'has_paid_plans' => false,
3150 )
3151 );
3152 }
3153
3154 return $ocean_modal_window_fs;
3155 }
3156
3157 function ocean_modal_window_fs_addon_init() {
3158 if ( class_exists( 'Ocean_Extra' ) ) {
3159 OceanWP_EDD_Addon_Migration::instance( 'ocean_modal_window_fs' )->init();
3160 }
3161 }
3162
3163 if ( 0 == did_action( 'owp_fs_loaded' ) ) {
3164 // Init add-on only after parent theme was loaded.
3165 add_action( 'owp_fs_loaded', 'ocean_modal_window_fs_addon_init', 15 );
3166 } else {
3167 if ( class_exists( 'Ocean_Extra' ) ) {
3168 /**
3169 * This makes sure that if the theme was already loaded
3170 * before the plugin, it will run Freemius right away.
3171 *
3172 * This is crucial for the plugin's activation hook.
3173 */
3174 ocean_modal_window_fs_addon_init();
3175 }
3176 }
3177 }
3178 // endregion