WordPress.org

Make WordPress Core

Changeset 25577


Ignore:
Timestamp:
09/23/2013 06:52:04 PM (6 years ago)
Author:
nacin
Message:

Introduce a bulk_post_updated_messages filter.

props johnbillion for initial patch.
fixes #18710.

File:
1 edited

Legend:

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

    r25527 r25577  
    225225add_screen_option( 'per_page', array( 'label' => $title, 'default' => 20, 'option' => 'edit_' . $post_type . '_per_page' ) );
    226226
     227$bulk_counts = array(
     228    'updated'   => isset( $_REQUEST['updated'] )   ? absint( $_REQUEST['updated'] )   : 0,
     229    'locked'    => isset( $_REQUEST['locked'] )    ? absint( $_REQUEST['locked'] )    : 0,
     230    'deleted'   => isset( $_REQUEST['deleted'] )   ? absint( $_REQUEST['deleted'] )   : 0,
     231    'trashed'   => isset( $_REQUEST['trashed'] )   ? absint( $_REQUEST['trashed'] )   : 0,
     232    'untrashed' => isset( $_REQUEST['untrashed'] ) ? absint( $_REQUEST['untrashed'] ) : 0,
     233);
     234
     235$bulk_messages = array();
     236$bulk_messages['post'] = array(
     237    'updated'   => _n( '%s post updated.', '%s posts updated.', $bulk_counts['updated'] ),
     238    'locked'    => _n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', $bulk_counts['locked'] ),
     239    'deleted'   => _n( '%s post permanently deleted.', '%s posts permanently deleted.', $bulk_counts['deleted'] ),
     240    'trashed'   => _n( '%s post moved to the Trash.', '%s posts moved to the Trash.', $bulk_counts['trashed'] ),
     241    'untrashed' => _n( '%s post restored from the Trash.', '%s posts restored from the Trash.', $bulk_counts['untrashed'] ),
     242);
     243$bulk_messages['page'] = array(
     244    'updated'   => _n( '%s page updated.', '%s pages updated.', $bulk_counts['updated'] ),
     245    'locked'    => _n( '%s page not updated, somebody is editing it.', '%s pages not updated, somebody is editing them.', $bulk_counts['locked'] ),
     246    'deleted'   => _n( '%s page permanently deleted.', '%s pages permanently deleted.', $bulk_counts['deleted'] ),
     247    'trashed'   => _n( '%s page moved to the Trash.', '%s pages moved to the Trash.', $bulk_counts['trashed'] ),
     248    'untrashed' => _n( '%s page restored from the Trash.', '%s pages restored from the Trash.', $bulk_counts['untrashed'] ),
     249);
     250
     251/**
     252 * Filter the bulk action updated messages.
     253 *
     254 * By default, custom post types use the messages for the 'post' post type.
     255 *
     256 * @since 3.7.0
     257 *
     258 * @param array $bulk_messages Arrays of messages, each keyed by the corresponding post type. Messages are
     259 *                             keyed with 'updated', 'locked', 'deleted', 'trashed', and 'untrashed'.
     260 * @param array $bulk_counts   Array of item counts for each message, used to build internationalized strings.
     261 */
     262$bulk_messages = apply_filters( 'bulk_post_updated_messages', $bulk_messages, $bulk_counts );
     263$bulk_counts = array_filter( $bulk_counts );
     264
    227265require_once('./admin-header.php');
    228266?>
     
    237275?></h2>
    238276
    239 <?php if ( isset( $_REQUEST['locked'] ) || isset( $_REQUEST['updated'] ) || isset( $_REQUEST['deleted'] ) || isset( $_REQUEST['trashed'] ) || isset( $_REQUEST['untrashed'] ) ) {
    240     $messages = array();
    241 ?>
    242 <div id="message" class="updated"><p>
    243 <?php if ( isset( $_REQUEST['updated'] ) && $updated = absint( $_REQUEST['updated'] ) ) {
    244     $messages[] = sprintf( _n( '%s post updated.', '%s posts updated.', $updated ), number_format_i18n( $updated ) );
    245 }
    246 
    247 if ( isset( $_REQUEST['locked'] ) && $locked = absint( $_REQUEST['locked'] ) ) {
    248     $messages[] = sprintf( _n( '%s item not updated, somebody is editing it.', '%s items not updated, somebody is editing them.', $locked ), number_format_i18n( $locked ) );
    249 }
    250 
    251 if ( isset( $_REQUEST['deleted'] ) && $deleted = absint( $_REQUEST['deleted'] ) ) {
    252     $messages[] = sprintf( _n( 'Item permanently deleted.', '%s items permanently deleted.', $deleted ), number_format_i18n( $deleted ) );
    253 }
    254 
    255 if ( isset( $_REQUEST['trashed'] ) && $trashed = absint( $_REQUEST['trashed'] ) ) {
    256     $messages[] = sprintf( _n( 'Item moved to the Trash.', '%s items moved to the Trash.', $trashed ), number_format_i18n( $trashed ) );
    257     $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
    258     $messages[] = '<a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", "bulk-posts" ) ) . '">' . __('Undo') . '</a>';
    259 }
    260 
    261 if ( isset( $_REQUEST['untrashed'] ) && $untrashed = absint( $_REQUEST['untrashed'] ) ) {
    262     $messages[] = sprintf( _n( 'Item restored from the Trash.', '%s items restored from the Trash.', $untrashed ), number_format_i18n( $untrashed ) );
     277<?php
     278// If we have a bulk message to issue:
     279$messages = array();
     280foreach ( $bulk_counts as $message => $count ) {
     281    if ( isset( $bulk_messages[ $post_type ][ $message ] ) )
     282        $messages[] = sprintf( $bulk_messages[ $post_type ][ $message ], number_format_i18n( $count ) );
     283    elseif ( isset( $bulk_messages['post'][ $message ] ) )
     284        $messages[] = sprintf( $bulk_messages['post'][ $message ], number_format_i18n( $count ) );
     285
     286    if ( $message == 'trashed' && isset( $_REQUEST['ids'] ) ) {
     287        $ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] );
     288        $messages[] = '<a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", "bulk-posts" ) ) . '">' . __('Undo') . '</a>';
     289    }
    263290}
    264291
    265292if ( $messages )
    266     echo join( ' ', $messages );
     293    echo '<div id="message" class="updated"><p>' . join( ' ', $messages ) . '</p></div>';
    267294unset( $messages );
    268295
    269296$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI'] );
    270297?>
    271 </p></div>
    272 <?php } ?>
    273298
    274299<?php $wp_list_table->views(); ?>
Note: See TracChangeset for help on using the changeset viewer.