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() { |
333 | 333 | 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 ); |
334 | 334 | } |
335 | 335 | |
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() ) { |
337 | 337 | @ini_set( 'display_errors', 0 ); |
338 | 338 | } |
339 | 339 | } |
… |
… |
function wp_doing_cron() { |
1080 | 1080 | } |
1081 | 1081 | |
1082 | 1082 | /** |
| 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 | */ |
| 1089 | function 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 | /** |
1083 | 1101 | * Check whether variable is a WordPress Error. |
1084 | 1102 | * |
1085 | 1103 | * Returns true if $thing is an object of the WP_Error class. |