Make WordPress Core

Changeset 55631


Ignore:
Timestamp:
04/06/2023 05:37:45 PM (11 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Correct sprintf() calls for messages in wp-admin/upload.php.

This ensures that sprintf() is not unnecessarily applied to strings without any placeholders.

Follow-up to [31941], [31619], [36328], [55178].

See #57839.

File:
1 edited

Legend:

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

    r55412 r55631  
    1616$message = '';
    1717if ( ! empty( $_GET['posted'] ) ) {
    18     $message                = __( 'Media file updated.' );
     18    $message = __( 'Media file updated.' );
     19
    1920    $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'posted' ), $_SERVER['REQUEST_URI'] );
    2021    unset( $_GET['posted'] );
     
    2324if ( ! empty( $_GET['attached'] ) && absint( $_GET['attached'] ) ) {
    2425    $attached = absint( $_GET['attached'] );
     26
    2527    if ( 1 === $attached ) {
    2628        $message = __( 'Media file attached.' );
    2729    } else {
    28         /* translators: %s: Number of media files. */
    29         $message = _n( '%s media file attached.', '%s media files attached.', $attached );
    30     }
    31     $message                = sprintf( $message, $attached );
     30        $message = sprintf(
     31            /* translators: %s: Number of media files. */
     32            _n( '%s media file attached.', '%s media files attached.', $attached ),
     33            number_format_i18n( $attached )
     34        );
     35    }
     36
    3237    $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
    3338    unset( $_GET['detach'], $_GET['attached'] );
     
    3641if ( ! empty( $_GET['detach'] ) && absint( $_GET['detach'] ) ) {
    3742    $detached = absint( $_GET['detach'] );
     43
    3844    if ( 1 === $detached ) {
    3945        $message = __( 'Media file detached.' );
    4046    } else {
    41         /* translators: %s: Number of media files. */
    42         $message = _n( '%s media file detached.', '%s media files detached.', $detached );
    43     }
    44     $message                = sprintf( $message, $detached );
     47        $message = sprintf(
     48            /* translators: %s: Number of media files. */
     49            _n( '%s media file detached.', '%s media files detached.', $detached ),
     50            number_format_i18n( $detached )
     51        );
     52    }
     53
    4554    $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
    4655    unset( $_GET['detach'], $_GET['attached'] );
     
    4958if ( ! empty( $_GET['deleted'] ) && absint( $_GET['deleted'] ) ) {
    5059    $deleted = absint( $_GET['deleted'] );
     60
    5161    if ( 1 === $deleted ) {
    5262        $message = __( 'Media file permanently deleted.' );
    5363    } else {
    54         /* translators: %s: Number of media files. */
    55         $message = _n( '%s media file permanently deleted.', '%s media files permanently deleted.', $deleted );
    56     }
    57     $message                = sprintf( $message, $deleted );
     64        $message = sprintf(
     65            /* translators: %s: Number of media files. */
     66            _n( '%s media file permanently deleted.', '%s media files permanently deleted.', $deleted ),
     67            number_format_i18n( $deleted )
     68        );
     69    }
     70
    5871    $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'deleted' ), $_SERVER['REQUEST_URI'] );
    5972    unset( $_GET['deleted'] );
     
    6275if ( ! empty( $_GET['trashed'] ) && absint( $_GET['trashed'] ) ) {
    6376    $trashed = absint( $_GET['trashed'] );
     77
    6478    if ( 1 === $trashed ) {
    6579        $message = __( 'Media file moved to the Trash.' );
    6680    } else {
    67         /* translators: %s: Number of media files. */
    68         $message = _n( '%s media file moved to the Trash.', '%s media files moved to the Trash.', $trashed );
    69     }
    70     $message                = sprintf( $message, $trashed );
    71     $message               .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ) . '">' . __( 'Undo' ) . '</a>';
     81        $message = sprintf(
     82            /* translators: %s: Number of media files. */
     83            _n( '%s media file moved to the Trash.', '%s media files moved to the Trash.', $trashed ),
     84            number_format_i18n( $trashed )
     85        );
     86    }
     87
     88    $message .= sprintf(
     89        ' <a href="%1$s">%2$s</a>',
     90        esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ),
     91        __( 'Undo' )
     92    );
     93
    7294    $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'trashed' ), $_SERVER['REQUEST_URI'] );
    7395    unset( $_GET['trashed'] );
     
    7698if ( ! empty( $_GET['untrashed'] ) && absint( $_GET['untrashed'] ) ) {
    7799    $untrashed = absint( $_GET['untrashed'] );
     100
    78101    if ( 1 === $untrashed ) {
    79102        $message = __( 'Media file restored from the Trash.' );
    80103    } else {
    81         /* translators: %s: Number of media files. */
    82         $message = _n( '%s media file restored from the Trash.', '%s media files restored from the Trash.', $untrashed );
    83     }
    84     $message                = sprintf( $message, $untrashed );
     104        $message = sprintf(
     105            /* translators: %s: Number of media files. */
     106            _n( '%s media file restored from the Trash.', '%s media files restored from the Trash.', $untrashed ),
     107            number_format_i18n( $untrashed )
     108        );
     109    }
     110
    85111    $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'untrashed' ), $_SERVER['REQUEST_URI'] );
    86112    unset( $_GET['untrashed'] );
     
    90116$messages[2] = __( 'Media file permanently deleted.' );
    91117$messages[3] = __( 'Error saving media file.' );
    92 $messages[4] = __( 'Media file moved to the Trash.' ) . ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ) . '">' . __( 'Undo' ) . '</a>';
     118$messages[4] = __( 'Media file moved to the Trash.' ) . sprintf(
     119    ' <a href="%1$s">%2$s</a>',
     120    esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ),
     121    __( 'Undo' )
     122);
    93123$messages[5] = __( 'Media file restored from the Trash.' );
    94124
    95125if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) {
    96     $message                = $messages[ $_GET['message'] ];
     126    $message = $messages[ $_GET['message'] ];
     127
    97128    $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message' ), $_SERVER['REQUEST_URI'] );
    98129}
Note: See TracChangeset for help on using the changeset viewer.