Skip to content

Commit

Permalink
Merge branch 'main' into issue-31-custom-buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
josephfusco authored Feb 29, 2024
2 parents f74ba9f + e54ffdb commit 8bd3de7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md)

## Custom Hooks

See [ACTIONS_AND_FILTERS.md](ACTIONS_AND_FILTERS.md)
See [ACTIONS_AND_FILTERS.md](ACTIONS_AND_FILTERS.md).
43 changes: 37 additions & 6 deletions wpgraphql-ide.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,25 @@ function user_lacks_capability(): bool {
}

/**
* Checks if the current page is intended for the dedicated WPGraphQL IDE (non-drawer).
* Determines if the current admin page is a dedicated WPGraphQL IDE page.
*
* This function checks whether the current admin page is exclusively for either the new GraphQL IDE
* or the legacy GraphiQL IDE, distinguishing them from other admin pages where the IDE might be present
* in a drawer. It is designed to help in tailoring the admin interface or enqueuing specific scripts
* and styles on these dedicated IDE pages.
*
* @return bool True if the current page is a dedicated WPGraphQL IDE page, false otherwise.
*/
function is_dedicated_ide_page(): bool {
return is_ide_page() || is_legacy_ide_page();
}

/**
* Checks if the current admin page is the new WPGraphQL IDE page.
*
* @return bool True if the current page is the new WPGraphQL IDE page, false otherwise.
*/
function is_ide_page(): bool {
if ( ! function_exists( 'get_current_screen' ) ) {
return false;
}
Expand All @@ -67,12 +81,25 @@ function is_dedicated_ide_page(): bool {
return false;
}

$dedicated_ide_screens = [
'toplevel_page_graphiql-ide', // old - GraphiQL IDE
'graphql_page_graphql-ide', // new - GraphQL IDE
];
return 'graphql_page_graphql-ide' === $screen->id;
}

return in_array( $screen->id, $dedicated_ide_screens, true );
/**
* Checks if the current admin page is the legacy GraphiQL IDE page.
*
* @return bool True if the current page is the legacy GraphiQL IDE page, false otherwise.
*/
function is_legacy_ide_page(): bool {
if ( ! function_exists( 'get_current_screen' ) ) {
return false;
}

$screen = get_current_screen();
if ( ! $screen ) {
return false;
}

return 'toplevel_page_graphiql-ide' === $screen->id;
}

/**
Expand Down Expand Up @@ -172,6 +199,10 @@ function enqueue_graphql_ide_menu_icon_css(): void {
* Enqueues the React application script and associated styles.
*/
function enqueue_react_app_with_styles(): void {
if ( is_legacy_ide_page() ) {
return;
}

if ( ! class_exists( '\WPGraphQL\Router' ) ) {
return;
}
Expand Down

0 comments on commit 8bd3de7

Please sign in to comment.