Make WordPress Core

Changeset 61484


Ignore:
Timestamp:
01/14/2026 11:57:24 PM (less than one hour ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/screen.php

    r58419 r61484  
    225225    global $current_screen;
    226226
    227     if ( ! isset( $current_screen ) ) {
     227    if ( ! $current_screen instanceof WP_Screen ) {
    228228        return null;
    229229    }
  • trunk/tests/phpunit/tests/admin/includesScreen.php

    r54090 r61484  
    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' );
Note: See TracChangeset for help on using the changeset viewer.