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__( 'Essential Pro Pack core is still loading. Please ensure Elementor is active, then reload this page.', 'admore-widgets-suite' ) . '