PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
← All changes | src/integrations/third-party/woocommerce.php +37 -53 18.1 → trunk View file →
@@ -6,8 +6,9 @@
6 6 use Yoast\WP\SEO\Conditionals\Front_End_Conditional;
7 7 use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
8 8 use Yoast\WP\SEO\Helpers\Options_Helper;
9 9 use Yoast\WP\SEO\Helpers\Pagination_Helper;
10 +use Yoast\WP\SEO\Helpers\Woocommerce_Helper;
10 11 use Yoast\WP\SEO\Integrations\Integration_Interface;
11 12 use Yoast\WP\SEO\Memoizers\Meta_Tags_Context_Memoizer;
12 13 use Yoast\WP\SEO\Models\Indexable;
13 14 use Yoast\WP\SEO\Presentations\Indexable_Presentation;
@@ -53,8 +54,15 @@
53 54 */
54 55 protected $pagination_helper;
55 56
56 57 /**
58 + * The WooCommerce helper.
59 + *
60 + * @var Woocommerce_Helper
61 + */
62 + private $woocommerce_helper;
63 +
64 + /**
57 65 * Returns the conditionals based in which this loadable should be active.
58 66 *
59 67 * @return array
60 68 */
@@ -64,13 +72,14 @@
64 72
65 73 /**
66 74 * WooCommerce constructor.
67 75 *
68 - * @param Options_Helper $options The options helper.
69 - * @param WPSEO_Replace_Vars $replace_vars The replace vars helper.
70 - * @param Meta_Tags_Context_Memoizer $context_memoizer The meta tags context memoizer.
71 - * @param Indexable_Repository $repository The indexable repository.
72 - * @param Pagination_Helper $pagination_helper The paginataion helper.
76 + * @param Options_Helper $options The options helper.
77 + * @param WPSEO_Replace_Vars $replace_vars The replace vars helper.
78 + * @param Meta_Tags_Context_Memoizer $context_memoizer The meta tags context memoizer.
79 + * @param Indexable_Repository $repository The indexable repository.
80 + * @param Pagination_Helper $pagination_helper The paginataion helper.
81 + * @param Woocommerce_Helper $woocommerce_helper The WooCommerce helper.
73 82 */
74 83 public function __construct(
75 84 Options_Helper $options,
76 85 WPSEO_Replace_Vars $replace_vars,
@@ -75,15 +84,17 @@
75 84 Options_Helper $options,
76 85 WPSEO_Replace_Vars $replace_vars,
77 86 Meta_Tags_Context_Memoizer $context_memoizer,
78 87 Indexable_Repository $repository,
79 - Pagination_Helper $pagination_helper
88 + Pagination_Helper $pagination_helper,
89 + Woocommerce_Helper $woocommerce_helper
80 90 ) {
81 - $this->options = $options;
82 - $this->replace_vars = $replace_vars;
83 - $this->context_memoizer = $context_memoizer;
84 - $this->repository = $repository;
85 - $this->pagination_helper = $pagination_helper;
91 + $this->options = $options;
92 + $this->replace_vars = $replace_vars;
93 + $this->context_memoizer = $context_memoizer;
94 + $this->repository = $repository;
95 + $this->pagination_helper = $pagination_helper;
96 + $this->woocommerce_helper = $woocommerce_helper;
86 97 }
87 98
88 99 /**
89 100 * Initializes the integration.
@@ -110,9 +121,9 @@
110 121 *
111 122 * @return string The correct canonical.
112 123 */
113 124 public function canonical( $canonical, $presentation = null ) {
114 - if ( ! $this->is_shop_page() ) {
125 + if ( ! $this->woocommerce_helper->is_shop_page() ) {
115 126 return $canonical;
116 127 }
117 128
118 129 $url = $this->get_shop_paginated_link( 'curr', $presentation );
@@ -133,9 +144,9 @@
133 144 *
134 145 * @return string The correct link.
135 146 */
136 147 public function adjacent_rel_url( $link, $rel, $presentation = null ) {
137 - if ( ! $this->is_shop_page() ) {
148 + if ( ! $this->woocommerce_helper->is_shop_page() ) {
138 149 return $link;
139 150 }
140 151
141 152 if ( $rel !== 'next' && $rel !== 'prev' ) {
@@ -158,17 +169,20 @@
158 169 *
159 170 * @return Indexable[] The indexables to be shown in the breadcrumbs, with the shop page added.
160 171 */
161 172 public function add_shop_to_breadcrumbs( $indexables ) {
162 - $shop_page_id = $this->get_shop_page_id();
173 + $shop_page_id = $this->woocommerce_helper->get_shop_page_id();
163 174
164 - if ( $shop_page_id < 1 ) {
175 + if ( ! \is_int( $shop_page_id ) || $shop_page_id < 1 ) {
165 176 return $indexables;
166 177 }
167 178
168 179 foreach ( $indexables as $index => $indexable ) {
169 180 if ( $indexable->object_type === 'post-type-archive' && $indexable->object_sub_type === 'product' ) {
170 - $indexables[ $index ] = $this->repository->find_by_id_and_type( $shop_page_id, 'post' );
181 + $shop_page_indexable = $this->repository->find_by_id_and_type( $shop_page_id, 'post' );
182 + if ( \is_a( $shop_page_indexable, Indexable::class ) ) {
183 + $indexables[ $index ] = $shop_page_indexable;
184 + }
171 185 }
172 186 }
173 187
174 188 return $indexables;
@@ -181,13 +195,13 @@
181 195 *
182 196 * @return int The Page ID of the shop.
183 197 */
184 198 public function get_page_id( $page_id ) {
185 - if ( ! $this->is_shop_page() ) {
199 + if ( ! $this->woocommerce_helper->is_shop_page() ) {
186 200 return $page_id;
187 201 }
188 202
189 - return $this->get_shop_page_id();
203 + return $this->woocommerce_helper->get_shop_page_id();
190 204 }
191 205
192 206 /**
193 207 * Handles the title.
@@ -203,9 +217,9 @@
203 217 if ( $presentation->model->title ) {
204 218 return $title;
205 219 }
206 220
207 - if ( ! $this->is_shop_page() ) {
221 + if ( ! $this->woocommerce_helper->is_shop_page() ) {
208 222 return $title;
209 223 }
210 224
211 225 if ( ! \is_archive() ) {
@@ -211,9 +225,9 @@
211 225 if ( ! \is_archive() ) {
212 226 return $title;
213 227 }
214 228
215 - $shop_page_id = $this->get_shop_page_id();
229 + $shop_page_id = $this->woocommerce_helper->get_shop_page_id();
216 230 if ( $shop_page_id < 1 ) {
217 231 return $title;
218 232 }
219 233
@@ -239,9 +253,9 @@
239 253 if ( $presentation->model->description ) {
240 254 return $description;
241 255 }
242 256
243 - if ( ! $this->is_shop_page() ) {
257 + if ( ! $this->woocommerce_helper->is_shop_page() ) {
244 258 return $description;
245 259 }
246 260
247 261 if ( ! \is_archive() ) {
@@ -247,9 +261,9 @@
247 261 if ( ! \is_archive() ) {
248 262 return $description;
249 263 }
250 264
251 - $shop_page_id = $this->get_shop_page_id();
265 + $shop_page_id = $this->woocommerce_helper->get_shop_page_id();
252 266 if ( $shop_page_id < 1 ) {
253 267 return $description;
254 268 }
255 269
@@ -261,25 +275,8 @@
261 275 return $description;
262 276 }
263 277
264 278 /**
265 - * Checks if the current page is a WooCommerce shop page.
266 - *
267 - * @return bool True when the page is a shop page.
268 - */
269 - protected function is_shop_page() {
270 - if ( ! \is_shop() ) {
271 - return false;
272 - }
273 -
274 - if ( \is_search() ) {
275 - return false;
276 - }
277 -
278 - return true;
279 - }
280 -
281 - /**
282 279 * Uses template for the given option name and replace the replacement variables on it.
283 280 *
284 281 * @param string $option_name The option name to get the template for.
285 282 * @param string $shop_page_id The page id to retrieve template for.
@@ -293,21 +290,8 @@
293 290 return $this->replace_vars->replace( $template, $page );
294 291 }
295 292
296 293 /**
297 - * Returns the id of the set WooCommerce shop page.
298 - *
299 - * @return int The ID of the set page.
300 - */
301 - protected function get_shop_page_id() {
302 - if ( ! \function_exists( 'wc_get_page_id' ) ) {
303 - return -1;
304 - }
305 -
306 - return \wc_get_page_id( 'shop' );
307 - }
308 -
309 - /**
310 294 * Get paginated link for shop page.
311 295 *
312 296 * @param string $rel Link relationship, prev or next or curr.
313 297 * @param Indexable_Presentation|null $presentation The indexable presentation.
@@ -316,9 +300,9 @@
316 300 */
317 301 protected function get_shop_paginated_link( $rel, $presentation = null ) {
318 302 $presentation = $this->ensure_presentation( $presentation );
319 303
320 - $permalink = $presentation->get_permalink();
304 + $permalink = $presentation->permalink;
321 305 if ( ! $permalink ) {
322 306 return null;
323 307 }
324 308