time(), 'status' => 'pending', 'snoozed_until' => 0, ] ); } /** * Decides whether to render the notice on the current request. * Called directly from partials/dashboard.php's header markup - not hooked * to admin_notices, so the notice renders inside the plugin's own header * instead of WP's native top-of-page notices stack. * @return void */ public static function maybe_show_notice(): void { if( ! current_user_can( 'manage_options' ) ) { return; } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if( ! $screen || 'toplevel_page_adminease' !== $screen->id ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only preview flag, no state change, nonce not applicable. if( isset( $_GET[ self::PREVIEW_QUERY_ARG ] ) ) { self::render_notice(); return; } $state = get_option( self::OPTION_KEY ); $status = is_array( $state ) ? ( $state['status'] ?? '' ) : ''; if( 'pending' !== $status && 'snoozed' !== $status ) { return; } $ready_at = 'snoozed' === $status ? (int) ( $state['snoozed_until'] ?? PHP_INT_MAX ) : (int) ( $state['installed_at'] ?? time() ) + ( self::DELAY_DAYS * DAY_IN_SECONDS ); if( time() < $ready_at ) { return; } self::render_notice(); } /** * Renders the review request notice markup. * @return void */ private static function render_notice(): void { ?>
self::DISMISS_ACTION, 'adminease_review_action' => $review_action, '_wp_http_referer' => $referer, ], admin_url( 'admin-post.php' ) ); return wp_nonce_url( $url, 'adminease_review_request' ); } /** * Handles both the "Remind me later" and "No thanks" links via admin-post.php. * (Using real links rather than the notice's own JS dismiss button so the * choice persists server-side instead of just hiding client-side for one page load.) * @return void */ public function handle_dismiss(): void { if( ! current_user_can( 'manage_options' ) || ! check_admin_referer( 'adminease_review_request' ) ) { wp_die( esc_html__( 'Invalid request.', 'adminease' ) ); } $action = isset( $_GET['adminease_review_action'] ) ? sanitize_key( wp_unslash( $_GET['adminease_review_action'] ) ) : ''; $state = get_option( self::OPTION_KEY, [] ); if( 'snooze' === $action ) { $state['status'] = 'snoozed'; $state['snoozed_until'] = time() + ( self::SNOOZE_DAYS * DAY_IN_SECONDS ); } elseif( 'dismiss' === $action ) { $state['status'] = 'dismissed'; } update_option( self::OPTION_KEY, $state ); wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url() ); exit; } }