PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.6
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 / routes / integrations-route.php

integrations-route.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.6, at src/routes/integrations-route.php

102 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Routes;
4
5 use WP_REST_Request;
6 use WP_REST_Response;
7 use Yoast\WP\SEO\Actions\Integrations_Action;
8 use Yoast\WP\SEO\Conditionals\No_Conditionals;
9 use Yoast\WP\SEO\Main;
10
11 /**
12 * Integrations_Route class.
13 */
14 class Integrations_Route implements Route_Interface {
15
16 use No_Conditionals;
17
18 /**
19 * Represents the integrations route.
20 *
21 * @var string
22 */
23 public const INTEGRATIONS_ROUTE = '/integrations';
24
25 /**
26 * Represents a route to set the state of an integration.
27 *
28 * @var string
29 */
30 public const SET_ACTIVE_ROUTE = '/set_active';
31
32 /**
33 * The integrations action.
34 *
35 * @var Integrations_Action
36 */
37 private $integrations_action;
38
39 /**
40 * Integrations_Route constructor.
41 *
42 * @param Integrations_Action $integrations_action The integrations action.
43 */
44 public function __construct( Integrations_Action $integrations_action ) {
45 $this->integrations_action = $integrations_action;
46 }
47
48 /**
49 * Registers routes with WordPress.
50 *
51 * @return void
52 */
53 public function register_routes() {
54 $set_active_route = [
55 'methods' => 'POST',
56 'callback' => [ $this, 'set_integration_active' ],
57 'permission_callback' => [ $this, 'can_manage_options' ],
58 'args' => [
59 'active' => [
60 'type' => 'boolean',
61 'required' => true,
62 ],
63 'integration' => [
64 'type' => 'string',
65 'required' => true,
66 ],
67 ],
68 ];
69 \register_rest_route( Main::API_V1_NAMESPACE, self::INTEGRATIONS_ROUTE . self::SET_ACTIVE_ROUTE, $set_active_route );
70 }
71
72 /**
73 * Checks if the current user has the right capability.
74 *
75 * @return bool
76 */
77 public function can_manage_options() {
78 return \current_user_can( 'wpseo_manage_options' );
79 }
80
81 /**
82 * Sets integration state.
83 *
84 * @param WP_REST_Request $request The request.
85 *
86 * @return WP_REST_Response
87 */
88 public function set_integration_active( WP_REST_Request $request ) {
89 $params = $request->get_json_params();
90 $integration_name = $params['integration'];
91 $value = $params['active'];
92
93 $data = $this
94 ->integrations_action
95 ->set_integration_active( $integration_name, $value );
96
97 return new WP_REST_Response(
98 [ 'json' => $data ],
99 );
100 }
101 }
102