Make WordPress Core

Ticket #16031: 16021-4.7-2.patch

File 16021-4.7-2.patch, 21.0 KB (added by Veraxus, 7 years ago)

Updated patch - no longer possible to catch default WP actions.

  • src

  • src/wp-admin/edit-comments.php

    Property changes on: src
    ___________________________________________________________________
    Modified: svn:ignore
    ## -1,2 +1,3 ##
     .wp-tests-version
     .htaccess
    +.idea
     
    4646
    4747        wp_defer_comment_counting( true );
    4848
    49         foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
    50                 if ( !current_user_can( 'edit_comment', $comment_id ) )
    51                         continue;
    52 
    53                 switch ( $doaction ) {
    54                         case 'approve' :
     49        switch ( $doaction ) {
     50                case 'approve' :
     51                        foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
     52                                if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
     53                                        continue;
     54                                }
    5555                                wp_set_comment_status( $comment_id, 'approve' );
    56                                 $approved++;
    57                                 break;
    58                         case 'unapprove' :
     56                                $approved ++;
     57                        }
     58                        break;
     59                case 'unapprove' :
     60                        foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
     61                                if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
     62                                        continue;
     63                                }
    5964                                wp_set_comment_status( $comment_id, 'hold' );
    60                                 $unapproved++;
    61                                 break;
    62                         case 'spam' :
     65                                $unapproved ++;
     66                        }
     67                        break;
     68                case 'spam' :
     69                        foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
     70                                if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
     71                                        continue;
     72                                }
    6373                                wp_spam_comment( $comment_id );
    64                                 $spammed++;
    65                                 break;
    66                         case 'unspam' :
     74                                $spammed ++;
     75                        }
     76                        break;
     77                case 'unspam' :
     78                        foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
     79                                if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
     80                                        continue;
     81                                }
    6782                                wp_unspam_comment( $comment_id );
    68                                 $unspammed++;
    69                                 break;
    70                         case 'trash' :
     83                                $unspammed ++;
     84                        }
     85                        break;
     86                case 'trash' :
     87                        foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
     88                                if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
     89                                        continue;
     90                                }
    7191                                wp_trash_comment( $comment_id );
    72                                 $trashed++;
    73                                 break;
    74                         case 'untrash' :
     92                                $trashed ++;
     93                        }
     94                        break;
     95                case 'untrash' :
     96                        foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
     97                                if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
     98                                        continue;
     99                                }
    75100                                wp_untrash_comment( $comment_id );
    76                                 $untrashed++;
    77                                 break;
    78                         case 'delete' :
     101                                $untrashed ++;
     102                        }
     103                        break;
     104                case 'delete' :
     105                        foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
     106                                if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
     107                                        continue;
     108                                }
    79109                                wp_delete_comment( $comment_id );
    80                                 $deleted++;
    81                                 break;
    82                 }
     110                                $deleted ++;
     111                        }
     112                        break;
     113                default:
     114                        /**
     115                         * Fires when a custom bulk action should be handled.
     116                         *
     117                         * The sendback link should be modified with success or failure feedback
     118                         * from the action to be used to display feedback to the user.
     119                         *
     120                         * @since 4.7.0
     121                         *
     122                         * @param string $redirect_to The redirect URL.
     123                         * @param string $doaction    The action being taken.
     124                         * @param array  $comment_ids The comments to take the action on.
     125                         */
     126                        $redirect_to = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $comment_ids );
    83127        }
    84128
    85129        wp_defer_comment_counting( false );
     
    100144                $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
    101145        if ( $trashed || $spammed )
    102146                $redirect_to = add_query_arg( 'ids', join( ',', $comment_ids ), $redirect_to );
    103 
     147               
    104148        wp_safe_redirect( $redirect_to );
    105149        exit;
    106150} elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
  • src/wp-admin/edit-tags.php

     
    195195        else
    196196                $location = add_query_arg( array( 'error' => true, 'message' => 5 ), $location );
    197197        break;
     198default:
     199        /**
     200         * Fires when a custom bulk action should be handled.
     201         *
     202         * The sendback link should be modified with success or failure feedback
     203         * from the action to be used to display feedback to the user.
     204         *
     205         * @since 4.7.0
     206         *
     207         * @param string $location The redirect URL.
     208         * @param string $action The action being taken.
     209         * @param array  $tag_ids The tags to take the action on.
     210         */
     211        $location = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $location, $wp_list_table->current_action(), $_REQUEST['delete_tags'] );
     212        break;
    198213}
    199214
    200215if ( ! $location && ! empty( $_REQUEST['_wp_http_referer'] ) ) {
    201216        $location = remove_query_arg( array('_wp_http_referer', '_wpnonce'), wp_unslash($_SERVER['REQUEST_URI']) );
    202217}
    203 
     218       
    204219if ( $location ) {
    205220        if ( ! empty( $_REQUEST['paged'] ) ) {
    206221                $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
  • src/wp-admin/edit.php

     
    162162                                }
    163163                        }
    164164                        break;
     165                default:
     166                        /**
     167                         * Fires when a custom bulk action should be handled.
     168                         *
     169                         * The sendback link should be modified with success or failure feedback
     170                         * from the action to be used to display feedback to the user.
     171                         *
     172                         * @since 4.7.0
     173                         *
     174                         * @param string $sendback The redirect URL.
     175                         * @param string $doaction The action being taken.
     176                         * @param array  $post_ids The posts to take the action on.
     177                         */
     178                        $sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $post_ids );
     179                        break;
    165180        }
    166181
    167182        $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback );
  • src/wp-admin/includes/class-wp-list-table.php

     
    436436         */
    437437        protected function bulk_actions( $which = '' ) {
    438438                if ( is_null( $this->_actions ) ) {
    439                         $no_new_actions = $this->_actions = $this->get_bulk_actions();
     439                        $this->_actions = $this->get_bulk_actions();
    440440                        /**
    441441                         * Filters the list table Bulk Actions drop-down.
    442442                         *
     
    450450                         * @param array $actions An array of the available bulk actions.
    451451                         */
    452452                        $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
    453                         $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
    454453                        $two = '';
    455454                } else {
    456455                        $two = '2';
  • src/wp-admin/link-manager.php

     
    1818
    1919if ( $doaction && isset( $_REQUEST['linkcheck'] ) ) {
    2020        check_admin_referer( 'bulk-bookmarks' );
     21       
     22        $redirect_to = admin_url( 'link-manager.php' );
     23        $bulklinks = (array) $_REQUEST['linkcheck'];
    2124
    2225        if ( 'delete' == $doaction ) {
    23                 $bulklinks = (array) $_REQUEST['linkcheck'];
     26               
    2427                foreach ( $bulklinks as $link_id ) {
    2528                        $link_id = (int) $link_id;
    2629
    2730                        wp_delete_link( $link_id );
    2831                }
    2932
    30                 wp_redirect( add_query_arg('deleted', count( $bulklinks ), admin_url( 'link-manager.php' ) ) );
    31                 exit;
     33                $redirect_to = add_query_arg('deleted', count( $bulklinks ), $redirect_to );
     34        } else {
     35                /**
     36                 * Fires when a custom bulk action should be handled.
     37                 *
     38                 * The sendback link should be modified with success or failure feedback
     39                 * from the action to be used to display feedback to the user.
     40                 *
     41                 * @since 4.7.0
     42                 *
     43                 * @param string $redirect_to The redirect URL.
     44                 * @param string $doaction    The action being taken.
     45                 * @param array  $bulklinks   The links to take the action on.
     46                 */
     47                $redirect_to = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $bulklinks );
    3248        }
     49       
     50        wp_redirect( $redirect_to );
     51        exit;
    3352} elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
    3453         wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
    3554         exit;
  • src/wp-admin/network/site-themes.php

     
    122122                                $n = 'none';
    123123                        }
    124124                        break;
     125                default:
     126                        /**
     127                         * Fires when a custom bulk action should be handled.
     128                         *
     129                         * The sendback link should be modified with success or failure feedback
     130                         * from the action to be used to display feedback to the user.
     131                         *
     132                         * @since 4.7.0
     133                         *
     134                         * @param string $referer The redirect URL.
     135                         * @param string $action The action being taken.
     136                         * @param array  $theme_ids The themes to take the action on.
     137                         * @param int    $site_id The current site id
     138                         */
     139                        $referer = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $referer, $action, $_REQUEST['checked'], $id );
     140                        $n = count( $themes );
    125141        }
    126142
    127143        update_option( 'allowedthemes', $allowed_themes );
  • src/wp-admin/network/site-users.php

     
    164164                                $update = 'err_promote';
    165165                        }
    166166                        break;
     167                default:
     168                        /**
     169                         * Fires when a custom bulk action should be handled.
     170                         *
     171                         * The sendback link should be modified with success or failure feedback
     172                         * from the action to be used to display feedback to the user.
     173                         *
     174                         * @since 4.7.0
     175                         *
     176                         * @param string $referer The redirect URL.
     177                         * @param string $action The action being taken.
     178                         * @param array  $user_ids The users to take the action on.
     179                         * @param int    $site_id The id of the current site
     180                         */
     181                        $referer = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $referer, $action, $_REQUEST['users'], $id );
     182                        $update = $action;
     183                        break;
    167184        }
    168185
    169186        wp_safe_redirect( add_query_arg( 'update', $update, $referer ) );
  • src/wp-admin/network/sites.php

     
    138138                case 'allblogs':
    139139                        if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
    140140                                $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
    141 
    142                                 foreach ( (array) $_POST['allblogs'] as $key => $val ) {
    143                                         if ( $val != '0' && $val != $current_site->blog_id ) {
    144                                                 switch ( $doaction ) {
    145                                                         case 'delete':
    146                                                                 if ( ! current_user_can( 'delete_site', $val ) )
     141                                switch ( $doaction ) {
     142                                        case 'delete':
     143                                                foreach ( (array) $_POST['allblogs'] as $key => $val ) {
     144                                                        if ( $val != '0' && $val != $current_site->blog_id ) {
     145                                                                if ( ! current_user_can( 'delete_site', $val ) ) {
    147146                                                                        wp_die( __( 'Sorry, you are not allowed to delete the site.' ) );
     147                                                                }
    148148
    149149                                                                $updated_action = 'all_delete';
    150150                                                                wpmu_delete_blog( $val, true );
    151                                                         break;
     151                                                        } else {
     152                                                                wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
     153                                                        }
     154                                                }
     155                                                break;
    152156
    153                                                         case 'spam':
    154                                                         case 'notspam':
     157                                        case 'spam':
     158                                        case 'notspam':
     159                                                foreach ( (array) $_POST['allblogs'] as $key => $val ) {
     160                                                        if ( $val != '0' && $val != $current_site->blog_id ) {
    155161                                                                $updated_action = ( 'spam' === $doaction ) ? 'all_spam' : 'all_notspam';
    156162                                                                update_blog_status( $val, 'spam', ( 'spam' === $doaction ) ? '1' : '0' );
    157                                                         break;
     163                                                        } else {
     164                                                                wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
     165                                                        }
    158166                                                }
    159                                         } else {
    160                                                 wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
    161                                         }
     167                                                break;
     168                                       
     169                                        default:
     170                                                if ( isset($_REQUEST['allblogs']) ) {
     171                                                        $sendback = wp_get_referer();
     172
     173                                                        /**
     174                                                         * Fires when a custom bulk action should be handled.
     175                                                         *
     176                                                         * The sendback link should be modified with success or failure feedback
     177                                                         * from the action to be used to display feedback to the user.
     178                                                         *
     179                                                         * @since 4.7.0
     180                                                         *
     181                                                         * @param string $sendback The redirect URL.
     182                                                         * @param string $action The action being taken.
     183                                                         * @param array  $blog_ids The blogs to take the action on.
     184                                                         * @param int    $site_id The current site id.
     185                                                         */
     186                                                        $sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $_REQUEST['allblogs'], $id );
     187
     188                                                        if ( $sendback ) {
     189                                                                wp_safe_redirect( $sendback );
     190                                                                exit();
     191                                                        }
     192                                                }
    162193                                }
     194                               
    163195                        } else {
    164196                                $location = network_admin_url( 'sites.php' );
    165197                                if ( ! empty( $_REQUEST['paged'] ) ) {
     
    219251                wp_safe_redirect( add_query_arg( array( 'updated' => $updated_action ), wp_get_referer() ) );
    220252                exit();
    221253        }
     254
    222255}
    223256
    224257$msg = '';
  • src/wp-admin/network/themes.php

     
    195195                                's' => $s
    196196                        ), network_admin_url( 'themes.php' ) ) );
    197197                        exit;
     198                        break;
     199                default:
     200                        if ( isset($_POST['checked']) ) {
     201                                $sendback = wp_get_referer();
     202
     203                                /**
     204                                 * Fires when a custom bulk action should be handled.
     205                                 *
     206                                 * The sendback link should be modified with success or failure feedback
     207                                 * from the action to be used to display feedback to the user.
     208                                 *
     209                                 * @since 4.7.0
     210                                 *
     211                                 * @param string $sendback The redirect URL.
     212                                 * @param string $action The action being taken.
     213                                 * @param array  $theme_ids The themes to take the action on.
     214                                 */
     215                                $sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $action, $_REQUEST['checked'] );
     216
     217                                if ( $sendback ) {
     218                                        wp_safe_redirect( $sendback );
     219                                        exit;
     220                                }
     221                        }
    198222        }
     223       
    199224}
    200225
    201226$wp_list_table->prepare_items();
  • src/wp-admin/network/users.php

     
    5252                                $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
    5353                                $userfunction = '';
    5454
    55                                 foreach ( (array) $_POST['allusers'] as $user_id ) {
    56                                         if ( !empty( $user_id ) ) {
    57                                                 switch ( $doaction ) {
    58                                                         case 'delete':
    59                                                                 if ( ! current_user_can( 'delete_users' ) )
     55                                switch ( $doaction ) {
     56                                        case 'delete':
     57                                                foreach ( (array) $_POST['allusers'] as $user_id ) {
     58                                                        if ( !empty( $user_id ) ) {
     59                                                                if ( ! current_user_can( 'delete_users' ) ) {
    6060                                                                        wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    61                                                                 $title = __( 'Users' );
     61                                                                }
     62                                                                $title       = __( 'Users' );
    6263                                                                $parent_file = 'users.php';
    6364                                                                require_once( ABSPATH . 'wp-admin/admin-header.php' );
    6465                                                                echo '<div class="wrap">';
     
    6667                                                                echo '</div>';
    6768                                                                require_once( ABSPATH . 'wp-admin/admin-footer.php' );
    6869                                                                exit();
    69 
    70                                                         case 'spam':
     70                                                        }
     71                                                }
     72                                                break;
     73                                       
     74                                        case 'spam':
     75                                                foreach ( (array) $_POST['allusers'] as $user_id ) {
     76                                                        if ( !empty( $user_id ) ) {
    7177                                                                $user = get_userdata( $user_id );
    72                                                                 if ( is_super_admin( $user->ID ) )
     78                                                                if ( is_super_admin( $user->ID ) ) {
    7379                                                                        wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
     80                                                                }
    7481
    7582                                                                $userfunction = 'all_spam';
    76                                                                 $blogs = get_blogs_of_user( $user_id, true );
     83                                                                $blogs        = get_blogs_of_user( $user_id, true );
    7784                                                                foreach ( (array) $blogs as $details ) {
    7885                                                                        if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
     86                                                                        {
    7987                                                                                update_blog_status( $details->userblog_id, 'spam', '1' );
     88                                                                        }
    8089                                                                }
    8190                                                                update_user_status( $user_id, 'spam', '1' );
    82                                                         break;
     91                                                        }
     92                                                }
     93                                                break;
    8394
    84                                                         case 'notspam':
     95                                        case 'notspam':
     96                                                foreach ( (array) $_POST['allusers'] as $user_id ) {
     97                                                        if ( ! empty( $user_id ) ) {
    8598                                                                $userfunction = 'all_notspam';
    86                                                                 $blogs = get_blogs_of_user( $user_id, true );
    87                                                                 foreach ( (array) $blogs as $details )
     99                                                                $blogs        = get_blogs_of_user( $user_id, true );
     100                                                                foreach ( (array) $blogs as $details ) {
    88101                                                                        update_blog_status( $details->userblog_id, 'spam', '0' );
     102                                                                }
    89103
    90104                                                                update_user_status( $user_id, 'spam', '0' );
    91                                                         break;
     105                                                        }
    92106                                                }
    93                                         }
     107                                                break;
     108                                       
     109                                        default:
     110                                                if ( isset( $_POST['allusers'] ) ) {
     111
     112                                                        $sendback = wp_get_referer();
     113
     114                                                        /**
     115                                                         * Fires when a custom bulk action should be handled.
     116                                                         *
     117                                                         * The sendback link should be modified with success or failure feedback
     118                                                         * from the action to be used to display feedback to the user.
     119                                                         *
     120                                                         * @since 4.7.0
     121                                                         *
     122                                                         * @param string $sendback The redirect URL.
     123                                                         * @param string $action The action being taken.
     124                                                         * @param array  $user_ids The users to take the action on.
     125                                                         * @param int    $site_id The id of the current site
     126                                                         */
     127                                                        $sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $_POST['allusers'], $id );
     128
     129                                                        if ( $sendback ) {
     130                                                                wp_safe_redirect( $sendback );
     131                                                                exit();
     132                                                        }
     133                                                }
     134                                                break;
    94135                                }
    95136
    96137                                wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
  • src/wp-admin/plugins.php

     
    356356                                update_site_option( 'recently_activated', array() );
    357357                        }
    358358                        break;
     359               
     360                default:
     361                        if ( isset( $_POST['checked'] ) ) {
     362                                $sendback = wp_get_referer();
     363
     364                                /**
     365                                 * Fires when a custom bulk action should be handled.
     366                                 *
     367                                 * The sendback link should be modified with success or failure feedback
     368                                 * from the action to be used to display feedback to the user.
     369                                 *
     370                                 * @since 4.7.0
     371                                 *
     372                                 * @param string $sendback The redirect URL.
     373                                 * @param string $action The action being taken.
     374                                 * @param array  $plugin_ids The plugins to take the action on.
     375                                 */
     376                                $sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $action, $_POST['checked'] );
     377
     378                                if ( $sendback ) {
     379                                        wp_safe_redirect( $sendback );
     380                                        exit;
     381                                }
     382                        }
     383                        break;
    359384        }
     385
    360386}
    361387
    362388$wp_list_table->prepare_items();
  • src/wp-admin/upload.php

     
    163163                        }
    164164                        $location = add_query_arg( 'deleted', count( $post_ids ), $location );
    165165                        break;
     166                default:
     167                        /**
     168                         * Fires when a custom bulk action should be handled.
     169                         *
     170                         * The sendback link should be modified with success or failure feedback
     171                         * from the action to be used to display feedback to the user.
     172                         *
     173                         * @since 4.7.0
     174                         *
     175                         * @param string $location The redirect URL.
     176                         * @param string $doaction The action being taken.
     177                         * @param array  $post_ids The posts to take the action on.
     178                         */
     179                        $location = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $location, $doaction, $post_ids );
    166180        }
    167181
    168182        wp_redirect( $location );
  • src/wp-admin/users.php

     
    410410                exit;
    411411        }
    412412
     413        if ( !empty($_REQUEST['users']) ) {
     414                $sendback = wp_get_referer();
     415
     416                /**
     417                 * Fires when a custom bulk action should be handled.
     418                 *
     419                 * The sendback link should be modified with success or failure feedback
     420                 * from the action to be used to display feedback to the user.
     421                 *
     422                 * @since 4.7.0
     423                 *
     424                 * @param string $sendback The redirect URL.
     425                 * @param string $action The action being taken.
     426                 * @param array  $user_ids The users to take the action on.
     427                 */
     428                $sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $wp_list_table->current_action(), $_REQUEST['users'] );
     429               
     430                if ( $sendback ) {
     431                        wp_safe_redirect( $sendback );
     432                        exit;
     433                }
     434        }
     435
    413436        $wp_list_table->prepare_items();
    414437        $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
    415438        if ( $pagenum > $total_pages && $total_pages > 0 ) {