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

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