EPPRO_Popup_CPT::POST_TYPE, 'post_title' => __( 'New Popup', 'admore-widgets-suite' ), 'post_status' => 'draft', ] ); if ( $new_id && ! is_wp_error( $new_id ) ) { update_post_meta( $new_id, '_elementor_edit_mode', 'builder' ); $edit_url = admin_url( 'post.php?post=' . $new_id . '&action=elementor' ); wp_safe_redirect( $edit_url ); exit; } } // post.php?post=X&action=edit — redirect to Elementor if it's a popup if ( 'post.php' === $pagenow && $post_id && 'edit' === $action ) { if ( get_post_type( $post_id ) === EPPRO_Popup_CPT::POST_TYPE ) { $edit_url = admin_url( 'post.php?post=' . $post_id . '&action=elementor' ); wp_safe_redirect( $edit_url ); exit; } } } /** * Auto-set Elementor edit mode when a popup post is first created. */ public static function auto_set_elementor_mode( int $post_id, \WP_Post $post ): void { if ( EPPRO_Popup_CPT::POST_TYPE !== $post->post_type ) return; if ( ! get_post_meta( $post_id, '_elementor_edit_mode', true ) ) { update_post_meta( $post_id, '_elementor_edit_mode', 'builder' ); } } public static function add_menu(): void { add_submenu_page( 'eppro-settings', __( 'Popup Builder', 'admore-widgets-suite' ), __( 'Popup Builder', 'admore-widgets-suite' ), 'manage_options', 'eppro-popups', [ __CLASS__, 'render_page' ] ); } public static function enqueue( string $_hook ): void { // Nothing extra: eppro-admin.css / js are enqueued by EPPRO_Admin_Settings::enqueue_admin_assets. } /** Redirect WP native post-edit to Elementor for eppro_popup CPT. */ public static function edit_notice(): void { $screen = get_current_screen(); if ( ! $screen || 'eppro_popup' !== $screen->post_type ) return; if ( 'post' !== $screen->base ) return; if ( ! class_exists( 'Elementor\Plugin' ) ) return; global $post; if ( ! $post ) return; $doc = \Elementor\Plugin::instance()->documents->get( $post->ID ); if ( ! $doc ) return; $url = $doc->get_edit_url(); ?>

__( 'Insufficient permissions.', 'admore-widgets-suite' ) ], 403 ); $post_id = absint( $_POST['post_id'] ?? 0 ); if ( EPPRO_Popup_CPT::POST_TYPE !== get_post_type( $post_id ) ) { wp_send_json_error( [ 'message' => __( 'Popup not found.', 'admore-widgets-suite' ) ] ); } // Shared duplicator: copies all settings and Elementor data safely; the copy starts inactive. $new_id = EPPRO_Template_Duplicator::do_duplicate( $post_id ); if ( is_wp_error( $new_id ) ) { wp_send_json_error( [ 'message' => $new_id->get_error_message() ] ); } wp_send_json_success( [ 'reload' => true, 'new_id' => $new_id ] ); } // ========================================================================= // AJAX: Toggle active status // ========================================================================= public static function ajax_toggle_status(): void { check_ajax_referer( 'eppro_admin_nonce', '_wpnonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( [ 'message' => 'Unauthorized' ], 403 ); } $post_id = absint( $_POST['post_id'] ?? 0 ); if ( ! $post_id || get_post_type( $post_id ) !== EPPRO_Popup_CPT::POST_TYPE ) { wp_send_json_error( [ 'message' => 'Invalid popup.' ], 400 ); } $active = ! empty( $_POST['active'] ) && '1' === $_POST['active']; $meta = EPPRO_Popup_Settings::get( $post_id ); $meta['active'] = $active; update_post_meta( $post_id, EPPRO_Popup_Settings::META_KEY, $meta ); wp_send_json_success( [ 'active' => $active ] ); } // ========================================================================= // AJAX: Quick settings save // ========================================================================= public static function ajax_quick_settings_save(): void { check_ajax_referer( 'eppro_admin_nonce', '_wpnonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( [ 'message' => 'Unauthorized' ], 403 ); } $post_id = absint( $_POST['post_id'] ?? 0 ); if ( ! $post_id || get_post_type( $post_id ) !== EPPRO_Popup_CPT::POST_TYPE ) { wp_send_json_error( [ 'message' => 'Invalid popup.' ], 400 ); } $meta = EPPRO_Popup_Settings::get( $post_id ); // Triggers $allowed_triggers = [ 'page_load', 'scroll', 'click', 'exit_intent', 'inactivity', 'form_submit', 'add_to_cart' ]; $meta['triggers'] = array_values( array_intersect( array_map( 'sanitize_key', (array) ( isset( $_POST['triggers'] ) ? wp_unslash( $_POST['triggers'] ) : [] ) ), $allowed_triggers ) ); $meta['page_load_delay'] = absint( $_POST['page_load_delay'] ?? 0 ); $meta['scroll_depth'] = min( 100, absint( $_POST['scroll_depth'] ?? 50 ) ); $meta['click_selector'] = sanitize_text_field( wp_unslash( $_POST['click_selector'] ?? '' ) ); // Conditions $allowed_scopes = [ 'entire_site', 'page', 'post_type', 'url', 'url_param', 'front_page', 'blog_page', 'search_results', 'category', 'tag', 'referrer', 'woo_shop', 'woo_product', 'woo_cart', 'woo_checkout', 'woo_account', ]; $scope = sanitize_key( wp_unslash( $_POST['condition_scope'] ?? 'entire_site' ) ); $meta['condition_scope'] = in_array( $scope, $allowed_scopes, true ) ? $scope : 'entire_site'; $meta['condition_page_ids'] = sanitize_text_field( wp_unslash( $_POST['condition_page_ids'] ?? '' ) ); $meta['condition_post_types'] = array_map( 'sanitize_key', (array) ( $_POST['condition_post_types'] ?? [] ) ); $meta['condition_url_contains'] = sanitize_text_field( wp_unslash( $_POST['condition_url_contains'] ?? '' ) ); $meta['condition_url_param'] = sanitize_key( wp_unslash( $_POST['condition_url_param'] ?? '' ) ); $allowed_uc = [ 'all', 'logged_in', 'logged_out' ]; $uc = sanitize_key( wp_unslash( $_POST['user_condition'] ?? 'all' ) ); $meta['user_condition'] = in_array( $uc, $allowed_uc, true ) ? $uc : 'all'; // Devices $allowed_devices = [ 'desktop', 'tablet', 'mobile' ]; $meta['devices'] = array_values( array_intersect( array_map( 'sanitize_key', (array) ( isset( $_POST['devices'] ) ? wp_unslash( $_POST['devices'] ) : $allowed_devices ) ), $allowed_devices ) ); if ( empty( $meta['devices'] ) ) { $meta['devices'] = $allowed_devices; } // Trigger sub-settings $meta['inactivity_time'] = absint( $_POST['inactivity_time'] ?? 30 ); $meta['form_selector'] = sanitize_text_field( wp_unslash( $_POST['form_selector'] ?? '' ) ); // Status & behaviour $meta['active'] = ! empty( $_POST['active'] ) && '1' === $_POST['active']; $meta['show_once'] = ! empty( $_POST['show_once'] ) && '1' === $_POST['show_once']; $meta['show_once_session'] = ! empty( $_POST['show_once_session'] ) && '1' === $_POST['show_once_session']; $meta['cookie_days'] = absint( $_POST['cookie_days'] ?? 30 ); // Animation and close behaviour are edited in the Elementor editor's // Page Settings (EPPRO_Popup_Design); existing values are left as they are. update_post_meta( $post_id, EPPRO_Popup_Settings::META_KEY, $meta ); wp_send_json_success( [ 'message' => __( 'Settings saved.', 'admore-widgets-suite' ) ] ); } // ========================================================================= // Page render // ========================================================================= public static function render_page(): void { if ( ! current_user_can( 'manage_options' ) ) return; if ( ! class_exists( 'EPPRO_Popup_CPT' ) ) { echo '

' . esc_html__( 'Popup Builder', 'admore-widgets-suite' ) . '

'; echo '

' . esc_html__( 'Essential Pro Pack core is still loading. Please ensure Elementor is active, then reload this page.', 'admore-widgets-suite' ) . '

'; return; } $popups = get_posts( [ 'post_type' => EPPRO_Popup_CPT::POST_TYPE, 'post_status' => [ 'publish', 'draft' ], 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'DESC', ] ); $new_url = add_query_arg( [ 'post_type' => EPPRO_Popup_CPT::POST_TYPE ], admin_url( 'post-new.php' ) ); $t_labels = [ 'page_load' => __( 'Page Load', 'admore-widgets-suite' ), 'scroll' => __( 'Scroll', 'admore-widgets-suite' ), 'click' => __( 'Click', 'admore-widgets-suite' ), 'exit_intent' => __( 'Exit Intent', 'admore-widgets-suite' ), 'inactivity' => __( 'Inactivity', 'admore-widgets-suite' ), 'form_submit' => __( 'Form Submit', 'admore-widgets-suite' ), 'add_to_cart' => __( 'Add to Cart', 'admore-widgets-suite' ), ]; $scope_map = [ 'entire_site' => __( 'Entire Site', 'admore-widgets-suite' ), 'page' => __( 'Specific Pages', 'admore-widgets-suite' ), 'post_type' => __( 'Post Type', 'admore-widgets-suite' ), 'url' => __( 'URL Contains', 'admore-widgets-suite' ), 'url_param' => __( 'URL Parameter', 'admore-widgets-suite' ), 'front_page' => __( 'Front Page', 'admore-widgets-suite' ), 'blog_page' => __( 'Blog Page', 'admore-widgets-suite' ), 'search_results' => __( 'Search Results', 'admore-widgets-suite' ), 'category' => __( 'Category', 'admore-widgets-suite' ), 'tag' => __( 'Tag', 'admore-widgets-suite' ), 'referrer' => __( 'Referrer URL', 'admore-widgets-suite' ), 'woo_shop' => __( 'Woo: Shop', 'admore-widgets-suite' ), 'woo_product' => __( 'Woo: Product', 'admore-widgets-suite' ), 'woo_cart' => __( 'Woo: Cart', 'admore-widgets-suite' ), 'woo_checkout' => __( 'Woo: Checkout', 'admore-widgets-suite' ), 'woo_account' => __( 'Woo: Account', 'admore-widgets-suite' ), ]; ?>

ID ); $active = ! empty( $meta['active'] ); $triggers = (array) ( $meta['triggers'] ?? [] ); $scope = $meta['condition_scope'] ?? 'entire_site'; $elem_url = admin_url( 'post.php?post=' . $popup->ID . '&action=elementor' ); $delete_url = get_delete_post_link( $popup->ID ); // Build Quick Settings data payload $qs_meta = [ 'active' => ! empty( $meta['active'] ), 'triggers' => (array) ( $meta['triggers'] ?? [] ), 'page_load_delay' => absint( $meta['page_load_delay'] ?? 0 ), 'scroll_depth' => absint( $meta['scroll_depth'] ?? 50 ), 'click_selector' => $meta['click_selector'] ?? '', 'inactivity_time' => absint( $meta['inactivity_time'] ?? 30 ), 'form_selector' => $meta['form_selector'] ?? '', 'condition_scope' => $meta['condition_scope'] ?? 'entire_site', 'condition_page_ids' => $meta['condition_page_ids'] ?? '', 'condition_post_types' => (array) ( $meta['condition_post_types'] ?? [] ), 'condition_url_contains'=> $meta['condition_url_contains'] ?? '', 'condition_url_param' => $meta['condition_url_param'] ?? '', 'user_condition' => $meta['user_condition'] ?? 'all', 'devices' => (array) ( $meta['devices'] ?? [ 'desktop', 'tablet', 'mobile' ] ), 'show_once' => ! empty( $meta['show_once'] ), 'show_once_session' => ! empty( $meta['show_once_session'] ), 'cookie_days' => absint( $meta['cookie_days'] ?? 30 ), ]; $date_str = get_the_date( 'M j, Y', $popup ); $tl = []; foreach ( $triggers as $t ) { $tl[] = $t_labels[ $t ] ?? $t; } ?> ID, '_eppro_popup_views', true ); ?>