Commit c50aa2a453 for wordpress.org
commit c50aa2a4539149a39af4f5989668350887d15e02
Author: westonruter <westonruter@git.wordpress.org>
Date: Thu Sep 17 00:23:49 2026 +0000
Code Quality: Add the missing types around `_get_list_table()`.
- The return type promised `WP_List_Table|false` whatever class was asked for. A `@phpstan-template` now ties it to the `class-string` passed in.
- The `$args` param was described as accepting only `screen`. It now carries the hash notation from `WP_List_Table::__construct()`.
- That `screen` argument was typed as a string. It is documented as the `string|WP_Screen|null` it has always accepted. This type union is also applied to `convert_to_screen()` and `WP_Screen::get()`.
Nothing changes at runtime. The function is left free of PHPStan errors at every rule level.
Developed in https://github.com/WordPress/wordpress-develop/pull/13553.
Follow-up to r29459, r54378, r63020, r63420.
Props soean, westonruter.
See #65817.
Built from https://develop.svn.wordpress.org/trunk@63648
git-svn-id: http://core.svn.wordpress.org/trunk@62823 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-admin/includes/class-wp-list-table.php b/wp-admin/includes/class-wp-list-table.php
index df8e71834e..13e61014d6 100644
--- a/wp-admin/includes/class-wp-list-table.php
+++ b/wp-admin/includes/class-wp-list-table.php
@@ -133,18 +133,18 @@ class WP_List_Table {
* @param array|string $args {
* Array or string of arguments.
*
- * @type string $plural Plural value used for labels and the objects being listed.
- * This affects things such as CSS class-names and nonces used
- * in the list table, e.g. 'posts'. Default empty.
- * @type string $singular Singular label for an object being listed, e.g. 'post'.
- * Default empty
- * @type bool $ajax Whether the list table supports Ajax. This includes loading
- * and sorting data, for example. If true, the class will call
- * the _js_vars() method in the footer to provide variables
- * to any scripts handling Ajax events. Default false.
- * @type string $screen String containing the hook name used to determine the current
- * screen. If left null, the current screen will be automatically set.
- * Default null.
+ * @type string $plural Plural value used for labels and the objects being listed.
+ * This affects things such as CSS class-names and nonces used
+ * in the list table, e.g. 'posts'. Default empty.
+ * @type string $singular Singular label for an object being listed, e.g. 'post'.
+ * Default empty.
+ * @type bool $ajax Whether the list table supports Ajax. This includes loading
+ * and sorting data, for example. If true, the class will call
+ * the _js_vars() method in the footer to provide variables
+ * to any scripts handling Ajax events. Default false.
+ * @type string|WP_Screen|null $screen String containing the hook name used to determine the current
+ * screen, or a `WP_Screen` instance. If left null, the current
+ * screen will be automatically set. Default null.
* }
*/
public function __construct( $args = array() ) {
diff --git a/wp-admin/includes/class-wp-screen.php b/wp-admin/includes/class-wp-screen.php
index b0b689d412..a60ecca955 100644
--- a/wp-admin/includes/class-wp-screen.php
+++ b/wp-admin/includes/class-wp-screen.php
@@ -205,8 +205,8 @@ final class WP_Screen {
*
* @global string $hook_suffix
*
- * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
- * Defaults to the current $hook_suffix global.
+ * @param string|WP_Screen|null $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
+ * Defaults to the current $hook_suffix global.
* @return WP_Screen Screen object.
*/
public static function get( $hook_name = '' ) {
diff --git a/wp-admin/includes/list-table.php b/wp-admin/includes/list-table.php
index 97dfe4f858..565144768e 100644
--- a/wp-admin/includes/list-table.php
+++ b/wp-admin/includes/list-table.php
@@ -15,8 +15,28 @@
* @global string $hook_suffix
*
* @param string $class_name The type of the list table, which is the class name.
- * @param array $args Optional. Arguments to pass to the class. Accepts 'screen'.
- * @return WP_List_Table|false List table object on success, false if the class does not exist.
+ * @param array $args {
+ * Optional. Arguments to pass to the class.
+ *
+ * @type string $plural Plural value used for labels and the objects being listed.
+ * This affects things such as CSS class-names and nonces used
+ * in the list table, e.g. 'posts'. Default empty.
+ * @type string $singular Singular label for an object being listed, e.g. 'post'.
+ * Default empty.
+ * @type bool $ajax Whether the list table supports Ajax. This includes loading
+ * and sorting data, for example. If true, the class will call
+ * the _js_vars() method in the footer to provide variables
+ * to any scripts handling Ajax events. Default false.
+ * @type string|WP_Screen|null $screen String containing the hook name used to determine the current
+ * screen, or a `WP_Screen` instance. If left null, the current
+ * screen will be automatically set. Default null.
+ * }
+ * @return WP_List_Table|false List table object of the type given in `$class_name`
+ * on success, false if the class does not exist.
+ *
+ * @phpstan-template T of WP_List_Table
+ * @phpstan-param class-string<T> $class_name
+ * @phpstan-return T|false
*/
function _get_list_table( $class_name, $args = array() ) {
$core_classes = array(
@@ -64,6 +84,9 @@ function _get_list_table( $class_name, $args = array() ) {
*
* @param string $class_name The list table class to use.
* @param array $args An array containing _get_list_table() arguments.
+ *
+ * @phpstan-template T of WP_List_Table
+ * @phpstan-param class-string<T> $class_name
*/
$custom_class_name = apply_filters( 'wp_list_table_class_name', $class_name, $args );
diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php
index a24aae32cc..b535b3acbf 100644
--- a/wp-admin/includes/template.php
+++ b/wp-admin/includes/template.php
@@ -2725,7 +2725,9 @@ function _wp_admin_html_begin() {
*
* @since 3.0.0
*
- * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen.
+ * @param string|WP_Screen|null $hook_name The hook name (also known as the hook suffix) used to determine the screen.
+ * A `WP_Screen` instance is returned as-is. If null, the current
+ * $hook_suffix global is used.
* @return WP_Screen Screen object.
*/
function convert_to_screen( $hook_name ) {
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 610ce7ec33..82c1b17674 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-63647';
+$wp_version = '7.2-alpha-63648';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.