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

Yoast / wordpress-seo / 7561f46cff3e6b924be9a525ca603c82678cf226

26 Nov 2025 11:46AM UTC coverage: 49.023%. First build
7561f46cff3e6b924be9a525ca603c82678cf226

push

github

web-flow
Merge pull request #22740 from Yoast/862-backend-add-microcaching

Add microcaching

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

17518 of 35734 relevant lines covered (49.02%)

3.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/complete-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\Tasks;
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\Domain\Exceptions\Task_Not_Found_Exception;
12
use Yoast\WP\SEO\Task_List\Infrastructure\Tasks_Collectors\Cached_Tasks_Collector;
13
use Yoast\WP\SEO\Task_List\Infrastructure\Tasks_Collectors\Tasks_Collector;
14

15
/**
16
 * Tasks route.
17
 */
18
final class Complete_Task_Route implements Route_Interface {
19

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

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

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

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

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

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

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

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

117
                        if ( ! $task ) {
×
118
                                throw new Task_Not_Found_Exception();
×
119
                        }
120

121
                        $task->complete_task();
×
122
                } catch ( Exception $exception ) {
×
123
                        return new WP_REST_Response(
×
124
                                [
×
125
                                        'success' => false,
×
126
                                        'error'   => $exception->getMessage(),
×
127
                                ],
×
128
                                $exception->getCode()
×
129
                        );
×
130
                }
131

NEW
132
                \delete_transient( Cached_Tasks_Collector::TASKS_TRANSIENT );
×
133

134
                return new WP_REST_Response(
×
135
                        [
×
136
                                'success' => true,
×
137
                        ],
×
138
                        200
×
139
                );
×
140
        }
141

142
        /**
143
         * Permission callback.
144
         *
145
         * @return bool True when user has the 'wpseo_manage_options' capability.
146
         */
147
        public function permission_manage_options() {
×
148
                return $this->capability_helper->current_user_can( 'wpseo_manage_options' );
×
149
        }
150
}
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