Skip to content

Commit

Permalink
Update Request logic that checks if it's a Dashboard View
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mrcasual committed May 21, 2024
1 parent 05473eb commit d3556bd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit d3556bd

Please sign in to comment.