Make WordPress Core

Changeset 38455


Ignore:
Timestamp:
08/30/2016 08:06:30 PM (10 years ago)
Author:
wonderboymusic
Message:

List Tables: AJAX actions for List Tables do not need to declare global $wp_list_table. List tables on admin screens are in global scope, and they contain hooks that don't pass the the list table as context, hence using globals there so that functions can import them. That problem does not exist in the AJAX actions, which are virtually impossible to hook into as is.

See #37699.

Location:
trunk/src/wp-admin/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r38411 r38455  
    8080 *
    8181 * @since 3.1.0
    82  *
    83  * @global WP_List_Table $wp_list_table
    8482 */
    8583function wp_ajax_fetch_list() {
    86         global $wp_list_table;
    87 
    8884        $list_class = $_GET['list_args']['class'];
    8985        check_ajax_referer( "fetch-list-$list_class", '_ajax_fetch_list_nonce' );
    9086
    9187        $wp_list_table = _get_list_table( $list_class, array( 'screen' => $_GET['list_args']['screen']['id'] ) );
    92         if ( ! $wp_list_table )
     88        if ( ! $wp_list_table ) {
    9389                wp_die( 0 );
    94 
    95         if ( ! $wp_list_table->ajax_user_can() )
    96                 wp_die( -1 );
     90        }
     91
     92        if ( ! $wp_list_table->ajax_user_can() ) {
     93                wp_die( -1 );
     94        }
    9795
    9896        $wp_list_table->ajax_response();
     
    830828 *
    831829 * @since 3.1.0
    832  *
    833  * @global WP_List_Table $wp_list_table
    834830 */
    835831function wp_ajax_add_tag() {
    836         global $wp_list_table;
    837 
    838832        check_ajax_referer( 'add-tag', '_wpnonce_add-tag' );
    839833        $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
     
    934928 * @since 3.1.0
    935929 *
    936  * @global WP_List_Table $wp_list_table
    937930 * @global int           $post_id
    938931 *
     
    940933 */
    941934function wp_ajax_get_comments( $action ) {
    942         global $wp_list_table, $post_id;
    943         if ( empty( $action ) )
     935        global $post_id;
     936        if ( empty( $action ) ) {
    944937                $action = 'get-comments';
    945 
     938        }
    946939        check_ajax_referer( $action );
    947940
    948941        if ( empty( $post_id ) && ! empty( $_REQUEST['p'] ) ) {
    949942                $id = absint( $_REQUEST['p'] );
    950                 if ( ! empty( $id ) )
     943                if ( ! empty( $id ) ) {
    951944                        $post_id = $id;
    952         }
    953 
    954         if ( empty( $post_id ) )
    955                 wp_die( -1 );
     945                }
     946        }
     947
     948        if ( empty( $post_id ) ) {
     949                wp_die( -1 );
     950        }
    956951
    957952        $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    958953
    959         if ( ! current_user_can( 'edit_post', $post_id ) )
    960                 wp_die( -1 );
     954        if ( ! current_user_can( 'edit_post', $post_id ) ) {
     955                wp_die( -1 );
     956        }
    961957
    962958        $wp_list_table->prepare_items();
    963959
    964         if ( !$wp_list_table->has_items() )
     960        if ( ! $wp_list_table->has_items() ) {
    965961                wp_die( 1 );
     962        }
    966963
    967964        $x = new WP_Ajax_Response();
     
    987984 * @since 3.1.0
    988985 *
    989  * @global WP_List_Table $wp_list_table
    990  *
    991986 * @param string $action Action to perform.
    992987 */
    993988function wp_ajax_replyto_comment( $action ) {
    994         global $wp_list_table;
    995989        if ( empty( $action ) )
    996990                $action = 'replyto-comment';
     
    11091103 *
    11101104 * @since 3.1.0
    1111  *
    1112  * @global WP_List_Table $wp_list_table
    11131105 */
    11141106function wp_ajax_edit_comment() {
    1115         global $wp_list_table;
    1116 
    11171107        check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' );
    11181108
     
    13281318 * @since 3.1.0
    13291319 *
    1330  * @global WP_List_Table $wp_list_table
    1331  *
    13321320 * @param string $action Action to perform.
    13331321 */
    13341322function wp_ajax_add_user( $action ) {
    1335         global $wp_list_table;
    1336         if ( empty( $action ) )
     1323        if ( empty( $action ) ) {
    13371324                $action = 'add-user';
     1325        }
    13381326
    13391327        check_ajax_referer( $action );
     
    16081596 *
    16091597 * @since 3.1.0
    1610  *
    1611  * @global WP_List_Table $wp_list_table
    16121598 */
    16131599function wp_ajax_inline_save() {
    1614         global $wp_list_table, $mode;
     1600        global $mode;
    16151601
    16161602        check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
     
    17081694 *
    17091695 * @since 3.1.0
    1710  *
    1711  * @global WP_List_Table $wp_list_table
    17121696 */
    17131697function wp_ajax_inline_save_tax() {
    1714         global $wp_list_table;
    1715 
    17161698        check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
    17171699
  • trunk/src/wp-admin/includes/list-table.php

    r38411 r38455  
    6464 */
    6565function register_column_headers($screen, $columns) {
    66         $wp_list_table = new _WP_List_Table_Compat($screen, $columns);
     66        new _WP_List_Table_Compat( $screen, $columns );
    6767}
    6868
Note: See TracChangeset for help on using the changeset viewer.