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

Yoast / wordpress-seo / 7efa174615a676ba19866d99c0c6308cce9e246e

26 Nov 2025 09:09AM UTC coverage: 52.648% (-0.02%) from 52.669%
7efa174615a676ba19866d99c0c6308cce9e246e

Pull #22740

github

web-flow
Merge bf16cdc00 into e61fbb6c9
Pull Request #22740: Add microcaching

8307 of 15569 branches covered (53.36%)

Branch coverage included in aggregate %.

0 of 23 new or added lines in 5 files covered. (0.0%)

63 existing lines in 4 files now uncovered.

31811 of 60632 relevant lines covered (52.47%)

47555.86 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\Helpers\Capability_Helper;
8
use Yoast\WP\SEO\Main;
9
use Yoast\WP\SEO\Routes\Route_Interface;
10
use Yoast\WP\SEO\Task_List\Application\Tasks_Repository;
11

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

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

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

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

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

45
        /**
46
         * Returns the needed conditionals.
47
         *
48
         * @return array<string> The conditionals that must be met to load this.
49
         */
50
        public static function get_conditionals(): array {
×
51
                // @TODO: Add the conditional of whether the tasklist feature is enabled (as with the other endpoints too).
52
                return [];
×
53
        }
54

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

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

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

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

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