Make WordPress Core

Changeset 15642


Ignore:
Timestamp:
09/22/2010 12:10:39 AM (16 years ago)
Author:
scribu
Message:

Introduce WP_List_Table::current_action() and use throughout admin list screens. See #14579

Location:
trunk/wp-admin
Files:
9 edited

Legend:

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

    r15596 r15642  
    1313$wp_list_table->check_permissions();
    1414
    15 if ( isset( $_REQUEST['doaction'] ) ||  isset( $_REQUEST['doaction2'] ) || isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
     15$doaction = $wp_list_table->current_action();
     16
     17if ( $doaction ) {
    1618        check_admin_referer( 'bulk-comments' );
    1719
    18         if ( ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
     20        if ( 'delete_all' == $do_action && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
    1921                $comment_status = $wpdb->escape( $_REQUEST['comment_status'] );
    2022                $delete_time = $wpdb->escape( $_REQUEST['pagegen_timestamp'] );
    2123                $comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = '$comment_status' AND '$delete_time' > comment_date_gmt" );
    2224                $doaction = 'delete';
    23         } elseif ( ( $_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1 ) && isset( $_REQUEST['delete_comments'] ) ) {
     25        } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
    2426                $comment_ids = $_REQUEST['delete_comments'];
    2527                $doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
    26         } elseif ( $_REQUEST['doaction'] == 'undo' && isset( $_REQUEST['ids'] ) ) {
     28        } elseif ( isset( $_REQUEST['ids'] ) ) {
    2729                $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
    28                 $doaction = $_REQUEST['action'];
    2930        } else {
    3031                wp_redirect( wp_get_referer() );
  • trunk/wp-admin/edit-tags.php

    r15528 r15642  
    2323}
    2424
    25 if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) )
    26         $action = 'bulk-delete';
    27 
    28 switch ( $action ) {
     25switch ( $wp_list_table->current_action() ) {
    2926
    3027case 'add-tag':
  • trunk/wp-admin/edit.php

    r15578 r15642  
    2222
    2323// Handle bulk actions
    24 if ( isset($_REQUEST['doaction']) || isset($_REQUEST['doaction2']) || isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2']) || isset($_REQUEST['bulk_edit']) ) {
     24$doaction = $wp_list_table->current_action();
     25
     26if ( $doaction ) {
    2527        check_admin_referer('bulk-posts');
    2628        $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
     
    2931                $sendback = admin_url($post_new_file);
    3032
    31         if ( isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2']) ) {
    32                 $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']);
    33                 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
     33        if ( 'delete_all' == $doaction ) {
     34                $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
    3435                $doaction = 'delete';
    35         } elseif ( ( $_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1 ) && ( isset($_REQUEST['post']) || isset($_REQUEST['ids']) ) ) {
    36                 $post_ids = isset($_REQUEST['post']) ? array_map( 'intval', (array) $_REQUEST['post'] ) : explode(',', $_REQUEST['ids']);
    37                 $doaction = ($_REQUEST['action'] != -1) ? $_REQUEST['action'] : $_REQUEST['action2'];
    38         } else {
     36        } elseif ( isset( $_REQUEST['media'] ) ) {
     37                $post_ids = $_REQUEST['media'];
     38        } elseif ( isset( $_REQUEST['ids'] ) ) {
     39                $post_ids = explode( ',', $_REQUEST['ids'] );
     40        }
     41
     42        if ( !isset( $post_ids ) ) {
    3943                wp_redirect( admin_url("edit.php?post_type=$post_type") );
    4044        }
     
    98102        }
    99103
    100         if ( isset($_REQUEST['action']) )
    101                 $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view'), $sendback );
     104        $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view'), $sendback );
    102105
    103106        wp_redirect($sendback);
  • trunk/wp-admin/includes/default-list-tables.php

    r15633 r15642  
    214214<?php
    215215                }
     216        }
     217
     218        function current_action() {
     219                if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
     220                        return 'delete_all';
     221
     222                return parent::current_action();
    216223        }
    217224
     
    10811088        }
    10821089
     1090        function current_action() {
     1091                if ( isset( $_REQUEST['find_detached'] ) )
     1092                        return 'find_detached';
     1093
     1094                if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) )
     1095                        return 'attach';
     1096
     1097                if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
     1098                        return 'delete_all';
     1099
     1100                return parent::current_action();
     1101        }
     1102
    10831103        function has_items() {
    10841104                return have_posts();
     
    14831503        }
    14841504
     1505        function current_action() {
     1506                if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) )
     1507                        return 'bulk-delete';
     1508
     1509                return parent::current_action();
     1510        }
     1511
    14851512        function get_columns() {
    14861513                global $taxonomy;
     
    18611888        </div>
    18621889<?php
     1890        }
     1891       
     1892        function current_action() {
     1893                if ( isset($_REQUEST['changeit']) && !empty($_REQUEST['new_role']) )
     1894                        return 'promote';
     1895
     1896                return parent::current_action();
    18631897        }
    18641898
     
    22132247                do_action( 'manage_comments_nav', $comment_status );
    22142248                echo '</div>';
     2249        }
     2250
     2251        function current_action() {
     2252                if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
     2253                        return 'delete_all';
     2254
     2255                return parent::current_action();
    22152256        }
    22162257
     
    34593500        }
    34603501
     3502        function current_action() {
     3503                if ( isset($_POST['clear-recent-list']) )
     3504                        return 'clear-recent-list';
     3505
     3506                return parent::current_action();
     3507        }
     3508
    34613509        function display_rows() {
    34623510                global $status, $page;
  • trunk/wp-admin/includes/list-table.php

    r15629 r15642  
    245245
    246246                echo "<input type='submit' value='" . esc_attr__( 'Apply' ) . "' name='doaction$two' id='doaction$two' class='button-secondary action' />\n";
     247        }
     248
     249        /**
     250         * Get the current action selected from the bulk actions dropdown.
     251         *
     252         * @since 3.1.0
     253         * @access public
     254         *
     255         * @return string|bool The action name or False if no action was selected
     256         */
     257        function current_action() {
     258                if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
     259                        return $_REQUEST['action'];
     260
     261                if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
     262                        return $_REQUEST['action2'];
     263               
     264                return false;
    247265        }
    248266
  • trunk/wp-admin/link-manager.php

    r15528 r15642  
    1414
    1515// Handle bulk deletes
    16 if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['linkcheck'] ) ) {
     16$doaction = $wp_list_table->current_action();
     17
     18if ( $doaction && isset( $_REQUEST['linkcheck'] ) ) {
    1719        check_admin_referer( 'bulk-bookmarks' );
    18 
    19         $doaction = $_REQUEST['action'] ? $_REQUEST['action'] : $_REQUEST['action2'];
    2020
    2121        if ( 'delete' == $doaction ) {
  • trunk/wp-admin/plugins.php

    r15578 r15642  
    1313$wp_list_table->check_permissions();
    1414
    15 if ( isset($_POST['clear-recent-list']) )
    16         $action = 'clear-recent-list';
    17 elseif ( !empty($_REQUEST['action']) )
    18         $action = $_REQUEST['action'];
    19 elseif ( !empty($_REQUEST['action2']) )
    20         $action = $_REQUEST['action2'];
    21 else
    22         $action = false;
     15$action = $wp_list_table->current_action();
    2316
    2417$plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
    2518
    26 //Clean up request URI from temporary args for screen options/paging uri's to work as expected.
     19// Clean up request URI from temporary args for screen options/paging uri's to work as expected.
    2720$_SERVER['REQUEST_URI'] = remove_query_arg(array('error', 'deleted', 'activate', 'activate-multi', 'deactivate', 'deactivate-multi', '_error_nonce'), $_SERVER['REQUEST_URI']);
    2821
    29 if ( !empty($action) ) {
     22if ( $action ) {
    3023        $network_wide = false;
    3124        if ( ( isset( $_GET['networkwide'] ) || 'network-activate-selected' == $action ) && is_multisite() && current_user_can( 'manage_network_plugins' ) )
  • trunk/wp-admin/upload.php

    r15578 r15642  
    1414
    1515// Handle bulk actions
    16 if ( isset($_REQUEST['find_detached']) ) {
     16$doaction = $wp_list_table->current_action();
     17
     18if ( $doaction ) {
    1719        check_admin_referer('bulk-media');
    1820
    19         if ( !current_user_can('edit_posts') )
    20                 wp_die( __('You are not allowed to scan for lost attachments.') );
    21 
    22         $lost = $wpdb->get_col( "
    23                 SELECT ID FROM $wpdb->posts
    24                 WHERE post_type = 'attachment' AND post_parent > '0'
    25                 AND post_parent NOT IN (
    26                         SELECT ID FROM $wpdb->posts
    27                         WHERE post_type NOT IN ( 'attachment', '" . join( "', '", get_post_types( array( 'public' => false ) ) ) . "' )
    28                 )
    29         " );
    30 
    31         $_REQUEST['detached'] = 1;
    32 
    33 } elseif ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) {
    34         check_admin_referer( 'bulk-media' );
    35 
    36         $parent_id = (int) $_REQUEST['found_post_id'];
    37         if ( !$parent_id )
    38                 return;
    39 
    40         $parent = &get_post( $parent_id );
    41         if ( !current_user_can( 'edit_post', $parent_id ) )
    42                 wp_die( __( 'You are not allowed to edit this post.' ) );
    43 
    44         $attach = array();
    45         foreach ( (array) $_REQUEST['media'] as $att_id ) {
    46                 $att_id = (int) $att_id;
    47 
    48                 if ( !current_user_can( 'edit_post', $att_id ) )
    49                         continue;
    50 
    51                 $attach[] = $att_id;
    52                 clean_attachment_cache( $att_id );
    53         }
    54 
    55         if ( ! empty( $attach ) ) {
    56                 $attach = implode( ',', $attach );
    57                 $attached = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $attach )", $parent_id ) );
    58         }
    59 
    60         if ( isset( $attached ) ) {
    61                 $location = 'upload.php';
    62                 if ( $referer = wp_get_referer() ) {
    63                         if ( false !== strpos( $referer, 'upload.php' ) )
    64                                 $location = $referer;
    65                 }
    66 
    67                 $location = add_query_arg( array( 'attached' => $attached ) , $location );
    68                 wp_redirect( $location );
    69                 exit;
    70         }
    71 
    72 } elseif ( isset( $_REQUEST['doaction'] ) || isset( $_REQUEST['doaction2'] ) || isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
    73         check_admin_referer( 'bulk-media' );
    74 
    75         if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
     21        if ( 'delete_all' == $doaction ) {
    7622                $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
    7723                $doaction = 'delete';
    78         } elseif ( ( $_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1 ) && ( isset( $_REQUEST['media'] ) || isset( $_REQUEST['ids'] ) ) ) {
    79                 $post_ids = isset( $_REQUEST['media'] ) ? $_REQUEST['media'] : explode( ',', $_REQUEST['ids'] );
    80                 $doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
    81         } else {
    82                 wp_redirect( $_SERVER['HTTP_REFERER'] );
     24        } elseif ( isset( $_REQUEST['media'] ) ) {
     25                $post_ids = $_REQUEST['media'];
     26        } elseif ( isset( $_REQUEST['ids'] ) ) {
     27                $post_ids = explode( ',', $_REQUEST['ids'] );
    8328        }
    8429
     
    9035
    9136        switch ( $doaction ) {
     37                case 'find_detached':
     38                        if ( !current_user_can('edit_posts') )
     39                                wp_die( __('You are not allowed to scan for lost attachments.') );
     40
     41                        $lost = $wpdb->get_col( "
     42                                SELECT ID FROM $wpdb->posts
     43                                WHERE post_type = 'attachment' AND post_parent > '0'
     44                                AND post_parent NOT IN (
     45                                        SELECT ID FROM $wpdb->posts
     46                                        WHERE post_type NOT IN ( 'attachment', '" . join( "', '", get_post_types( array( 'public' => false ) ) ) . "' )
     47                                )
     48                        " );
     49
     50                        $_REQUEST['detached'] = 1;
     51                        break;
     52                case 'attach':
     53                        $parent_id = (int) $_REQUEST['found_post_id'];
     54                        if ( !$parent_id )
     55                                return;
     56
     57                        $parent = &get_post( $parent_id );
     58                        if ( !current_user_can( 'edit_post', $parent_id ) )
     59                                wp_die( __( 'You are not allowed to edit this post.' ) );
     60
     61                        $attach = array();
     62                        foreach ( (array) $_REQUEST['media'] as $att_id ) {
     63                                $att_id = (int) $att_id;
     64
     65                                if ( !current_user_can( 'edit_post', $att_id ) )
     66                                        continue;
     67
     68                                $attach[] = $att_id;
     69                                clean_attachment_cache( $att_id );
     70                        }
     71
     72                        if ( ! empty( $attach ) ) {
     73                                $attach = implode( ',', $attach );
     74                                $attached = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $attach )", $parent_id ) );
     75                        }
     76
     77                        if ( isset( $attached ) ) {
     78                                $location = 'upload.php';
     79                                if ( $referer = wp_get_referer() ) {
     80                                        if ( false !== strpos( $referer, 'upload.php' ) )
     81                                                $location = $referer;
     82                                }
     83
     84                                $location = add_query_arg( array( 'attached' => $attached ) , $location );
     85                                wp_redirect( $location );
     86                                exit;
     87                        }
     88                        break;
    9289                case 'trash':
    9390                        foreach ( (array) $post_ids as $post_id ) {
  • trunk/wp-admin/users.php

    r15578 r15642  
    3030);
    3131
    32 $update = $doaction = '';
    33 if ( isset($_REQUEST['action']) )
    34         $doaction = $_REQUEST['action'] ? $_REQUEST['action'] : $_REQUEST['action2'];
    35 
    36 if ( "-1" == $doaction ) {
    37         if ( isset($_REQUEST['changeit']) && !empty($_REQUEST['new_role']) )
    38                 $doaction = 'promote';
    39 }
    40 
    4132if ( empty($_REQUEST) ) {
    4233        $referer = '<input type="hidden" name="wp_http_referer" value="'. esc_attr(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
     
    4940}
    5041
    51 switch ($doaction) {
     42$update = '';
     43
     44switch ( $wp_list_table->current_action() ) {
    5245
    5346/* Bulk Dropdown menu Role changes */
Note: See TracChangeset for help on using the changeset viewer.