WordPress.org

Make WordPress Core

Changeset 38334


Ignore:
Timestamp:
08/23/2016 02:32:18 PM (21 months ago)
Author:
wonderboymusic
Message:

AJAX: add a new function, wp_doing_ajax(), which can replace... (wait for it...) DOING_AJAX checks via the constant.

Props Mte90, sebastian.pisula, swissspidy.
Fixes #25669.

Location:
trunk/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-comments-list-table.php

    r37674 r38334  
    9595        $comments_per_page = $this->get_per_page( $comment_status );
    9696
    97         $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
     97        $doing_ajax = wp_doing_ajax();
    9898
    9999        if ( isset( $_REQUEST['number'] ) ) {
     
    601601
    602602            // Reply and quickedit need a hide-if-no-js span when not added with ajax
    603             if ( ( 'reply' === $action || 'quickedit' === $action ) && ! defined('DOING_AJAX') )
     603            if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() )
    604604                $action .= ' hide-if-no-js';
    605605            elseif ( ( $action === 'untrash' && $the_comment_status === 'trash' ) || ( $action === 'unspam' && $the_comment_status === 'spam' ) ) {
  • trunk/src/wp-admin/includes/class-wp-list-table.php

    r38146 r38334  
    285285
    286286        // Redirect if page number is invalid and headers are not already sent.
    287         if ( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
     287        if ( ! headers_sent() && ! wp_doing_ajax() && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
    288288            wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
    289289            exit;
  • trunk/src/wp-admin/includes/class-wp-terms-list-table.php

    r38077 r38334  
    368368        $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' );
    369369
    370         $uri = ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ? wp_get_referer() : $_SERVER['REQUEST_URI'];
     370        $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
    371371
    372372        $edit_link = add_query_arg(
     
    426426        $default_term = get_option( 'default_' . $taxonomy );
    427427
    428         $uri = ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ? wp_get_referer() : $_SERVER['REQUEST_URI'];
     428        $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
    429429
    430430        $edit_link = add_query_arg(
  • trunk/src/wp-admin/includes/dashboard.php

    r38028 r38334  
    967967function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
    968968    $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
    969     $doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX );
     969    $doing_ajax = wp_doing_ajax();
    970970
    971971    if ( empty($check_urls) ) {
  • trunk/src/wp-admin/includes/ms.php

    r38024 r38334  
    4141    }
    4242
    43     if ( $file['error'] != '0' && ! isset( $_POST['html-upload'] ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
     43    if ( $file['error'] != '0' && ! isset( $_POST['html-upload'] ) && ! wp_doing_ajax() ) {
    4444        wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
    4545    }
  • trunk/src/wp-admin/includes/theme.php

    r38167 r38334  
    460460
    461461        if ( $ssl && is_wp_error( $request ) ) {
    462             if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
     462            if ( ! wp_doing_ajax() ) {
    463463                trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE );
    464464            }
  • trunk/src/wp-includes/class-wp-ajax-response.php

    r38028 r38334  
    150150            echo $response;
    151151        echo '</wp_ajax>';
    152         if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
     152        if ( wp_doing_ajax() )
    153153            wp_die();
    154154        else
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r38299 r38334  
    316316     */
    317317    public function doing_ajax( $action = null ) {
    318         $doing_ajax = ( defined( 'DOING_AJAX' ) && DOING_AJAX );
    319         if ( ! $doing_ajax ) {
     318        if ( ! wp_doing_ajax() ) {
    320319            return false;
    321320        }
  • trunk/src/wp-includes/comment.php

    r38313 r38334  
    633633         */
    634634        do_action( 'comment_duplicate_trigger', $commentdata );
    635         if ( defined( 'DOING_AJAX' ) ) {
     635        if ( wp_doing_ajax() ) {
    636636            die( __('Duplicate comment detected; it looks as though you&#8217;ve already said that!') );
    637637        }
     
    769769            do_action( 'comment_flood_trigger', $time_lastcomment, $time_newcomment );
    770770
    771             if ( defined('DOING_AJAX') )
     771            if ( wp_doing_ajax() )
    772772                die( __('You are posting comments too quickly. Slow down.') );
    773773
  • trunk/src/wp-includes/functions.php

    r38308 r38334  
    25712571    }
    25722572
    2573     if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
     2573    if ( wp_doing_ajax() ) {
    25742574        /**
    25752575         * Filters the callback for killing WordPress execution for Ajax requests.
     
    30653065    @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
    30663066    echo wp_json_encode( $response );
    3067     if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
     3067    if ( wp_doing_ajax() )
    30683068        wp_die();
    30693069    else
  • trunk/src/wp-includes/load.php

    r38239 r38334  
    335335    }
    336336
    337     if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
     337    if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || wp_doing_ajax() ) {
    338338        @ini_set( 'display_errors', 0 );
    339339    }
     
    10281028    return false;
    10291029}
     1030
     1031/**
     1032 * Determines whether the current request is a WordPress Ajax request.
     1033 *
     1034 * @since 4.7.0
     1035 *
     1036 * @return bool True if it's a WordPress Ajax request, false otherwise.
     1037 */
     1038function wp_doing_ajax() {
     1039    /**
     1040     * Filter whether the current request is a WordPress Ajax request.
     1041     *
     1042     * @since 4.7.0
     1043     *
     1044     * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request.
     1045     */
     1046    return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
     1047}
  • trunk/src/wp-includes/option.php

    r38307 r38334  
    787787function wp_user_settings() {
    788788
    789     if ( ! is_admin() || defined( 'DOING_AJAX' ) ) {
     789    if ( ! is_admin() || wp_doing_ajax() ) {
    790790        return;
    791791    }
  • trunk/src/wp-includes/pluggable.php

    r38286 r38334  
    604604
    605605    // Allow a grace period for POST and Ajax requests
    606     if ( defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD'] ) {
     606    if ( wp_doing_ajax() || 'POST' == $_SERVER['REQUEST_METHOD'] ) {
    607607        $expired += HOUR_IN_SECONDS;
    608608    }
     
    11051105
    11061106    if ( $die && false === $result ) {
    1107         if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
     1107        if ( wp_doing_ajax() ) {
    11081108            wp_die( -1 );
    11091109        } else {
  • trunk/src/wp-includes/update.php

    r37570 r38334  
    679679}
    680680
    681 if ( ( ! is_main_site() && ! is_network_admin() ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
     681if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) {
    682682    return;
    683683}
Note: See TracChangeset for help on using the changeset viewer.