Ticket #45875: 45875.diff
File 45875.diff, 1.7 KB (added by , 6 years ago) |
---|
-
src/wp-includes/load.php
1182 1182 } 1183 1183 1184 1184 /** 1185 * Determines whether the current request is a WordPress REST request. 1186 * 1187 * @since 5.1.0 1188 * 1189 * @return bool True if it's a WordPress REST request, false otherwise. 1190 */ 1191 function wp_doing_rest_request() { 1192 /** 1193 * Filters whether the current request is a WordPress REST request. 1194 * 1195 * @since 5.1.0 1196 * 1197 * @param bool $wp_doing_rest_request Whether the current request is a WordPress REST request. 1198 */ 1199 return apply_filters( 'wp_doing_rest_request', defined( 'REST_REQUEST' ) && REST_REQUEST ); 1200 } 1201 1202 /** 1185 1203 * Check whether variable is a WordPress Error. 1186 1204 * 1187 1205 * Returns true if $thing is an object of the WP_Error class. -
tests/phpunit/tests/load/doingRestRequest.php
1 <?php 2 /** 3 * Tests for wp_doing_rest_request(). 4 * 5 * @group load.php 6 */ 7 class Tests_Functions_Doing_Rest_Request extends WP_UnitTestCase { 8 9 /** 10 * Tests if a REST request has been done. 11 */ 12 public function test_wp_doing_rest_request() { 13 $this->assertFalse( wp_doing_rest_request() ); 14 15 add_filter( 'wp_doing_rest_request', '__return_true' ); 16 $this->assertTrue( wp_doing_rest_request() ); 17 18 define( 'REST_REQUEST', TRUE ); 19 20 $this->assertTrue( wp_doing_rest_request() ); 21 22 add_filter( 'wp_doing_rest_request', '__return_false' ); 23 $this->assertFalse( wp_doing_rest_request() ); 24 } 25 }