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

Yoast / wordpress-seo / 2243882f0ca744a7c0183ad3f429aa5ea7de4a97

17 Dec 2025 11:13AM UTC coverage: 53.03% (-0.01%) from 53.04%
2243882f0ca744a7c0183ad3f429aa5ea7de4a97

Pull #22815

github

web-flow
Merge cb861603d into 0e416242f
Pull Request #22815: Add tracking for the task list.

8708 of 16082 branches covered (54.15%)

Branch coverage included in aggregate %.

35 of 81 new or added lines in 11 files covered. (43.21%)

2 existing lines in 2 files now uncovered.

32455 of 61540 relevant lines covered (52.74%)

46854.65 hits per line

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

0.0
/src/task-list/user-interface/tasks/get-tasks-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\Tasks;
4

5
use Exception;
6
use WP_REST_Response;
7
use Yoast\WP\SEO\Conditionals\Task_List_Enabled_Conditional;
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_Repository;
12
use Yoast\WP\SEO\Tracking\Application\Action_Tracker;
13

14
/**
15
 * Get tasks route.
16
 */
17
final class Get_Tasks_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 = '/get_tasks';
32

33
        /**
34
         * The task repository.
35
         *
36
         * @var Tasks_Repository
37
         */
38
        private $tasks_repository;
39

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

47
        /**
48
         * Holds the action tracker instance.
49
         *
50
         * @var Action_Tracker
51
         */
52
        private $action_tracker;
53

54
        /**
55
         * Returns the needed conditionals.
56
         *
57
         * @return array<string> The conditionals that must be met to load this.
58
         */
59
        public static function get_conditionals(): array {
×
60
                return [
×
61
                        Task_List_Enabled_Conditional::class,
×
62
                ];
×
63
        }
64

65
        /**
66
         * The constructor.
67
         *
68
         * @param Tasks_Repository  $tasks_repository  The repository for all tasks.
69
         * @param Capability_Helper $capability_helper The capability helper.
70
         * @param Action_Tracker    $action_tracker    The action tracker.
71
         */
72
        public function __construct(
×
73
                Tasks_Repository $tasks_repository,
74
                Capability_Helper $capability_helper,
75
                Action_Tracker $action_tracker
76
        ) {
77
                $this->tasks_repository  = $tasks_repository;
×
78
                $this->capability_helper = $capability_helper;
×
NEW
79
                $this->action_tracker    = $action_tracker;
×
80
        }
81

82
        /**
83
         * Registers routes for scores.
84
         *
85
         * @return void
86
         */
87
        public function register_routes() {
×
88
                \register_rest_route(
×
89
                        self::ROUTE_NAMESPACE,
×
90
                        self::ROUTE_NAME,
×
91
                        [
×
92
                                [
×
93
                                        'methods'             => 'GET',
×
94
                                        'callback'            => [ $this, 'get_tasks' ],
×
95
                                        'permission_callback' => [ $this, 'permission_manage_options' ],
×
96
                                        'args'                => [
×
97
                                                'options' => [
×
98
                                                        'type'       => 'object',
×
99
                                                        'required'   => false,
×
100
                                                        'properties' => [
×
101
                                                                'filter' => [
×
102
                                                                        'type'              => 'string',
×
103
                                                                        'required'          => false,
×
104
                                                                        'sanitize_callback' => 'sanitize_text_field',
×
105
                                                                ],
×
106
                                                                'limit' => [
×
107
                                                                        'type'              => 'int',
×
108
                                                                        'required'          => false,
×
109
                                                                        'sanitize_callback' => 'absint',
×
110
                                                                ],
×
111
                                                        ],
×
112
                                                ],
×
113
                                        ],
×
114
                                ],
×
115
                        ]
×
116
                );
×
117
        }
118

119
        /**
120
         * Gets tasks with their information.
121
         *
122
         * @return WP_REST_Response The success or failure response.
123
         */
124
        public function get_tasks(): WP_REST_Response {
×
125
                try {
NEW
126
                        $this->action_tracker->track_version_for_performed_action( 'task_list_first_opened_on' );
×
127

128
                        $tasks_data = $this->tasks_repository->get_tasks_data();
×
129
                } catch ( Exception $exception ) {
×
130
                        return new WP_REST_Response(
×
131
                                [
×
132
                                        'success' => false,
×
133
                                        'error'   => $exception->getMessage(),
×
134
                                ],
×
135
                                $exception->getCode()
×
136
                        );
×
137
                }
138

139
                return new WP_REST_Response(
×
140
                        [
×
141
                                'success' => true,
×
142
                                'tasks'   => $tasks_data,
×
143
                        ],
×
144
                        200
×
145
                );
×
146
        }
147

148
        /**
149
         * Permission callback.
150
         *
151
         * @return bool True when user has the 'wpseo_manage_options' capability.
152
         */
153
        public function permission_manage_options() {
×
154
                return $this->capability_helper->current_user_can( 'wpseo_manage_options' );
×
155
        }
156
}
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