This aims to:
* Perform the checks as early as possible to avoid redundant function calls.
* Remove an empty conditiaonal branch and make the exit conditions clearer.
* Bring the formatting in line with other multi-line conditionals in core.
Follow-up to [56836].
See #59650.
Built from https://develop.svn.wordpress.org/trunk@57123
git-svn-id: http://core.svn.wordpress.org/trunk@56634 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Move the label after the checkbox in `WP_List_Table` instances. Resolve a false positive that will be presented by automated accessibility testing tools. Follow up to [55954].
Props dimitrism, joedolson, sabernhardt, oglekler, marybaum, tobiasbg.
Fixes#58703.
Built from https://develop.svn.wordpress.org/trunk@56665
git-svn-id: http://core.svn.wordpress.org/trunk@56177 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Replaces `trigger_error()` with `wp_trigger_error()` in each of the `WP_List_Table` magic methods.
[56349] added the dynamic properties deprecation messages to the `__get()`, `__set()`, `__isset()`, `__unset()` magic methods. Since that commit, `wp_trigger_error()` was introduced (see [56530]) as a wrapper for `trigger_error()`.
Follow-up to [56349], [56356], [56530].
See #58896, #57686.
Built from https://develop.svn.wordpress.org/trunk@56542
git-svn-id: http://core.svn.wordpress.org/trunk@56054 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Changes "define" to "declare" in the deprecation message in `WP_List_Table` magic methods.
Why is "declare" better?
It aligns well to:
* the topic of and published information about dynamic properties.
* the act of explicitly listing the variable as a property on the class.
The goal of this message is guide developers to change their code. Changing the term to "declare" hopefully will aid in the understanding of what is being asked of developers when this deprecation is thrown.
Follow-up [56349].
Props hellofromTonya, antonvlasenko.
Fixes#58896.
Built from https://develop.svn.wordpress.org/trunk@56356
git-svn-id: http://core.svn.wordpress.org/trunk@55868 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The unknown use of unknown dynamic property within the `WP_List_Table` property magic methods is now deprecated. A descriptive deprecation notice is provided to alert developers to declare the property on the child class extending `WP_List_Table`.
Changes in this commit:
* Adds a deprecation notice to the `__get()`, `__set()`, `__isset()`, `__unset()` magic methods, i.e. to alert and inform developers when attempting to get/set/isset/unset a dynamic property.
* Fixes `__get()` to explicitly returns `null` when attempting to get a dynamic property.
* Removes returning the value when setting a declared property, as (a) unnecessary and (b) `__set()` should return `void` [https://www.php.net/manual/en/language.oop5.overloading.php#object.set per the PHP handbook].
* Adds unit tests for happy and unhappy paths.
For backward compatibility, no changes are made to the internal declared properties listed in `$compat_fields` and accessed through the magic methods.
For example:
A child class uses a property named `$data` that is not declared / defined as a property on the child class. When getting its value, e.g. `$list_table->data`, the `WP_List_Table::__get()` magic method is invoked, the following deprecation notice thrown, and `null` returned:
>The property `data` is not defined. Setting a dynamic (undefined) property is deprecated since version 6.4.0! Instead, define the property on the class.
=== Why not remove the magic methods, remove the `$compat_fields` property, and restore the properties `public`?
tl;dr Backward compatibility.
Several plugins, one of which has over 5M installs, add a property to the `$compat_fields` array. Removing the property would cause an `Undefined property` `Warning` (PHP 8) | `Notice` (PHP 7) to be thrown. Removing the associated code would change the functionality.
=== Why not limit the deprecation for PHP versions >= 8.2?
tl;dr original design intent and inform
The magic methods and `$compat_fields` property were added for one purpose: to continue providing external access to internal properties declared on `WP_List_Table`. They were not intended to be used for dynamic properties.
Deprecating that unintended usage both alerts developers a change is needed in their child class and informs them what to change.
References:
* Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.
* A [https://www.youtube.com/live/vDZWepDQQVE?feature=share&t=10097 live open public working session] where these changes were discussed and agreed to.
* [https://wiki.php.net/rfc/deprecate_dynamic_properties PHP RFC: Deprecate dynamic properties.]
Related to #14579, #22234, #30891.
Follow-up to [15491], [28493], [28521], [28524], [31146].
Props antonvlasenko, jrf, markjaquith, hellofromTonya, SergeyBiryukov, desrosj, peterwilsoncc, audrasjb, costdev, oglekler, jeffpaul.
Fixes#58896.
See #56034.
Built from https://develop.svn.wordpress.org/trunk@56349
git-svn-id: http://core.svn.wordpress.org/trunk@55861 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Replace use of `list` to parse array keys into variables. `list` throws errors if the keys don't exist, and many extenders will not define the new array keys. The code path already falls back effectively for empty values.
Also add translator comments to screen reader hidden text, fix a docblock, and fix an HTML error.
Follow up to [r55971].
Props kebbet, chouby, joedolson.
Fixes#32170.
Built from https://develop.svn.wordpress.org/trunk@56004
git-svn-id: http://core.svn.wordpress.org/trunk@55516 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Implement `aria-sort` and change icon states to indicate current sort for list tables. Allow screen reader users to get context about the current sort and allow sighted users to know how the table is currently sorted.
Props afercia, rianrietveld, joedolson, alexstine, johnjamesjacoby.
Fixes#32170.
Built from https://develop.svn.wordpress.org/trunk@55971
git-svn-id: http://core.svn.wordpress.org/trunk@55483 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Change the `label` for `.check-column` inside list tables to a block filling the entire cell. Improves accessibility by increasing the target area for the control.
Props mitchoyoshitaka, lessbloat, sabernhardt, ogleker, tacoverdo, joostdevalk, karmatosed.
Fixes#21516.
Built from https://develop.svn.wordpress.org/trunk@55954
git-svn-id: http://core.svn.wordpress.org/trunk@55466 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This aims to provide better context for translators and make it easier to determine that some strings contain hidden accessibility text and are not displayed in the UI.
Props kebbet, mercime, pavelevap, ocean90, swissspidy, Chouby, jipmoors, afercia, desrosj, costdev, audrasjb, SergeyBiryukov.
Fixes#29748.
Built from https://develop.svn.wordpress.org/trunk@55276
git-svn-id: http://core.svn.wordpress.org/trunk@54809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Remove the private delegation from the following classes and function:
* `WP_List_Table`
* `WP_Application_Passwords_List_Table`
* `WP_Comments_List_Table`
* `WP_Links_List_Table`
* `WP_Media_List_Table`
* `WP_MS_Sites_List_Table`
* `WP_MS_Themes_List_Table`
* `WP_MS_Users_List_Table`
* `WP_Plugin_Install_List_Table`
* `WP_Plugins_List_Table`
* `WP_Post_Comments_List_Table`
* `WP_Posts_List_Table`
* `WP_Terms_List_Table`
* `WP_Theme_Install_List_Table`
* `WP_Themes_List_Table`
* `WP_Users_List_Table`
* `_get_list_table()`
This change is to reflect the reality that list tables are very, very, very widely used by extenders and backward compatibility therefore needs to be maintained.
Introduces the filter `wp_list_table_class_name` within `_get_list_table()` to allow extenders to modify the list table returned for custom screens.
Props audrasjb, birgire, costdev, desrosj, faison, johnbillion, jrbeilke, kurtpayne, milana_cap, miqrogroove, nacin, peterwilsoncc, scribu, sergeybiryukov, sirzooro, westonruter, wonderboymusic.
Fixes#18449.
Built from https://develop.svn.wordpress.org/trunk@54378
git-svn-id: http://core.svn.wordpress.org/trunk@53937 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Many `WP_List_Table` child classes in core use mostly the same code to create their "view" links markup. To DRY-up the code, a new `WP_List_Table->get_view_links` method is being introduced to consolidate the HTML link generation when provided an array of links.
This change also implements this new method in the relevant `WP_List_Table_xxx` child classes `get_views` methods. Finally, unit tests are being added to validate view links markup and test for some "unhappy paths".
Props afercia, costdev, garrett-eclipse, Dharm1025, juhise, peterwilsoncc.
Fixes#42066.
Built from https://develop.svn.wordpress.org/trunk@54215
git-svn-id: http://core.svn.wordpress.org/trunk@53774 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.
There are a number of ways to mitigate this:
* If it is an accidental typo for a declared property: fix the typo.
* For known properties: declare them on the class.
* For unknown properties: add the magic `__get()`, `__set()`, et al. methods to the class or let the class extend `stdClass` which has highly optimized versions of these magic methods built in.
* For unknown ''use'' of dynamic properties, the `#[AllowDynamicProperties]` attribute can be added to the class. The attribute will automatically be inherited by child classes.
Trac ticket #56034 is open to investigate and handle the third and fourth type of situations, however it has become clear this will need more time and will not be ready in time for WP 6.1.
To reduce “noise” in the meantime, both in the error logs of WP users moving onto PHP 8.2, in the test run logs of WP itself, in test runs of plugins and themes, as well as to prevent duplicate tickets from being opened for the same issue, this commit adds the `#[AllowDynamicProperties]` attribute to all “parent” classes in WP.
The logic used for this commit is as follows:
* If a class already has the attribute: no action needed.
* If a class does not `extend`: add the attribute.
* If a class does `extend`:
- If it extends `stdClass`: no action needed (as `stdClass` supports dynamic properties).
- If it extends a PHP native class: add the attribute.
- If it extends a class from one of WP's external dependencies: add the attribute.
* In all other cases: no action — the attribute should not be needed as child classes inherit from the parent.
Whether or not a class contains magic methods has not been taken into account, as a review of the currently existing magic methods has shown that those are generally not sturdy enough and often even set dynamic properties (which they should not). See the [https://www.youtube.com/watch?v=vDZWepDQQVE live stream from August 16, 2022] for more details.
This commit only affects classes in the `src` directory of WordPress core.
* Tests should not get this attribute, but should be fixed to not use dynamic properties instead. Patches for this are already being committed under ticket #56033.
* While a number bundled themes (2014, 2019, 2020, 2021) contain classes, they are not a part of this commit and may be updated separately.
Reference: [https://wiki.php.net/rfc/deprecate_dynamic_properties PHP RFC: Deprecate dynamic properties].
Follow-up to [53922].
Props jrf, hellofromTonya, markjaquith, peterwilsoncc, costdev, knutsp, aristath.
See #56513, #56034.
Built from https://develop.svn.wordpress.org/trunk@54133
git-svn-id: http://core.svn.wordpress.org/trunk@53692 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This renames some variables for clarity, per the [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions Naming Conventions]:
> Don’t abbreviate variable names unnecessarily; let the code be unambiguous and self-documenting.
* `$out` is renamed to `$output` in various list table methods and admin functions.
* `$sep` is renamed to `$separator` in various list table methods and admin functions.
This affects:
* `WP_Comments_List_Table::handle_row_actions()`
* `WP_List_Table::row_actions()`
* `WP_Media_List_Table::column_default()`
* `WP_MS_Sites_List_Table::site_states()`
* `WP_MS_Users_List_Table::column_blogs()`
* `WP_Terms_List_Table::column_name()`
* `_wp_dashboard_recent_comments_row()`
* `image_align_input_fields()`
* `image_size_input_fields()`
* `wp_doc_link_parse()`
* `_post_states()`
* `_media_states()`
Follow-up to [8653], [8692], [8864], [8910], [8911], [8916], [9103], [9153], [10607], [15491], [17793], [32644], [54070].
Props mukesh27, costdev.
See #56448, #55647.
Built from https://develop.svn.wordpress.org/trunk@54071
git-svn-id: http://core.svn.wordpress.org/trunk@53630 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Improve the performance of `WP_List_Table::get_column_info()` by adding the primary column to the cached header values. This reduces the number of calls to the `WP_List_Table::get_primary_column_name()` method to once per table in line with the other header getter functions.
Props bobbingwide, chaion07, costdev, mikeschroder, mukesh27, peterwilsoncc, shetheliving, spacedmonkey.
Fixes#34564.
Built from https://develop.svn.wordpress.org/trunk@53868
git-svn-id: http://core.svn.wordpress.org/trunk@53427 1a063a9b-81f0-0310-95a4-ce76da25c4cd
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$default` parameter to `$default_value` in `WP_List_Table::get_items_per_page()`.
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53039
git-svn-id: http://core.svn.wordpress.org/trunk@52628 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Previously the first and last page pagination buttons were disabled when on their next or previous page respectively. This commit removes that unnecessary logic to keep these buttons enabled and avoid confusion in the user's navigation workflow.
New behavior:
- When on page 2, the go to first page `«` button is enabled
- When on the page before the last page, the go to last page `»` button is enabled
Follow-up to [32948], [47219].
Props wp_kc, ronakganatra, knutsp, sabernhardt, Hareesh Pillai, audrasjb, hellofromTonya.
Fixes#42763.
Built from https://develop.svn.wordpress.org/trunk@51880
git-svn-id: http://core.svn.wordpress.org/trunk@51473 1a063a9b-81f0-0310-95a4-ce76da25c4cd
As this can cause large, long running queries on sites with many posts, this filter allows the query to be modified, bypassing entirely if needed.
Fixes#51660.
Props geoffguillain, SergeyBiryukov, hareesh-pillai, hellofromTonya, TimothyBlynJacobs, whyisjake.
Built from https://develop.svn.wordpress.org/trunk@50163
git-svn-id: http://core.svn.wordpress.org/trunk@49842 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This joyous marriage means that users will no longer find a selected top bulk action on a list table unexpectedly being applied instead of their selected bottom bulk action. The top and bottom controls for changing user roles are equally wedded forever too.
Props clayray, subrataemfluence, garrett-eclipse, pbiron, hareesh-pillai
Fixes#46872
Built from https://develop.svn.wordpress.org/trunk@49944
git-svn-id: http://core.svn.wordpress.org/trunk@49643 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Using the canonical function name for PHP functions is strongly recommended, as aliases may be deprecated or removed without (much) warning.
This replaces all uses of the following:
* `join()` with `implode()`
* `sizeof()` with `count()`
* `is_writeable()` with `is_writable()`
* `doubleval()` with a `(float)` cast
In part, this is a follow-up to #47746.
Props jrf.
See #50767.
Built from https://develop.svn.wordpress.org/trunk@49193
git-svn-id: http://core.svn.wordpress.org/trunk@48955 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* `WP_List_Table::get_default_primary_column_name()` is a protected method, so calling it statically with the class name is bad practice.
* Similarly, this applies when calling a private constructor in `WP_Screen::get()`.
Props jrf.
See #50767.
Built from https://develop.svn.wordpress.org/trunk@49192
git-svn-id: http://core.svn.wordpress.org/trunk@48954 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The allowed format for bulk actions is now an associative array where each element represents either a top level option value and label, or an array representing an optgroup and its options.
For a standard option, the array element key is the field value and the array element value is the field label.
For an optgroup, the array element key is the label and the array element value is an associative array of options as above.
Props goldenapples, mattkeys, valentinbora, davidbaumwald
Fixes#19278
Built from https://develop.svn.wordpress.org/trunk@49190
git-svn-id: http://core.svn.wordpress.org/trunk@48952 1a063a9b-81f0-0310-95a4-ce76da25c4cd