type */ private $fields = [ '_foxcp_display_home' => 'boolean', '_foxcp_display_posts' => 'boolean', '_foxcp_display_pages' => 'boolean', '_foxcp_trigger_delay' => 'integer', '_foxcp_trigger_scroll' => 'integer', '_foxcp_trigger_exit_intent' => 'boolean', // exit-intent trigger '_foxcp_cookie_always' => 'boolean', '_foxcp_cookie_duration' => 'integer', '_foxcp_cookie_unit' => 'string', '_foxcp_animation' => 'string', '_foxcp_image_mode' => 'boolean', '_foxcp_link_url' => 'string', '_foxcp_woo_cart_abandonment' => 'boolean', '_foxcp_woo_coupon_code' => 'string', ]; public function __construct() { add_action( 'init', [ $this, 'register_meta' ] ); add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_editor_assets' ] ); add_filter( 'preview_post_link', [ $this, 'custom_preview_link' ], 10, 2 ); } public function custom_preview_link( $link, $post ) { if ( ! $post || 'foxcp_popup' !== $post->post_type ) { return $link; } $url = add_query_arg( 'foxcp_preview', absint( $post->ID ), home_url( '/' ) ); return wp_nonce_url( $url, 'foxcp_preview_' . absint( $post->ID ) ); } public function register_meta() { $defaults = [ '_foxcp_trigger_exit_intent' => false, '_foxcp_cookie_always' => false, '_foxcp_cookie_duration' => 30, '_foxcp_cookie_unit' => 'days', '_foxcp_animation' => 'none', '_foxcp_image_mode' => false, '_foxcp_link_url' => '', '_foxcp_woo_cart_abandonment' => false, '_foxcp_woo_coupon_code' => '', ]; foreach ( $this->fields as $key => $type ) { if ( isset( $defaults[ $key ] ) ) { $default = $defaults[ $key ]; } elseif ( 'boolean' === $type ) { $default = false; } elseif ( 'string' === $type ) { $default = ''; } else { $default = 0; } register_post_meta( 'foxcp_popup', $key, [ 'single' => true, 'type' => $type, 'show_in_rest' => true, 'default' => $default, 'auth_callback' => static function () { return current_user_can( 'edit_posts' ); }, ] ); } } public function enqueue_editor_assets() { $screen = get_current_screen(); if ( ! $screen || 'foxcp_popup' !== $screen->post_type ) { return; } wp_enqueue_script( 'foxcp-editor', FOXCP_PLUGIN_URL . 'assets/js/popup-editor.js', [ 'wp-plugins', 'wp-edit-post', 'wp-element', 'wp-components', 'wp-data', 'wp-i18n' ], FOXCP_VERSION, true ); // Load JS translations (de_DE etc.) wp_set_script_translations( 'foxcp-editor', '2fox4-custom-popup', FOXCP_PLUGIN_DIR . 'languages' ); // Pass WooCommerce availability flag to JS. wp_localize_script( 'foxcp-editor', 'foxcpEditorData', [ 'wooActive' => class_exists( 'WooCommerce' ), ] ); wp_enqueue_style( 'foxcp-editor', FOXCP_PLUGIN_URL . 'assets/css/popup-editor.css', [], FOXCP_VERSION ); } }