PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.0
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
wordpress-seo / src / ai-generator / user-interface / bust-subscription-cache-route.php

bust-subscription-cache-route.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.0, at src/ai-generator/user-interface/bust-subscription-cache-route.php

92 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4 namespace Yoast\WP\SEO\AI_Generator\User_Interface;
5
6 use WP_REST_Response;
7 use WPSEO_Addon_Manager;
8 use Yoast\WP\SEO\Conditionals\AI_Conditional;
9 use Yoast\WP\SEO\Conditionals\Old_Premium_AI_Conditional;
10 use Yoast\WP\SEO\Main;
11 use Yoast\WP\SEO\Routes\Route_Interface;
12
13 /**
14 * Registers a route to bust the subscription cache.
15 *
16 * @makePublic
17 *
18 * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
19 */
20 class Bust_Subscription_Cache_Route implements Route_Interface {
21
22 use Route_Permission_Trait;
23
24 /**
25 * The namespace for this route.
26 *
27 * @var string
28 */
29 public const ROUTE_NAMESPACE = Main::API_V1_NAMESPACE;
30
31 /**
32 * The prefix for this route.
33 *
34 * @var string
35 */
36 public const ROUTE_PREFIX = '/ai_generator/bust_subscription_cache';
37
38 /**
39 * The addon manager instance.
40 *
41 * @var WPSEO_Addon_Manager
42 */
43 private $addon_manager;
44
45 /**
46 * Returns the conditionals based in which this loadable should be active.
47 *
48 * @return array<string> The conditionals.
49 */
50 public static function get_conditionals() {
51 return [ AI_Conditional::class, Old_Premium_AI_Conditional::class ];
52 }
53
54 /**
55 * Class constructor.
56 *
57 * @param WPSEO_Addon_Manager $addon_manager The addon manager instance.
58 */
59 public function __construct( WPSEO_Addon_Manager $addon_manager ) {
60 $this->addon_manager = $addon_manager;
61 }
62
63 /**
64 * Registers routes with WordPress.
65 *
66 * @return void
67 */
68 public function register_routes() {
69 \register_rest_route(
70 self::ROUTE_NAMESPACE,
71 self::ROUTE_PREFIX,
72 [
73 'methods' => 'POST',
74 'args' => [],
75 'callback' => [ $this, 'bust_subscription_cache' ],
76 'permission_callback' => [ $this, 'check_permissions' ],
77 ],
78 );
79 }
80
81 /**
82 * Runs the callback that busts the subscription cache.
83 *
84 * @return WP_REST_Response The response of the callback action.
85 */
86 public function bust_subscription_cache(): WP_REST_Response {
87 $this->addon_manager->remove_site_information_transients();
88
89 return new WP_REST_Response( 'Subscription cache successfully busted.' );
90 }
91 }
92