id, [ self::TARGET_SCREEN, 'edit-wpvr' ], true ) || ( isset( $screen->base, $screen->post_type ) && 'edit' === $screen->base && in_array( $screen->post_type, [ self::POST_TYPE, 'wpvr' ], true ) ); if ( ! $is_listing ) { return false; } // Suppress if WPVR Pro is active with a valid license. if ( function_exists( 'wpvr_is_pro_active' ) && wpvr_is_pro_active() ) { return false; } // Suppress if user permanently dismissed the banner. if ( get_option( self::OPTION_DISMISSED, 'no' ) === 'yes' ) { return false; } // Suppress if campaign has ended. if ( time() >= strtotime( self::END_DATE ) ) { return false; } return true; } /** * Computes initial countdown values for server-side render. * * @return array */ public function get_countdown_data(): array { $end_timestamp = strtotime( self::END_DATE ); $diff = max( 0, $end_timestamp - time() ); $days = floor( $diff / ( 60 * 60 * 24 ) ); $hours = floor( ( $diff % ( 60 * 60 * 24 ) ) / ( 60 * 60 ) ); $mins = floor( ( $diff % ( 60 * 60 ) ) / 60 ); $secs = floor( $diff % 60 ); return [ 'days' => sprintf( '%02d', (int) $days ), 'hours' => sprintf( '%02d', (int) $hours ), 'mins' => sprintf( '%02d', (int) $mins ), 'secs' => sprintf( '%02d', (int) $secs ), 'end_timestamp' => $end_timestamp, ]; } /** * Enqueue assets strictly when banner should display. */ public function enqueue_assets(): void { if ( ! $this->should_display() ) { return; } $plugin_url = plugin_dir_url( WPVR_FILE ); $plugin_path = plugin_dir_path( WPVR_FILE ); $css_file = $plugin_path . 'app/admin/promotional-banner.css'; $css_ver = file_exists( $css_file ) ? (string) filemtime( $css_file ) : WPVR_VERSION; $js_file = $plugin_path . 'app/admin/promotional-banner.js'; $js_ver = file_exists( $js_file ) ? (string) filemtime( $js_file ) : WPVR_VERSION; wp_enqueue_style( 'wpvr-promotional-banner', $plugin_url . 'app/admin/promotional-banner.css', [], $css_ver ); wp_enqueue_script( 'wpvr-promotional-banner', $plugin_url . 'app/admin/promotional-banner.js', [], $js_ver, true ); wp_localize_script( 'wpvr-promotional-banner', 'wpvrPromoBanner', [ 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'action' => self::AJAX_ACTION, 'nonce' => wp_create_nonce( self::NONCE_ACTION ), 'endTimestamp' => strtotime( self::END_DATE ), ] ); } /** * Renders promotional banner HTML markup. */ public function render_banner(): void { if ( ! $this->should_display() ) { return; } $countdown = $this->get_countdown_data(); ?>
esc_html__( 'Permission denied.', 'wpvr' ) ], 403 ); } check_ajax_referer( self::NONCE_ACTION, 'nonce' ); update_option( self::OPTION_DISMISSED, 'yes' ); wp_send_json_success( [ 'message' => esc_html__( 'Banner permanently dismissed.', 'wpvr' ) ] ); } }