WordPress.org

Make WordPress Core

Ticket #12732: bulk_actions_filter.diff

File bulk_actions_filter.diff, 14.0 KB (added by ptahdunbar, 5 years ago)

Uses a filter approach

  • wp-admin/users.php

     
    348348if ( ! empty($messages) ) { 
    349349        foreach ( $messages as $msg ) 
    350350                echo $msg; 
    351 } ?> 
     351} 
    352352 
     353// Setup Bulk Actions 
     354$bulk_actions['-1'] = __('Bulk Actions'); 
     355if ( !is_multisite() && current_user_can('delete_users') ) 
     356        $bulk_actions['delete'] = __('Delete'); 
     357else 
     358        $bulk_actions['remove'] = __('Remove'); 
     359 
     360$bulk_actions = apply_filters( 'bulk_actions-users', $bulk_actions ); 
     361?> 
     362 
    353363<div class="wrap"> 
    354364<?php screen_icon(); ?> 
    355365<h2><?php echo esc_html( $title ); if ( current_user_can( 'create_users' ) ) { ?>  <a href="user-new.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'user'); ?></a><?php } 
     
    410420 
    411421<div class="alignleft actions"> 
    412422<select name="action"> 
    413 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option> 
    414 <?php if ( !is_multisite() && current_user_can('delete_users') ) { ?> 
    415 <option value="delete"><?php _e('Delete'); ?></option> 
    416 <?php } else { ?> 
    417 <option value="remove"><?php _e('Remove'); ?></option> 
    418 <?php } ?> 
     423        <?php wp_list_bulk_actions( $bulk_actions ); ?> 
    419424</select> 
    420425<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" /> 
    421426<label class="screen-reader-text" for="new_role"><?php _e('Change role to&hellip;') ?></label><select name="new_role" id="new_role"><option value=''><?php _e('Change role to&hellip;') ?></option><?php wp_dropdown_roles(); ?></select> 
     
    483488 
    484489<div class="alignleft actions"> 
    485490<select name="action2"> 
    486 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option> 
    487 <?php if ( !is_multisite() && current_user_can('delete_users') ) { ?> 
    488 <option value="delete"><?php _e('Delete'); ?></option> 
    489 <?php } else { ?> 
    490 <option value="remove"><?php _e('Remove'); ?></option> 
    491 <?php } ?></select> 
     491        <?php wp_list_bulk_actions( $bulk_actions ); ?> 
     492</select> 
    492493<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" /> 
    493494</div> 
    494495 
  • wp-admin/edit-comments.php

     
    116116$comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : ''; 
    117117 
    118118$search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : ''; 
    119 $search = esc_attr( $search_dirty ); ?> 
     119$search = esc_attr( $search_dirty ); 
    120120 
     121// Setup Bulk Actions 
     122$bulk_actions['-1'] = __('Bulk Actions'); 
     123if ( 'all' == $comment_status || 'approved' == $comment_status ) 
     124        $bulk_actions['unapprove'] = __('Unapprove'); 
     125if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ) 
     126        $bulk_actions['approve'] = __('Approve'); 
     127if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ) 
     128        $bulk_actions['spam'] = _x('Mark as Spam', 'comment'); 
     129if ( 'trash' == $comment_status ) 
     130        $bulk_actions['untrash'] = __('Restore'); 
     131elseif ( 'spam' == $comment_status ) 
     132        $bulk_actions['unspam'] = _x('Not Spam', 'comment'); 
     133if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ) 
     134        $bulk_actions['delete'] = __('Delete Permanently'); 
     135else 
     136        $bulk_actions['trash'] = __('Move to Trash'); 
     137 
     138$bulk_actions = apply_filters( 'bulk_actions-comments', $bulk_actions ); 
     139?> 
     140 
    121141<div class="wrap"> 
    122142<?php screen_icon(); ?> 
    123143<h2><?php echo esc_html( $title ); 
     
    308328 
    309329<div class="alignleft actions"> 
    310330<select name="action"> 
    311 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option> 
    312 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?> 
    313 <option value="unapprove"><?php _e('Unapprove'); ?></option> 
    314 <?php endif; ?> 
    315 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?> 
    316 <option value="approve"><?php _e('Approve'); ?></option> 
    317 <?php endif; ?> 
    318 <?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?> 
    319 <option value="spam"><?php echo _x('Mark as Spam', 'comment'); ?></option> 
    320 <?php endif; ?> 
    321 <?php if ( 'trash' == $comment_status ): ?> 
    322 <option value="untrash"><?php _e('Restore'); ?></option> 
    323 <?php elseif ( 'spam' == $comment_status ): ?> 
    324 <option value="unspam"><?php echo _x('Not Spam', 'comment'); ?></option> 
    325 <?php endif; ?> 
    326 <?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?> 
    327 <option value="delete"><?php _e('Delete Permanently'); ?></option> 
    328 <?php else: ?> 
    329 <option value="trash"><?php _e('Move to Trash'); ?></option> 
    330 <?php endif; ?> 
     331        <?php wp_list_bulk_actions( $bulk_actions ); ?> 
    331332</select> 
    332333<input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" /> 
    333334<?php wp_nonce_field('bulk-comments'); ?> 
     
    405406 
    406407<div class="alignleft actions"> 
    407408<select name="action2"> 
    408 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option> 
    409 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?> 
    410 <option value="unapprove"><?php _e('Unapprove'); ?></option> 
    411 <?php endif; ?> 
    412 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?> 
    413 <option value="approve"><?php _e('Approve'); ?></option> 
    414 <?php endif; ?> 
    415 <?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?> 
    416 <option value="spam"><?php echo _x('Mark as Spam', 'comment'); ?></option> 
    417 <?php endif; ?> 
    418 <?php if ( 'trash' == $comment_status ): ?> 
    419 <option value="untrash"><?php _e('Restore'); ?></option> 
    420 <?php endif; ?> 
    421 <?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?> 
    422 <option value="delete"><?php _e('Delete Permanently'); ?></option> 
    423 <?php elseif ( 'spam' == $comment_status ): ?> 
    424 <option value="unspam"><?php echo _x('Not Spam', 'comment'); ?></option> 
    425 <?php else: ?> 
    426 <option value="trash"><?php _e('Move to Trash'); ?></option> 
    427 <?php endif; ?> 
     409        <?php wp_list_bulk_actions( $bulk_actions ); ?> 
    428410</select> 
    429411<input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" /> 
    430412 
  • wp-admin/includes/misc.php

     
    682682</fieldset> 
    683683<?php 
    684684} 
    685 ?> 
     685 
     686/** 
     687 * Outputs a list of bulk actions. 
     688 * 
     689 * @since 3.0.0 
     690 **/ 
     691function wp_list_bulk_actions( $bulk_actions = array() ) { 
     692        if ( empty($bulk_actions) ) 
     693                return false; 
     694         
     695        $actions = array(); 
     696        foreach ( (array) $bulk_actions as $value => $label ) { 
     697                $actions[$value] = "<option value=\"{$value}\">{$label}</option>"; 
     698        } 
     699         
     700        echo join( "\n", apply_filters( 'wp_list_bulk_actions', $actions ) ); 
     701} 
     702?> 
     703 No newline at end of file 
  • wp-admin/edit-tags.php

     
    173173$messages[5] = __('Item not updated.'); 
    174174$messages[6] = __('Items deleted.'); 
    175175 
     176// Setup Bulk Actions  
     177$bulk_actions = array( 
     178        '-1' => __('Bulk Actions'), 
     179        'delete' => __('Delete'), 
     180); 
     181 
     182$bulk_actions = apply_filters( "bulk_actions-$taxonomy", $bulk_actions ); 
    176183?> 
    177184 
    178185<div class="wrap nosubsub"> 
     
    248255 
    249256<div class="alignleft actions"> 
    250257<select name="action"> 
    251 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option> 
    252 <option value="delete"><?php _e('Delete'); ?></option> 
     258        <?php wp_list_bulk_actions( $bulk_actions ); ?> 
    253259</select> 
    254260<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" /> 
    255261<?php wp_nonce_field('bulk-tags'); ?> 
     
    286292 
    287293<div class="alignleft actions"> 
    288294<select name="action2"> 
    289 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option> 
    290 <option value="delete"><?php _e('Delete'); ?></option> 
     295        <?php wp_list_bulk_actions( $bulk_actions ); ?> 
    291296</select> 
    292297<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" /> 
    293298</div> 
  • wp-admin/ms-sites.php

     
    7171        <?php 
    7272} 
    7373 
     74// Setup Bulk Actions 
     75$bulk_actions = array( 
     76        '-1' => __('Bulk Actions'), 
     77        'delete' => __('Delete'), 
     78        'spam' => _x( 'Mark as Spam', 'site' ), 
     79        'notspam' => _x( 'Not Spam', 'site' ), 
     80); 
     81 
     82$bulk_actions = apply_filters( 'bulk_actions-ms_sites', $bulk_actions ); 
     83 
    7484$action = isset( $_GET['action'] ) ? $_GET['action'] : 'list'; 
    7585 
    7686switch ( $action ) { 
     
    412422                <div class="tablenav"> 
    413423                <div class="alignleft actions"> 
    414424                        <select name="action"> 
    415                                 <option value="-1" selected="selected"><?php _e( 'Bulk Actions' ); ?></option> 
    416                                 <option value="delete"><?php _e( 'Delete' ); ?></option> 
    417                                 <option value="spam"><?php echo _x( 'Mark as Spam', 'site' ); ?></option> 
    418                                 <option value="notspam"><?php echo _x( 'Not Spam', 'site' ); ?></option> 
     425                                <?php wp_list_bulk_actions( $bulk_actions ); ?> 
    419426                        </select> 
    420427                        <input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" name="doaction" id="doaction" class="button-secondary action" /> 
    421428                        <?php wp_nonce_field( 'bulk-ms-sites' ); ?> 
     
    663670 
    664671                        <div class="alignleft actions"> 
    665672                        <select name="action2"> 
    666                                 <option value="-1" selected="selected"><?php _e( 'Bulk Actions' ); ?></option> 
    667                                 <option value="delete"><?php _e( 'Delete' ); ?></option> 
    668                                 <option value="spam"><?php echo _x( 'Mark as Spam', 'site' ); ?></option> 
    669                                 <option value="notspam"><?php echo _x( 'Not Spam', 'site' ); ?></option> 
     673                                <?php wp_list_bulk_actions( $bulk_actions ); ?> 
    670674                        </select> 
    671675                        <input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" /> 
    672676                        </div> 
  • wp-admin/edit.php

     
    161161if ( empty($_GET['mode']) ) 
    162162        $mode = 'list'; 
    163163else 
    164         $mode = esc_attr($_GET['mode']); ?> 
     164        $mode = esc_attr($_GET['mode']); 
    165165 
     166$is_trash = isset($_GET['post_status']) && $_GET['post_status'] == 'trash'; 
     167 
     168// Setup Bulk Actions  
     169$bulk_actions['-1'] = __('Bulk Actions'); 
     170if ( $is_trash ) 
     171        $bulk_actions['untrash'] = __('Restore'); 
     172else 
     173        $bulk_actions['edit'] = __('Edit'); 
     174 
     175if ( $is_trash || !EMPTY_TRASH_DAYS ) 
     176        $bulk_actions['delete'] = __('Delete Permanently'); 
     177else 
     178        $bulk_actions['trash'] = __('Move to Trash'); 
     179 
     180$bulk_actions = apply_filters( "bulk_actions-$post_type", $bulk_actions ); 
     181?> 
     182 
    166183<div class="wrap"> 
    167184<?php screen_icon(); ?> 
    168185<h2><?php echo esc_html( $title ); ?> <a href="<?php echo $post_new_file ?>" class="button add-new-h2"><?php echo esc_html_x('Add New', 'post'); ?></a> <?php 
     
    290307 
    291308<div class="alignleft actions"> 
    292309<select name="action"> 
    293 <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option> 
    294 <?php if ( $is_trash ) { ?> 
    295 <option value="untrash"><?php _e('Restore'); ?></option> 
    296 <?php } else { ?> 
    297 <option value="edit"><?php _e('Edit'); ?></option> 
    298 <?php } if ( $is_trash || !EMPTY_TRASH_DAYS ) { ?> 
    299 <option value="delete"><?php _e('Delete Permanently'); ?></option> 
    300 <?php } else { ?> 
    301 <option value="trash"><?php _e('Move to Trash'); ?></option> 
    302 <?php } ?> 
     310        <?php wp_list_bulk_actions( $bulk_actions ); ?> 
    303311</select> 
    304312<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" /> 
    305313<?php wp_nonce_field('bulk-posts'); ?> 
     
    386394 
    387395<div class="alignleft actions"> 
    388396<select name="action2"> 
    389 <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option> 
    390 <?php if ( $is_trash ) { ?> 
    391 <option value="untrash"><?php _e('Restore'); ?></option> 
    392 <?php } else { ?> 
    393 <option value="edit"><?php _e('Edit'); ?></option> 
    394 <?php } if ( $is_trash || !EMPTY_TRASH_DAYS ) { ?> 
    395 <option value="delete"><?php _e('Delete Permanently'); ?></option> 
    396 <?php } else { ?> 
    397 <option value="trash"><?php _e('Move to Trash'); ?></option> 
    398 <?php } ?> 
     397        <?php wp_list_bulk_actions( $bulk_actions ); ?> 
    399398</select> 
    400399<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" /> 
    401400<?php if ( $is_trash && current_user_can($post_type_object->edit_others_cap) ) { ?> 
  • wp-admin/link-manager.php

     
    6868        default : 
    6969                $sqlorderby = 'name'; 
    7070                break; 
    71 } ?> 
     71} 
    7272 
     73$bulk_actions = array( 
     74        '-1' = __('Bulk Actions'), 
     75        'delete' = __('Delete'), 
     76); 
     77 
     78$bulk_actions = apply_filters( 'bulk_actions-links', $bulk_actions ); 
     79?> 
     80 
    7381<div class="wrap nosubsub"> 
    7482<?php screen_icon(); ?> 
    7583<h2><?php echo esc_html( $title ); ?> <a href="link-add.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'link'); ?></a> <?php 
     
    111119 
    112120<div class="alignleft actions"> 
    113121<select name="action"> 
    114 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option> 
    115 <option value="delete"><?php _e('Delete'); ?></option> 
     122        <?php wp_list_bulk_actions( $bulk_actions ); ?> 
    116123</select> 
    117124<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" /> 
    118125 
     
    258265 
    259266<div class="alignleft actions"> 
    260267<select name="action2"> 
    261 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option> 
    262 <option value="delete"><?php _e('Delete'); ?></option> 
     268        <?php wp_list_bulk_actions( $bulk_actions ); ?> 
    263269</select> 
    264270<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" /> 
    265271</div>