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

Yoast / wordpress-seo / 8218b111533b92ec47f94130a94bcd0102263a45

01 Dec 2025 09:48AM UTC coverage: 53.092%. First build
8218b111533b92ec47f94130a94bcd0102263a45

push

github

web-flow
Merge pull request #22759 from Yoast/feature/task-list

Feature/task list

8697 of 16050 branches covered (54.19%)

Branch coverage included in aggregate %.

98 of 605 new or added lines in 51 files covered. (16.2%)

32413 of 61381 relevant lines covered (52.81%)

46976.02 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

13
/**
14
 * Get tasks route.
15
 */
16
final class Get_Tasks_Route implements Route_Interface {
17

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

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

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

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

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

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

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

108
        /**
109
         * Gets tasks with their information.
110
         *
111
         * @return WP_REST_Response The success or failure response.
112
         */
NEW
113
        public function get_tasks(): WP_REST_Response {
×
114
                try {
NEW
115
                        $tasks_data = $this->tasks_repository->get_tasks_data();
×
NEW
116
                } catch ( Exception $exception ) {
×
NEW
117
                        return new WP_REST_Response(
×
NEW
118
                                [
×
NEW
119
                                        'success' => false,
×
NEW
120
                                        'error'   => $exception->getMessage(),
×
NEW
121
                                ],
×
NEW
122
                                $exception->getCode()
×
NEW
123
                        );
×
124
                }
125

NEW
126
                return new WP_REST_Response(
×
NEW
127
                        [
×
NEW
128
                                'success' => true,
×
NEW
129
                                'tasks'   => $tasks_data,
×
NEW
130
                        ],
×
NEW
131
                        200
×
NEW
132
                );
×
133
        }
134

135
        /**
136
         * Permission callback.
137
         *
138
         * @return bool True when user has the 'wpseo_manage_options' capability.
139
         */
NEW
140
        public function permission_manage_options() {
×
NEW
141
                return $this->capability_helper->current_user_can( 'wpseo_manage_options' );
×
142
        }
143
}
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

© 2025 Coveralls, Inc