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
  • Loading branch information
dcalhoun authored Sep 11, 2024
1 parent 3a06084 commit 5ee714f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Prevent undefined `get_current_screen` function errors resulting from invoking the function in contexts where it is undefined.
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

0 comments on commit 5ee714f

Please sign in to comment.