• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / a8a215def53aa38d83991bd5baaddd3337e43c4b

07 Nov 2025 10:08AM UTC coverage: 49.286%. First build
a8a215def53aa38d83991bd5baaddd3337e43c4b

Pull #22691

github

web-flow
Merge aeebaf311 into b63825c5c
Pull Request #22691: Initialize the backend work needed for the tasklist.

7 of 184 new or added lines in 13 files covered. (3.8%)

17497 of 35501 relevant lines covered (49.29%)

3.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/task-list/user-interface/detection/detect-task-route.php
1
<?php
2
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
3
namespace Yoast\WP\SEO\Task_List\User_Interface\Detection;
4

5
use Exception;
6
use WP_REST_Request;
7
use WP_REST_Response;
8
use Yoast\WP\SEO\Helpers\Capability_Helper;
9
use Yoast\WP\SEO\Main;
10
use Yoast\WP\SEO\Routes\Route_Interface;
11
use Yoast\WP\SEO\Task_List\Application\Tasks_Collector;
12
use Yoast\WP\SEO\Task_List\Domain\Task_Not_Found_Exception;
13

14
/**
15
 * Tasks route.
16
 */
17
final class Detect_Task_Route implements Route_Interface {
18

19
        /**
20
         * The namespace of the route.
21
         *
22
         * @var string
23
         */
24
        public const ROUTE_NAMESPACE = Main::API_V1_NAMESPACE;
25

26
        /**
27
         * The prefix of the route.
28
         *
29
         * @var string
30
         */
31
        public const ROUTE_NAME = '/detect_task';
32

33
        /**
34
         * The task collector.
35
         *
36
         * @var Tasks_Collector
37
         */
38
        private $tasks_collector;
39

40
        /**
41
         * Holds the capability helper instance.
42
         *
43
         * @var Capability_Helper
44
         */
45
        private $capability_helper;
46

47
        /**
48
         * Returns the needed conditionals.
49
         *
50
         * @return array<string> The conditionals that must be met to load this.
51
         */
NEW
52
        public static function get_conditionals(): array {
×
NEW
53
                return [];
×
54
        }
55

56
        /**
57
         * The constructor.
58
         *
59
         * @param Tasks_Collector   $tasks_collector   The collector for all tasks.
60
         * @param Capability_Helper $capability_helper The capability helper.
61
         */
NEW
62
        public function __construct(
×
63
                Tasks_Collector $tasks_collector,
64
                Capability_Helper $capability_helper
65
        ) {
NEW
66
                $this->tasks_collector   = $tasks_collector;
×
NEW
67
                $this->capability_helper = $capability_helper;
×
68
        }
69

70
        /**
71
         * Registers routes for scores.
72
         *
73
         * @return void
74
         */
NEW
75
        public function register_routes() {
×
NEW
76
                \register_rest_route(
×
NEW
77
                        self::ROUTE_NAMESPACE,
×
NEW
78
                        self::ROUTE_NAME,
×
NEW
79
                        [
×
NEW
80
                                [
×
NEW
81
                                        'methods'             => 'GET',
×
NEW
82
                                        'callback'            => [ $this, 'detect_task' ],
×
NEW
83
                                        'permission_callback' => [ $this, 'permission_manage_options' ],
×
NEW
84
                                        'args'                => [
×
NEW
85
                                                'options' => [
×
NEW
86
                                                        'type'       => 'object',
×
NEW
87
                                                        'required'   => true,
×
NEW
88
                                                        'properties' => [
×
NEW
89
                                                                'task' => [
×
NEW
90
                                                                        'type'              => 'string',
×
NEW
91
                                                                        'required'          => true,
×
NEW
92
                                                                        'sanitize_callback' => 'sanitize_text_field',
×
NEW
93
                                                                ],
×
NEW
94
                                                        ],
×
NEW
95
                                                ],
×
NEW
96
                                        ],
×
NEW
97
                                ],
×
NEW
98
                        ]
×
NEW
99
                );
×
100
        }
101

102
        /**
103
         * Detects whether a task is completed.
104
         *
105
         * @param WP_REST_Request $request The request object.
106
         *
107
         * @return WP_REST_Response The success or failure response.
108
         *
109
         * @throws Task_Not_Found_Exception When the given task name is not implemented yet.
110
         */
NEW
111
        public function detect_task( WP_REST_Request $request ): WP_REST_Response {
×
112
                try {
NEW
113
                        $task_name = $request->get_param( 'options' )['task'];
×
NEW
114
                        $task      = $this->tasks_collector->get_task( $task_name );
×
115

NEW
116
                        if ( ! $task ) {
×
NEW
117
                                throw new Task_Not_Found_Exception();
×
118
                        }
NEW
119
                } catch ( Exception $exception ) {
×
NEW
120
                        return new WP_REST_Response(
×
NEW
121
                                [
×
NEW
122
                                        'success' => false,
×
NEW
123
                                        'error'   => $exception->getMessage(),
×
NEW
124
                                ],
×
NEW
125
                                $exception->getCode()
×
NEW
126
                        );
×
127
                }
128

NEW
129
                return new WP_REST_Response(
×
NEW
130
                        [
×
NEW
131
                                'success'     => true,
×
NEW
132
                                'isCompleted' => $task->get_is_completed(),
×
NEW
133
                        ],
×
NEW
134
                        200
×
NEW
135
                );
×
136
        }
137

138
        /**
139
         * Permission callback.
140
         *
141
         * @return bool True when user has the 'wpseo_manage_options' capability.
142
         */
NEW
143
        public function permission_manage_options() {
×
NEW
144
                return $this->capability_helper->current_user_can( 'wpseo_manage_options' );
×
145
        }
146
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc