Make WordPress Core


Ignore:
Timestamp:
04/26/2022 02:54:37 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class.wp-scripts.php.

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 $echo parameter to $display in WP_Scripts class methods.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.

File:
1 edited

Legend:

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

    r52937 r53283  
    191191     *
    192192     * @since 2.1.0
    193      * @since 2.8.0 Added the `$echo` parameter.
     193     * @since 2.8.0 Added the `$display` parameter.
    194194     * @deprecated 3.3.0
    195195     *
    196196     * @see print_extra_script()
    197197     *
    198      * @param string $handle The script's registered handle.
    199      * @param bool   $echo   Optional. Whether to echo the extra script
    200      *                       instead of just returning it. Default true.
    201      * @return bool|string|void Void if no data exists, extra scripts if `$echo` is true,
     198     * @param string $handle  The script's registered handle.
     199     * @param bool   $display Optional. Whether to print the extra script
     200     *                        instead of just returning it. Default true.
     201     * @return bool|string|void Void if no data exists, extra scripts if `$display` is true,
    202202     *                          true otherwise.
    203203     */
    204     public function print_scripts_l10n( $handle, $echo = true ) {
     204    public function print_scripts_l10n( $handle, $display = true ) {
    205205        _deprecated_function( __FUNCTION__, '3.3.0', 'WP_Scripts::print_extra_script()' );
    206         return $this->print_extra_script( $handle, $echo );
     206        return $this->print_extra_script( $handle, $display );
    207207    }
    208208
     
    212212     * @since 3.3.0
    213213     *
    214      * @param string $handle The script's registered handle.
    215      * @param bool   $echo   Optional. Whether to echo the extra script
    216      *                       instead of just returning it. Default true.
    217      * @return bool|string|void Void if no data exists, extra scripts if `$echo` is true,
     214     * @param string $handle  The script's registered handle.
     215     * @param bool   $display Optional. Whether to print the extra script
     216     *                        instead of just returning it. Default true.
     217     * @return bool|string|void Void if no data exists, extra scripts if `$display` is true,
    218218     *                          true otherwise.
    219219     */
    220     public function print_extra_script( $handle, $echo = true ) {
     220    public function print_extra_script( $handle, $display = true ) {
    221221        $output = $this->get_data( $handle, 'data' );
    222222        if ( ! $output ) {
     
    224224        }
    225225
    226         if ( ! $echo ) {
     226        if ( ! $display ) {
    227227            return $output;
    228228        }
     
    445445     * @param string $position Optional. Whether to add the inline script
    446446     *                         before the handle or after. Default 'after'.
    447      * @param bool   $echo     Optional. Whether to echo the script
     447     * @param bool   $display  Optional. Whether to print the script
    448448     *                         instead of just returning it. Default true.
    449449     * @return string|false Script on success, false otherwise.
    450450     */
    451     public function print_inline_script( $handle, $position = 'after', $echo = true ) {
     451    public function print_inline_script( $handle, $position = 'after', $display = true ) {
    452452        $output = $this->get_data( $handle, $position );
    453453
     
    458458        $output = trim( implode( "\n", $output ), "\n" );
    459459
    460         if ( $echo ) {
     460        if ( $display ) {
    461461            printf( "<script%s id='%s-js-%s'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), esc_attr( $position ), $output );
    462462        }
     
    583583     * @since 5.0.0
    584584     *
    585      * @param string $handle Name of the script to add the inline script to.
    586      *                       Must be lowercase.
    587      * @param bool   $echo   Optional. Whether to echo the script
    588      *                       instead of just returning it. Default true.
     585     * @param string $handle  Name of the script to add the inline script to.
     586     *                        Must be lowercase.
     587     * @param bool   $display Optional. Whether to print the script
     588     *                        instead of just returning it. Default true.
    589589     * @return string|false Script on success, false otherwise.
    590590     */
    591     public function print_translations( $handle, $echo = true ) {
     591    public function print_translations( $handle, $display = true ) {
    592592        if ( ! isset( $this->registered[ $handle ] ) || empty( $this->registered[ $handle ]->textdomain ) ) {
    593593            return false;
     
    611611JS;
    612612
    613         if ( $echo ) {
     613        if ( $display ) {
    614614            printf( "<script%s id='%s-js-translations'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), $output );
    615615        }
Note: See TracChangeset for help on using the changeset viewer.