Make WordPress Core


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 ) {
Note: See TracChangeset for help on using the changeset viewer.