Skip to content

Commit

Permalink
fix: Prevent undefined get_current_screen function errors (#39228)
Browse files Browse the repository at this point in the history
* fix: Prevent undefined `get_current_screen` function errors

This function is undefined in certain contexts -- e.g., a REST API
request that results in enqueueing assets. Referencing an undefined
function results in a fatal error. With the `get_current_screen`
function specifically, it is common practice to check the function's
existence prior to invoking the it.

https://developer.wordpress.org/reference/functions/get_current_screen/#comment-5424

* docs: Add change log entry

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/10815999818

Upstream-Ref: Automattic/jetpack@5ee714f
  • Loading branch information
kraftbj authored and matticbot committed Sep 11, 2024
1 parent 7c9c60a commit 2087268
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 85 deletions.
58 changes: 29 additions & 29 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/automattic/jetpack-mu-wpcom/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This is an alpha version! The changes listed here are not final.
### Fixed
- Admin bar: fix paddings around wpcom and reader logos
- Launchpad first_post_published task reuses existing draft if there is one
- Prevent undefined `get_current_screen` function errors resulting from invoking the function in contexts where it is undefined.

## [5.62.0] - 2024-09-10
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ public function pass_error_to_frontend( $message ) {
* Enqueue block editor assets.
*/
public function enqueue_assets() {
if ( ! function_exists( 'get_current_screen' ) ) {
return;
}

$screen = get_current_screen();
$user_locale = Common\get_iso_639_locale( get_user_locale() );

Expand Down
Loading

0 comments on commit 2087268

Please sign in to comment.