PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.3.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.3.2
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Integrations / RankMath / RankMathService.php
RankMathService.php
61 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Integrations\RankMath;
4
5 use SureCart\Integrations\Abstracts\NoIndexService;
6
7 /**
8 * Controls the Rank Math integration.
9 */
10 class RankMathService extends NoIndexService {
11 /**
12 * The filter hook name for the robots meta.
13 *
14 * @var string
15 */
16 protected $hook_name = 'rank_math/frontend/robots';
17
18 /**
19 * The filter hook name for the robots meta.
20 *
21 * @var string
22 */
23 public function bootstrap(): void {
24 parent::bootstrap();
25
26 // Skip product model filter registration during sitemap generation to prevent memory exhaustion.
27 add_filter( 'surecart/product/skip_filters', [ $this, 'skipFiltersOnSitemap' ] );
28 }
29
30 /**
31 * Skip model filters during sitemap generation.
32 *
33 * @param bool $skip Whether to skip filters.
34 *
35 * @return bool
36 */
37 public function skipFiltersOnSitemap( $skip ): bool {
38 if ( $skip ) {
39 return $skip;
40 }
41
42 return $this->isSitemapRequest();
43 }
44
45 /**
46 * Check if current request is a sitemap request.
47 *
48 * @return bool
49 */
50 private function isSitemapRequest(): bool {
51 if ( isset( $_SERVER['REQUEST_URI'] ) ) {
52 $uri = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) );
53 if ( false !== strpos( $uri, 'sitemap' ) && '.xml' === substr( $uri, -4 ) ) {
54 return true;
55 }
56 }
57
58 return false;
59 }
60 }
61