set_404(); status_header( 404 ); nocache_headers(); include get_query_template( '404' ); exit; } public static function filter_elementor_cpt_support( $supported ): array { if ( ! is_array( $supported ) ) { $supported = [ 'page', 'post' ]; } if ( ! in_array( self::POST_TYPE, $supported, true ) ) { $supported[] = self::POST_TYPE; } return $supported; } /** Flush rewrite rules once when the CPT is first introduced. */ public static function maybe_flush(): void { if ( get_option( 'eppro_popup_cpt_flushed_v2' ) ) return; flush_rewrite_rules(); update_option( 'eppro_popup_cpt_flushed_v2', '1' ); } public static function register(): void { register_post_type( self::POST_TYPE, [ 'label' => __( 'Popups', 'admore-widgets-suite' ), 'labels' => [ 'name' => __( 'Popups', 'admore-widgets-suite' ), 'singular_name' => __( 'Popup', 'admore-widgets-suite' ), 'add_new_item' => __( 'Add New Popup', 'admore-widgets-suite' ), 'edit_item' => __( 'Edit Popup', 'admore-widgets-suite' ), ], 'public' => false, 'publicly_queryable' => true, 'exclude_from_search' => true, 'show_ui' => true, 'show_in_menu' => false, // Not exposed through the REST API: /wp/v2/ would otherwise list // every published popup, including inactive and members-only ones. 'show_in_rest' => false, 'has_archive' => false, 'rewrite' => false, 'supports' => [ 'title', 'editor', 'elementor' ], 'capability_type' => 'post', // Popups can appear on every page of the site, so only administrators may manage them. 'capabilities' => self::capabilities(), 'map_meta_cap' => true, ] ); } /** * Primitive capabilities for the popup post type, all mapped to * manage_options (the same capability the Popups admin page requires). */ public static function capabilities(): array { $cap = 'manage_options'; return [ 'edit_posts' => $cap, 'edit_others_posts' => $cap, 'edit_private_posts' => $cap, 'edit_published_posts' => $cap, 'publish_posts' => $cap, 'read_private_posts' => $cap, 'delete_posts' => $cap, 'delete_private_posts' => $cap, 'delete_published_posts' => $cap, 'delete_others_posts' => $cap, 'create_posts' => $cap, ]; } /** Custom admin columns. */ public static function columns( array $cols ): array { return [ 'cb' => $cols['cb'], 'title' => __( 'Title', 'admore-widgets-suite' ), 'status' => __( 'Status', 'admore-widgets-suite' ), 'trigger' => __( 'Trigger', 'admore-widgets-suite' ), 'conditions' => __( 'Conditions', 'admore-widgets-suite' ), 'popup_id' => __( 'ID', 'admore-widgets-suite' ), 'date' => $cols['date'], ]; } public static function column_content( string $col, int $post_id ): void { $meta = EPPRO_Popup_Settings::get( $post_id ); switch ( $col ) { case 'status': $active = ! empty( $meta['active'] ); printf( '%s', esc_attr( $active ? 'active' : 'inactive' ), esc_html( $active ? __( 'Active', 'admore-widgets-suite' ) : __( 'Inactive', 'admore-widgets-suite' ) ) ); break; case 'trigger': $triggers = (array) ( $meta['triggers'] ?? [] ); $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' ), ]; $out = []; foreach ( $triggers as $t ) { $out[] = $labels[ $t ] ?? $t; } echo esc_html( $out ? implode( ', ', $out ) : '—' ); break; case 'conditions': $scope = $meta['condition_scope'] ?? 'entire_site'; $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' ), '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' ), 'url_param' => __( 'URL Parameter', 'admore-widgets-suite' ), 'referrer' => __( 'Referrer URL', 'admore-widgets-suite' ), ]; echo esc_html( $map[ $scope ] ?? $scope ); break; case 'popup_id': echo '' . absint( $post_id ) . ''; break; } } /** Add "Edit with Elementor" row action. */ public static function row_actions( array $actions, \WP_Post $post ): array { if ( self::POST_TYPE !== $post->post_type ) return $actions; if ( class_exists( 'Elementor\Plugin' ) ) { $doc = \Elementor\Plugin::instance()->documents->get( $post->ID ); if ( $doc ) { $actions['edit_elementor'] = sprintf( '%s', esc_url( $doc->get_edit_url() ), esc_html__( 'Edit with Elementor', 'admore-widgets-suite' ) ); } } return $actions; } }