The conditionals that must be met to load this. */ public static function get_conditionals(): array { return [ Task_List_Enabled_Conditional::class, ]; } /** * The constructor. * * @param Tasks_Repository $tasks_repository The repository for all tasks. * @param Capability_Helper $capability_helper The capability helper. * @param Action_Tracker $action_tracker The action tracker. */ public function __construct( Tasks_Repository $tasks_repository, Capability_Helper $capability_helper, Action_Tracker $action_tracker ) { $this->tasks_repository = $tasks_repository; $this->capability_helper = $capability_helper; $this->action_tracker = $action_tracker; } /** * Registers routes for scores. * * @return void */ public function register_routes() { \register_rest_route( self::ROUTE_NAMESPACE, self::ROUTE_NAME, [ [ 'methods' => 'GET', 'callback' => [ $this, 'get_tasks' ], 'permission_callback' => [ $this, 'permission_manage_options' ], 'args' => [ 'options' => [ 'type' => 'object', 'required' => false, 'properties' => [ 'filter' => [ 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ], 'limit' => [ 'type' => 'int', 'required' => false, 'sanitize_callback' => 'absint', ], ], ], ], ], ], ); } /** * Gets tasks with their information. * * @return WP_REST_Response The success or failure response. */ public function get_tasks(): WP_REST_Response { try { $this->action_tracker->track_version_for_performed_action( 'task_list_first_opened_on' ); $tasks_data = $this->tasks_repository->get_tasks_data(); } catch ( Exception $exception ) { return new WP_REST_Response( [ 'success' => false, 'error' => $exception->getMessage(), ], $exception->getCode(), ); } return new WP_REST_Response( [ 'success' => true, 'tasks' => $tasks_data, ], 200, ); } /** * Permission callback. * * @return bool True when user has the 'wpseo_manage_options' capability. */ public function permission_manage_options() { return $this->capability_helper->current_user_can( 'wpseo_manage_options' ); } }