From d3556bdc347163c02372a425ef4553a8e347438c Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 21 May 2024 18:16:55 -0400 Subject: [PATCH] Update Request logic that checks if it's a Dashboard View Some GK plugins/extensions also use the request class to check if it's an admin request, in which case they stop initializing and loading assets, so we need to fake a "false" response unless doing Ajax. --- src/Request.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Request.php b/src/Request.php index eb271ea..ab85be5 100644 --- a/src/Request.php +++ b/src/Request.php @@ -9,6 +9,10 @@ /** * The default Dashboard View Request class. + * + * It's initialized in the Plugin class on the 'current_screen' action, which only runs in the admin. + * + * {@see Plugin::set_request()} */ class Request extends GravityViewRequest { /** @@ -44,9 +48,19 @@ public function declare_renderable( $is_renderable, $instance ) { * @return bool */ public function is_dashboard_view() { - $view_id = AdminMenu::get_submenu_view_id( $_REQUEST['page'] ?? '' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended + return ! ! AdminMenu::get_submenu_view_id( $_REQUEST['page'] ?? '' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended + } - return $view_id && ( $this->is_admin() || wp_doing_ajax() ); + /** + * Returns false to fake that we're not inside an admin screen unless it's an Ajax request. + * This response is expected by various GravityKit plugins/extensions to determine whether to initialize, load their assets, etc. + * + * @since TBD + * + * @return bool + */ + public static function is_admin() { + return wp_doing_ajax() || false; } /**