Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/SEO/Yoast.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + declare(strict_types=1);
3 +
4 + namespace WP_Rocket\ThirdParty\Plugins\SEO;
5 +
6 + use WP_Rocket\Admin\Options_Data;
7 + use WP_Rocket\Event_Management\Subscriber_Interface;
8 +
9 + class Yoast implements Subscriber_Interface {
10 +
11 + /**
12 + * Array of events this subscriber listens to
13 + *
14 + * @return array
15 + */
16 + public static function get_subscribed_events() {
17 + return [
18 + 'rocket_sitemap_preload_list' => [ 'add_sitemap', 15 ],
19 + ];
20 + }
21 +
22 + /**
23 + * Add Yoast SEO sitemap URL to the sitemaps to preload
24 + *
25 + * @since 2.8
26 + *
27 + * @param array $sitemaps An array of sitemaps to preload.
28 + *
29 + * @return array
30 + */
31 + public function add_sitemap( array $sitemaps ): array {
32 + if ( ! $this->is_sitemap_enabled() ) {
33 + return $sitemaps;
34 + }
35 +
36 + if ( ! class_exists( 'WPSEO_Sitemaps_Router' ) ) {
37 + return $sitemaps;
38 + }
39 +
40 + $sitemaps[] = \WPSEO_Sitemaps_Router::get_base_url( 'sitemap_index.xml' );
41 +
42 + return $sitemaps;
43 + }
44 +
45 + /**
46 + * Checks if sitemap is enabled in Yoast SEO
47 + *
48 + * @since 3.11.1
49 + *
50 + * @return bool
51 + */
52 + private function is_sitemap_enabled(): bool {
53 + static $enabled = null;
54 +
55 + if ( ! is_null( $enabled ) ) {
56 + return $enabled;
57 + }
58 +
59 + if ( ! rocket_has_constant( 'WPSEO_VERSION' ) ) {
60 + $enabled = false;
61 +
62 + return $enabled;
63 + }
64 +
65 + $yoast_seo_xml = get_option( 'wpseo_xml', [] ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
66 +
67 + if ( version_compare( rocket_get_constant( 'WPSEO_VERSION', '' ), '7.0' ) >= 0 ) {
68 + $yoast_seo = get_option( 'wpseo', [] ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
69 + $yoast_seo_xml['enablexmlsitemap'] = isset( $yoast_seo['enable_xml_sitemap'] ) && $yoast_seo['enable_xml_sitemap']; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
70 + }
71 +
72 + $enabled = (bool) $yoast_seo_xml['enablexmlsitemap'];
73 +
74 + return $enabled;
75 + }
76 + }
77 +