From a1f86ae569f1842b2f31e8f6229a0b9b9bd94f27 Mon Sep 17 00:00:00 2001 From: David Levine Date: Wed, 14 Aug 2024 11:48:31 +0000 Subject: [PATCH] fix: check if `get_current_screen()` is set before accessing properties --- .changeset/green-cows-accept.md | 5 +++++ includes/updates/update-callbacks.php | 6 +++--- phpstan-baseline.neon | 5 ----- 3 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 .changeset/green-cows-accept.md diff --git a/.changeset/green-cows-accept.md b/.changeset/green-cows-accept.md new file mode 100644 index 00000000..d758c4a9 --- /dev/null +++ b/.changeset/green-cows-accept.md @@ -0,0 +1,5 @@ +--- +"@wpengine/wp-graphql-content-blocks": patch +--- + +Fix: prevent fatal errors when get_current_screen() is unset. diff --git a/includes/updates/update-callbacks.php b/includes/updates/update-callbacks.php index 91ffcb93..a582494d 100644 --- a/includes/updates/update-callbacks.php +++ b/includes/updates/update-callbacks.php @@ -87,7 +87,7 @@ function custom_plugin_api_request( $api, $action, $args ) { */ function delegate_plugin_row_notice() { $screen = get_current_screen(); - if ( 'plugins' !== $screen->id ) { + if ( ! isset( $screen->id ) || 'plugins' !== $screen->id ) { return; } @@ -139,7 +139,7 @@ function display_plugin_row_notice() { */ function display_update_page_notice() { $screen = get_current_screen(); - if ( 'update-core' !== $screen->id ) { + if ( ! isset( $screen->id ) || 'update-core' !== $screen->id ) { return; } @@ -176,4 +176,4 @@ function filter_semver_notice_text( $notice_text, $plugin_filename ) { return $notice_text; } return '

' . __( 'THIS UPDATE MAY CONTAIN BREAKING CHANGES: This plugin uses Semantic Versioning, and this new version is a major release. Please review the changelog before updating.', 'wp-graphql-content-blocks' ); -} \ No newline at end of file +} diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 23c2223b..7a0c7e18 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -20,11 +20,6 @@ parameters: count: 1 path: includes/updates/update-callbacks.php - - - message: "#^Cannot access property \\$id on WP_Screen\\|null\\.$#" - count: 2 - path: includes/updates/update-callbacks.php - - message: "#^Function WPGraphQL\\\\ContentBlocks\\\\PluginUpdater\\\\custom_plugin_api_request\\(\\) has invalid return type WPGraphQL\\\\ContentBlocks\\\\PluginUpdater\\\\stdClass\\.$#" count: 1