handle(); } /** * Handle the dismiss post: capability, nonce, drop the flag, go back. */ public function handle(): void { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to manage this plugin.', 'agentmysite' ), '', array( 'response' => 403 ) ); } check_admin_referer( self::ACTION_DISMISS ); AgentMySite_Options::clear_connect_notice(); $back = wp_get_referer(); wp_safe_redirect( is_string( $back ) && '' !== $back ? $back : admin_url() ); $this->terminate(); } /** * Stop after redirecting. Overridden in tests. */ protected function terminate(): void { exit; } /** * Whether the notice belongs on the current admin request. */ private static function should_show(): bool { if ( ! current_user_can( 'manage_options' ) || is_network_admin() ) { return false; } if ( AgentMySite_Options::is_connected() || ! AgentMySite_Options::is_connect_notice_pending() ) { return false; } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; return ! ( is_object( $screen ) && isset( $screen->id ) && self::SETTINGS_SCREEN === $screen->id ); } }