WordPress.org

Make WordPress Core

Ticket #42061: 42061-add-wp-doing-rest-filterable-function.patch

File 42061-add-wp-doing-rest-filterable-function.patch, 1.7 KB (added by lots.0.logs, 4 years ago)
  • wp-includes/load.php

    From 4df4a4a99b3a29c6704e0e6683ddd2d6d83af986 Mon Sep 17 00:00:00 2001
    From: Dustin Falgout <dustin@falgout.us>
    Date: Mon, 2 Oct 2017 06:11:37 -0500
    Subject: [PATCH] Add new utility function: wp_doing_rest() which works exactly
     like the current wp_doing_ajax/cron functions, but for Rest API requests.
    
    ---
     wp-includes/load.php | 20 +++++++++++++++++++-
     1 file changed, 19 insertions(+), 1 deletion(-)
    
    diff --git a/wp-includes/load.php b/wp-includes/load.php
    index 63a4b0f64c9..8d79fb33f95 100644
    a b function wp_debug_mode() { 
    333333                error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
    334334        }
    335335
    336         if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) {
     336        if ( defined( 'XMLRPC_REQUEST' ) || wp_doing_rest() || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) {
    337337                @ini_set( 'display_errors', 0 );
    338338        }
    339339}
    function wp_doing_cron() { 
    10801080}
    10811081
    10821082/**
     1083 * Determines if the current request is a WordPress Rest API request.
     1084 *
     1085 * @since 4.9.0
     1086 *
     1087 * @return bool True if it's a WordPress Rest API request, false otherwise.
     1088 */
     1089function wp_doing_rest() {
     1090        /**
     1091         * Filters whether or not the current request is a WordPress Rest API request.
     1092         *
     1093         * @since 4.9.0
     1094         *
     1095         * @param bool $wp_doing_rest Whether or not the current request is a WordPress Rest API request.
     1096         */
     1097        return apply_filters( 'wp_doing_rest', defined( 'REST_REQUEST' ) && REST_REQUEST );
     1098}
     1099
     1100/**
    10831101 * Check whether variable is a WordPress Error.
    10841102 *
    10851103 * Returns true if $thing is an object of the WP_Error class.