Make WordPress Core

Changeset 53192


Ignore:
Timestamp:
04/17/2022 10:49:10 AM (2 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/media.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 $return parameter to $return_type in media_sideload_image().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185].

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/media.php

    r52837 r53192  
    975975 *
    976976 * @since 2.6.0
    977  * @since 4.2.0 Introduced the `$return` parameter.
    978  * @since 4.8.0 Introduced the 'id' option for the `$return` parameter.
     977 * @since 4.2.0 Introduced the `$return_type` parameter.
     978 * @since 4.8.0 Introduced the 'id' option for the `$return_type` parameter.
    979979 * @since 5.3.0 The `$post_id` parameter was made optional.
    980980 * @since 5.4.0 The original URL of the attachment is stored in the `_source_url`
    981981 *              post meta value.
    982982 *
    983  * @param string $file    The URL of the image to download.
    984  * @param int    $post_id Optional. The post ID the media is to be associated with.
    985  * @param string $desc    Optional. Description of the image.
    986  * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL),
    987  *                        or 'id' (attachment ID). Default 'html'.
     983 * @param string $file        The URL of the image to download.
     984 * @param int    $post_id     Optional. The post ID the media is to be associated with.
     985 * @param string $desc        Optional. Description of the image.
     986 * @param string $return_type Optional. Accepts 'html' (image tag html) or 'src' (URL),
     987 *                            or 'id' (attachment ID). Default 'html'.
    988988 * @return string|int|WP_Error Populated HTML img tag, attachment ID, or attachment source
    989989 *                             on success, WP_Error object otherwise.
    990990 */
    991 function media_sideload_image( $file, $post_id = 0, $desc = null, $return = 'html' ) {
     991function media_sideload_image( $file, $post_id = 0, $desc = null, $return_type = 'html' ) {
    992992    if ( ! empty( $file ) ) {
    993993
     
    10441044
    10451045        // If attachment ID was requested, return it.
    1046         if ( 'id' === $return ) {
     1046        if ( 'id' === $return_type ) {
    10471047            return $id;
    10481048        }
     
    10531053    // Finally, check to make sure the file has been saved, then return the HTML.
    10541054    if ( ! empty( $src ) ) {
    1055         if ( 'src' === $return ) {
     1055        if ( 'src' === $return_type ) {
    10561056            return $src;
    10571057        }
Note: See TracChangeset for help on using the changeset viewer.