Skip to content

Commit a8924f5

Browse files
Administration: Ensure get_current_screen() returns WP_Screen or null.
This adds a check that the `$current_screen` global is not only defined, but also has the correct type. Follow-up to [15746]. Props marian1, mayanktripathi32, abcd95, im3dabasia1, SergeyBiryukov. Fixes #62562. git-svn-id: https://develop.svn.wordpress.org/trunk@61484 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d015d16 commit a8924f5

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/wp-admin/includes/screen.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function add_screen_option( $option, $args = array() ) {
224224
function get_current_screen() {
225225
global $current_screen;
226226

227-
if ( ! isset( $current_screen ) ) {
227+
if ( ! $current_screen instanceof WP_Screen ) {
228228
return null;
229229
}
230230

tests/phpunit/tests/admin/includesScreen.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,19 @@ public function test_options() {
451451
$this->assertSame( $screen->get_options(), array() );
452452
}
453453

454+
/**
455+
* @ticket 62562
456+
*/
457+
public function test_get_current_screen_type() {
458+
global $current_screen;
459+
460+
set_current_screen( 'edit.php' );
461+
$this->assertInstanceOf( 'WP_Screen', get_current_screen() );
462+
463+
$current_screen = new stdClass();
464+
$this->assertNull( get_current_screen() );
465+
}
466+
454467
public function test_in_admin() {
455468
set_current_screen( 'edit.php' );
456469
$this->assertTrue( get_current_screen()->in_admin() );

0 commit comments

Comments
 (0)