Make WordPress Core

Opened 2 years ago

Closed 10 months ago

Last modified 2 months ago

#62562 closed enhancement (fixed)

Ensure get_current_screen() returns WP_Screen|null

Reported by: marian1 Owned by: SergeyBiryukov
Priority: normal Milestone: 7.0
Component: Administration Version:
Severity: trivial Keywords: has-patch dev-feedback
Cc: Focuses:

Description

Currently, get_current_screen() simply checks whether the global variable $current_screen is set before returning it. Since global variables may be overridden, it should confirm that $current_screen is actually a WP_Screen object to ensure that get_current_screen() reliably returns a valid WP_Screen object.

Change History (7)

This ticket was mentioned in ​PR #7885 on ​WordPress/wordpress-develop by ​@marian1.


2 years ago
#1

  • Keywords has-patch added; needs-patch removed

#2 @mayanktripathi32
2 years ago

  • Keywords dev-feedback needs-testing added

#3 @abcd95
2 years ago

  • Keywords needs-testing removed

Test Report

Description

This report validates that the indicated patch works as expected.

Environment

  • WordPress: 6.8-alpha-59274-src
  • PHP: 8.2.25
  • Server: nginx/1.27.2
  • Database: mysqli (Server: 8.0.40 / Client: mysqlnd 8.2.25)
  • Browser: Chrome 131.0.0.0
  • OS: macOS

Actual Results

✅ Issue addressed by the patch.

#4 @im3dabasia1
2 years ago

Test Report

Description

This report validates whether the indicated patch works as expected.

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/7885.diff

Environment

  • WordPress: 6.8-alpha-59274-src
  • PHP: 8.2.25
  • Server: nginx/1.27.2
  • Database: mysqli (Server: 8.0.40 / Client: mysqlnd 8.2.25)
  • Browser: Chrome 129.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.0
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Actual Results

  1. ✅ Issue resolved with patch.

#5 @SergeyBiryukov
10 months ago

  • Milestone Awaiting Review → 7.0

#6 @SergeyBiryukov
10 months ago

  • Owner set to SergeyBiryukov
  • Resolution → fixed
  • Status new → closed

In 61484:

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.

#7 @westonruter
2 months ago

In 63490:

Role/Capability: Ensure wp_roles() returns WP_Roles.

Previously wp_roles() only checked whether the $wp_roles global was set before returning it, so any code that overwrote that global with another value caused the function to hand back something which is not a WP_Roles object. Checking instanceof instead guarantees the return type, matching the approach already used by wp_scripts() and wp_styles().

Developed in ​https://github.com/WordPress/wordpress-develop/pull/8315.
Follow-up to r32541.

Props marian1.
See #62562.
Fixes #62959.

Note: See TracTickets for help on using tickets.