Skip to content

Commit 827c263

Browse files
authored
Merge pull request #21676 from Yoast/21333-use-wp_is_serving_rest_request
Replace request helper usage with core function
2 parents 6b33906 + 1d559cd commit 827c263

File tree

11 files changed

+33
-95
lines changed

11 files changed

+33
-95
lines changed

config/dependency-injection/deprecated-classes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Yoast\WP\SEO\Conditionals\Third_Party\Wordproof_Plugin_Inactive_Conditional;
2424
use Yoast\WP\SEO\Config\Wordproof_App_Config;
2525
use Yoast\WP\SEO\Config\Wordproof_Translations;
26+
use Yoast\WP\SEO\Helpers\Request_Helper;
2627
use Yoast\WP\SEO\Helpers\Wordproof_Helper;
2728
use Yoast\WP\SEO\Integrations\Admin\Disable_Concatenate_Scripts_Integration;
2829
use Yoast\WP\SEO\Integrations\Admin\Old_Premium_Integration;
@@ -45,6 +46,7 @@
4546
Ai_Generate_Titles_And_Descriptions_Introduction_Upsell::class => '23.2',
4647
Disable_Concatenate_Scripts_Integration::class => '23.2',
4748
Duplicate_Post_Integration::class => '23.4',
49+
Request_Helper::class => '23.6',
4850
];
4951

5052
foreach ( $deprecated_classes as $original_class => $version ) {

src/context/meta-tags-context.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Yoast\WP\SEO\Helpers\Indexable_Helper;
1212
use Yoast\WP\SEO\Helpers\Options_Helper;
1313
use Yoast\WP\SEO\Helpers\Permalink_Helper;
14-
use Yoast\WP\SEO\Helpers\Request_Helper;
1514
use Yoast\WP\SEO\Helpers\Schema\ID_Helper;
1615
use Yoast\WP\SEO\Helpers\Site_Helper;
1716
use Yoast\WP\SEO\Helpers\Url_Helper;
@@ -122,13 +121,6 @@ class Meta_Tags_Context extends Abstract_Presentation {
122121
*/
123122
private $id_helper;
124123

125-
/**
126-
* The request helper.
127-
*
128-
* @var Request_Helper
129-
*/
130-
private $request_helper;
131-
132124
/**
133125
* The WPSEO Replace Vars object.
134126
*
@@ -184,7 +176,6 @@ class Meta_Tags_Context extends Abstract_Presentation {
184176
* @param Permalink_Helper $permalink_helper The permalink helper.
185177
* @param Indexable_Helper $indexable_helper The indexable helper.
186178
* @param Indexable_Repository $indexable_repository The indexable repository.
187-
* @param Request_Helper $request_helper The request helper.
188179
*/
189180
public function __construct(
190181
Options_Helper $options,
@@ -196,8 +187,7 @@ public function __construct(
196187
User_Helper $user,
197188
Permalink_Helper $permalink_helper,
198189
Indexable_Helper $indexable_helper,
199-
Indexable_Repository $indexable_repository,
200-
Request_Helper $request_helper
190+
Indexable_Repository $indexable_repository
201191
) {
202192
$this->options = $options;
203193
$this->url = $url;
@@ -209,7 +199,6 @@ public function __construct(
209199
$this->permalink_helper = $permalink_helper;
210200
$this->indexable_helper = $indexable_helper;
211201
$this->indexable_repository = $indexable_repository;
212-
$this->request_helper = $request_helper;
213202
}
214203

215204
/**
@@ -625,7 +614,7 @@ public function generate_main_image_url() {
625614
return $this->image->get_attachment_image_url( $this->main_image_id, 'full' );
626615
}
627616

628-
if ( $this->request_helper->is_rest_request() ) {
617+
if ( \wp_is_serving_rest_request() ) {
629618
return $this->get_main_image_url_for_rest_request();
630619
}
631620

@@ -647,7 +636,7 @@ public function generate_main_image_url() {
647636
* @return int|null The main image ID.
648637
*/
649638
public function generate_main_image_id() {
650-
if ( $this->request_helper->is_rest_request() ) {
639+
if ( \wp_is_serving_rest_request() ) {
651640
return $this->get_main_image_id_for_rest_request();
652641
}
653642

src/helpers/request-helper.php renamed to src/deprecated/src/helpers/request-helper.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@
44

55
/**
66
* A helper object for the request state.
7+
*
8+
* @codeCoverageIgnore Because of deprecation.
79
*/
810
class Request_Helper {
911

1012
/**
1113
* Checks if the current request is a REST request.
1214
*
1315
* @return bool True when the current request is a REST request.
16+
*
17+
* @deprecated 23.6
18+
* @codeCoverageIgnore
1419
*/
1520
public function is_rest_request() {
21+
\_deprecated_function( __METHOD__, 'Yoast SEO 23.6', 'wp_is_serving_rest_request' );
22+
1623
return \defined( 'REST_REQUEST' ) && \REST_REQUEST === true;
1724
}
1825
}

src/integrations/blocks/breadcrumbs-block.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Yoast\WP\SEO\Integrations\Blocks;
44

55
use WPSEO_Replace_Vars;
6-
use Yoast\WP\SEO\Helpers\Request_Helper;
76
use Yoast\WP\SEO\Memoizers\Meta_Tags_Context_Memoizer;
87
use Yoast\WP\SEO\Presenters\Breadcrumbs_Presenter;
98
use Yoast\WP\SEO\Repositories\Indexable_Repository;
@@ -56,34 +55,24 @@ class Breadcrumbs_Block extends Dynamic_Block_V3 {
5655
*/
5756
private $indexable_repository;
5857

59-
/**
60-
* The request helper.
61-
*
62-
* @var Request_Helper
63-
*/
64-
private $request_helper;
65-
6658
/**
6759
* Siblings_Block constructor.
6860
*
6961
* @param Meta_Tags_Context_Memoizer $context_memoizer The context.
7062
* @param WPSEO_Replace_Vars $replace_vars The replace variable helper.
7163
* @param Helpers_Surface $helpers The Helpers surface.
7264
* @param Indexable_Repository $indexable_repository The indexable repository.
73-
* @param Request_Helper $request_helper The request helper.
7465
*/
7566
public function __construct(
7667
Meta_Tags_Context_Memoizer $context_memoizer,
7768
WPSEO_Replace_Vars $replace_vars,
7869
Helpers_Surface $helpers,
79-
Indexable_Repository $indexable_repository,
80-
Request_Helper $request_helper
70+
Indexable_Repository $indexable_repository
8171
) {
8272
$this->context_memoizer = $context_memoizer;
8373
$this->replace_vars = $replace_vars;
8474
$this->helpers = $helpers;
8575
$this->indexable_repository = $indexable_repository;
86-
$this->request_helper = $request_helper;
8776

8877
$this->base_path = \WPSEO_PATH . 'blocks/dynamic-blocks/';
8978
}
@@ -99,7 +88,7 @@ public function present( $attributes ) {
9988
$presenter = new Breadcrumbs_Presenter();
10089
// $this->context_memoizer->for_current_page only works on the frontend. To render the right breadcrumb in the
10190
// editor, we need the repository.
102-
if ( $this->request_helper->is_rest_request() || \is_admin() ) {
91+
if ( \wp_is_serving_rest_request() || \is_admin() ) {
10392
$post_id = \get_the_ID();
10493
if ( $post_id ) {
10594
$indexable = $this->indexable_repository->find_by_id_and_type( $post_id, 'post' );

src/integrations/front-end-integration.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Yoast\WP\SEO\Conditionals\Front_End_Conditional;
88
use Yoast\WP\SEO\Context\Meta_Tags_Context;
99
use Yoast\WP\SEO\Helpers\Options_Helper;
10-
use Yoast\WP\SEO\Helpers\Request_Helper;
1110
use Yoast\WP\SEO\Memoizers\Meta_Tags_Context_Memoizer;
1211
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Presenter;
1312
use Yoast\WP\SEO\Presenters\Debug\Marker_Close_Presenter;
@@ -42,13 +41,6 @@ class Front_End_Integration implements Integration_Interface {
4241
*/
4342
protected $options;
4443

45-
/**
46-
* Represents the request helper.
47-
*
48-
* @var Request_Helper
49-
*/
50-
protected $request;
51-
5244
/**
5345
* The helpers surface.
5446
*
@@ -207,22 +199,19 @@ public static function get_conditionals() {
207199
* @param Meta_Tags_Context_Memoizer $context_memoizer The meta tags context memoizer.
208200
* @param ContainerInterface $service_container The DI container.
209201
* @param Options_Helper $options The options helper.
210-
* @param Request_Helper $request The request helper.
211202
* @param Helpers_Surface $helpers The helpers surface.
212203
* @param WPSEO_Replace_Vars $replace_vars The replace vars helper.
213204
*/
214205
public function __construct(
215206
Meta_Tags_Context_Memoizer $context_memoizer,
216207
ContainerInterface $service_container,
217208
Options_Helper $options,
218-
Request_Helper $request,
219209
Helpers_Surface $helpers,
220210
WPSEO_Replace_Vars $replace_vars
221211
) {
222212
$this->container = $service_container;
223213
$this->context_memoizer = $context_memoizer;
224214
$this->options = $options;
225-
$this->request = $request;
226215
$this->helpers = $helpers;
227216
$this->replace_vars = $replace_vars;
228217
}
@@ -353,7 +342,7 @@ public function filter_robots_presenter( $presenters ) {
353342
return $presenters;
354343
}
355344

356-
if ( $this->request->is_rest_request() ) {
345+
if ( \wp_is_serving_rest_request() ) {
357346
return $presenters;
358347
}
359348

@@ -559,7 +548,7 @@ public function should_title_presenter_be_removed() {
559548
*/
560549
private function maybe_remove_title_presenter( $presenters ) {
561550
// Do not remove the title if we're on a REST request.
562-
if ( $this->request->is_rest_request() ) {
551+
if ( \wp_is_serving_rest_request() ) {
563552
return $presenters;
564553
}
565554

src/integrations/third-party/wincher-publish.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ public static function get_conditionals() {
105105
* Determines whether the current request is a REST request.
106106
*
107107
* @return bool Whether the request is a REST request.
108+
*
109+
* @deprecated 23.6
110+
* @codeCoverageIgnore
108111
*/
109112
public function is_rest_request() {
113+
\_deprecated_function( __METHOD__, 'Yoast SEO 23.6', 'wp_is_serving_rest_request' );
110114
return \defined( 'REST_REQUEST' ) && \REST_REQUEST;
111115
}
112116

@@ -153,7 +157,7 @@ public function track_after_rest_api_request( $post ) {
153157
* @return void
154158
*/
155159
public function track_after_post_request( $post_id, $post ) {
156-
if ( $this->is_rest_request() ) {
160+
if ( \wp_is_serving_rest_request() ) {
157161
return;
158162
}
159163

src/surfaces/helpers-surface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
* @property Helpers\Primary_Term_Helper $primary_term
3636
* @property Helpers\Product_Helper $product
3737
* @property Helpers\Redirect_Helper $redirect
38-
* @property Helpers\Request_Helper $request
3938
* @property Helpers\Require_File_Helper $require_file
4039
* @property Helpers\Robots_Helper $robots
4140
* @property Helpers\Short_Link_Helper $short_link

tests/Unit/Context/Meta_Tags_Context_Test.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Yoast\WP\SEO\Helpers\Indexable_Helper;
1313
use Yoast\WP\SEO\Helpers\Options_Helper;
1414
use Yoast\WP\SEO\Helpers\Permalink_Helper;
15-
use Yoast\WP\SEO\Helpers\Request_Helper;
1615
use Yoast\WP\SEO\Helpers\Schema\ID_Helper;
1716
use Yoast\WP\SEO\Helpers\Site_Helper;
1817
use Yoast\WP\SEO\Helpers\Url_Helper;
@@ -92,13 +91,6 @@ final class Meta_Tags_Context_Test extends TestCase {
9291
*/
9392
private $indexable_helper;
9493

95-
/**
96-
* The request helper.
97-
*
98-
* @var Request_Helper
99-
*/
100-
private $request_helper;
101-
10294
/**
10395
* The indexable repository.
10496
*
@@ -131,7 +123,6 @@ protected function set_up() {
131123
$this->permalink_helper = Mockery::mock( Permalink_Helper::class );
132124
$this->indexable_helper = Mockery::mock( Indexable_Helper::class );
133125
$this->indexable_repository = Mockery::mock( Indexable_Repository::class );
134-
$this->request_helper = Mockery::mock( Request_Helper::class );
135126

136127
$this->instance = new Meta_Tags_Context(
137128
$this->options,
@@ -143,8 +134,7 @@ protected function set_up() {
143134
$this->user,
144135
$this->permalink_helper,
145136
$this->indexable_helper,
146-
$this->indexable_repository,
147-
$this->request_helper
137+
$this->indexable_repository
148138
);
149139
}
150140

0 commit comments

Comments
 (0)