Skip to content

Commit

Permalink
Coding Standards: Correct sprintf() calls for messages in `wp-admin…
Browse files Browse the repository at this point in the history
…/upload.php`.

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

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

See #57839.
Built from https://develop.svn.wordpress.org/trunk@55631


git-svn-id: http://core.svn.wordpress.org/trunk@55143 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
SergeyBiryukov committed Apr 6, 2023
1 parent 4f6e5a3 commit 03c3f90
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 20 deletions.
69 changes: 50 additions & 19 deletions wp-admin/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,85 +15,116 @@

$message = '';
if ( ! empty( $_GET['posted'] ) ) {
$message = __( 'Media file updated.' );
$message = __( 'Media file updated.' );

$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'posted' ), $_SERVER['REQUEST_URI'] );
unset( $_GET['posted'] );
}

if ( ! empty( $_GET['attached'] ) && absint( $_GET['attached'] ) ) {
$attached = absint( $_GET['attached'] );

if ( 1 === $attached ) {
$message = __( 'Media file attached.' );
} else {
/* translators: %s: Number of media files. */
$message = _n( '%s media file attached.', '%s media files attached.', $attached );
$message = sprintf(
/* translators: %s: Number of media files. */
_n( '%s media file attached.', '%s media files attached.', $attached ),
number_format_i18n( $attached )
);
}
$message = sprintf( $message, $attached );

$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
unset( $_GET['detach'], $_GET['attached'] );
}

if ( ! empty( $_GET['detach'] ) && absint( $_GET['detach'] ) ) {
$detached = absint( $_GET['detach'] );

if ( 1 === $detached ) {
$message = __( 'Media file detached.' );
} else {
/* translators: %s: Number of media files. */
$message = _n( '%s media file detached.', '%s media files detached.', $detached );
$message = sprintf(
/* translators: %s: Number of media files. */
_n( '%s media file detached.', '%s media files detached.', $detached ),
number_format_i18n( $detached )
);
}
$message = sprintf( $message, $detached );

$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
unset( $_GET['detach'], $_GET['attached'] );
}

if ( ! empty( $_GET['deleted'] ) && absint( $_GET['deleted'] ) ) {
$deleted = absint( $_GET['deleted'] );

if ( 1 === $deleted ) {
$message = __( 'Media file permanently deleted.' );
} else {
/* translators: %s: Number of media files. */
$message = _n( '%s media file permanently deleted.', '%s media files permanently deleted.', $deleted );
$message = sprintf(
/* translators: %s: Number of media files. */
_n( '%s media file permanently deleted.', '%s media files permanently deleted.', $deleted ),
number_format_i18n( $deleted )
);
}
$message = sprintf( $message, $deleted );

$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'deleted' ), $_SERVER['REQUEST_URI'] );
unset( $_GET['deleted'] );
}

if ( ! empty( $_GET['trashed'] ) && absint( $_GET['trashed'] ) ) {
$trashed = absint( $_GET['trashed'] );

if ( 1 === $trashed ) {
$message = __( 'Media file moved to the Trash.' );
} else {
/* translators: %s: Number of media files. */
$message = _n( '%s media file moved to the Trash.', '%s media files moved to the Trash.', $trashed );
$message = sprintf(
/* translators: %s: Number of media files. */
_n( '%s media file moved to the Trash.', '%s media files moved to the Trash.', $trashed ),
number_format_i18n( $trashed )
);
}
$message = sprintf( $message, $trashed );
$message .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ) . '">' . __( 'Undo' ) . '</a>';

$message .= sprintf(
' <a href="%1$s">%2$s</a>',
esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ),
__( 'Undo' )
);

$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'trashed' ), $_SERVER['REQUEST_URI'] );
unset( $_GET['trashed'] );
}

if ( ! empty( $_GET['untrashed'] ) && absint( $_GET['untrashed'] ) ) {
$untrashed = absint( $_GET['untrashed'] );

if ( 1 === $untrashed ) {
$message = __( 'Media file restored from the Trash.' );
} else {
/* translators: %s: Number of media files. */
$message = _n( '%s media file restored from the Trash.', '%s media files restored from the Trash.', $untrashed );
$message = sprintf(
/* translators: %s: Number of media files. */
_n( '%s media file restored from the Trash.', '%s media files restored from the Trash.', $untrashed ),
number_format_i18n( $untrashed )
);
}
$message = sprintf( $message, $untrashed );

$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'untrashed' ), $_SERVER['REQUEST_URI'] );
unset( $_GET['untrashed'] );
}

$messages[1] = __( 'Media file updated.' );
$messages[2] = __( 'Media file permanently deleted.' );
$messages[3] = __( 'Error saving media file.' );
$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>';
$messages[4] = __( 'Media file moved to the Trash.' ) . sprintf(
' <a href="%1$s">%2$s</a>',
esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ),
__( 'Undo' )
);
$messages[5] = __( 'Media file restored from the Trash.' );

if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) {
$message = $messages[ $_GET['message'] ];
$message = $messages[ $_GET['message'] ];

$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message' ), $_SERVER['REQUEST_URI'] );
}

Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3-alpha-55630';
$wp_version = '6.3-alpha-55631';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 03c3f90

Please sign in to comment.