Make WordPress Core


Ignore:
Timestamp:
09/02/2026 06:36:32 PM (9 days ago)
Author:
westonruter
Message:

Code Quality: Correct three inverted $display return docs.

WP_Styles::print_inline_style(), WP_Scripts::print_extra_script() and the deprecated WP_Scripts::print_scripts_l10n() each document their return the wrong way round. All three say the markup comes back when $display is true, but the string is returned on the ! $display branch and the printing branch returns true. The wording has read this way since r36744, so anyone consulting it to decide which argument to pass was told the opposite of what the code does.

Swapping true for false in the three descriptions corrects that, and a conditional @phpstan-return pins the two behaviors apart, since the plain unions collapse the distinction. print_inline_style() now resolves to bool when printing and string|false when retrieving, rather than string|bool either way, and print_extra_script() to true|null and string|null rather than bool|string|null. The narrower retrieval types matter at the two internal call sites that pass false and then use the result as a string.

WP_Scripts::print_inline_script() and print_translations() are left alone. Both print and then return the same value, so their existing string|false is accurate in either mode and there is nothing for a condition to separate.

Developed as subset of https://github.com/WordPress/wordpress-develop/pull/13359.
Follow-up to r36744, r62178.

Props apermo, westonruter.
See #65817.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-scripts.php

    r62550 r63440  
    202202         * @param bool   $display Optional. Whether to print the extra script
    203203         *                        instead of just returning it. Default true.
    204          * @return bool|string|null Null if no data exists, extra scripts if `$display` is true,
     204         * @return bool|string|null Null if no data exists, extra scripts if `$display` is false,
    205205         *                          true otherwise.
     206         * @phpstan-return ( $display is true ? true|null : string|null )
    206207         */
    207208        public function print_scripts_l10n( $handle, $display = true ) {
     
    218219         * @param bool   $display Optional. Whether to print the extra script
    219220         *                        instead of just returning it. Default true.
    220          * @return bool|string|null Null if no data exists, extra scripts if `$display` is true,
     221         * @return bool|string|null Null if no data exists, extra scripts if `$display` is false,
    221222         *                          true otherwise.
     223         * @phpstan-return ( $display is true ? true|null : string|null )
    222224         */
    223225        public function print_extra_script( $handle, $display = true ) {
Note: See TracChangeset for help on using the changeset viewer.