• 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/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\Conditionals\Task_List_Enabled_Conditional;
9
use Yoast\WP\SEO\Helpers\Capability_Helper;
10
use Yoast\WP\SEO\Main;
11
use Yoast\WP\SEO\Routes\Route_Interface;
12
use Yoast\WP\SEO\Task_List\Domain\Exceptions\Task_Not_Found_Exception;
13
use Yoast\WP\SEO\Task_List\Infrastructure\Tasks_Collectors\Cached_Tasks_Collector;
14
use Yoast\WP\SEO\Task_List\Infrastructure\Tasks_Collectors\Tasks_Collector;
15
use Yoast\WP\SEO\Tracking\Application\Action_Tracker;
16

17
/**
18
 * Tasks route.
19
 */
20
final class Complete_Task_Route implements Route_Interface {
21

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

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

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

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

50
        /**
51
         * Holds the action tracker instance.
52
         *
53
         * @var Action_Tracker
54
         */
55
        private $action_tracker;
56

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

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

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

117
        /**
118
         * Completes a task.
119
         *
120
         * @param WP_REST_Request $request The request object.
121
         *
122
         * @return WP_REST_Response The success or failure response.
123
         *
124
         * @throws Task_Not_Found_Exception When the given task name is not implemented yet.
125
         */
126
        public function complete_task( WP_REST_Request $request ): WP_REST_Response {
×
127
                try {
NEW
128
                        $this->action_tracker->track_version_for_performed_action( 'task_first_actioned_on' );
×
129

130
                        $task_name = $request->get_param( 'options' )['task'];
×
131
                        $task      = $this->tasks_collector->get_completeable_task( $task_name );
×
132

133
                        if ( ! $task ) {
×
134
                                throw new Task_Not_Found_Exception();
×
135
                        }
136

137
                        $task->complete_task();
×
138
                } catch ( Exception $exception ) {
×
139
                        return new WP_REST_Response(
×
140
                                [
×
141
                                        'success' => false,
×
142
                                        'error'   => $exception->getMessage(),
×
143
                                ],
×
144
                                $exception->getCode()
×
145
                        );
×
146
                }
147

148
                \delete_transient( Cached_Tasks_Collector::TASKS_TRANSIENT );
×
149

150
                return new WP_REST_Response(
×
151
                        [
×
152
                                'success' => true,
×
153
                        ],
×
154
                        200
×
155
                );
×
156
        }
157

158
        /**
159
         * Permission callback.
160
         *
161
         * @return bool True when user has the 'wpseo_manage_options' capability.
162
         */
163
        public function permission_manage_options() {
×
164
                return $this->capability_helper->current_user_can( 'wpseo_manage_options' );
×
165
        }
166
}
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