PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.8
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.8
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / task-list / infrastructure / tasks-collectors / cached-tasks-collector.php

cached-tasks-collector.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.8, at src/task-list/infrastructure/tasks-collectors/cached-tasks-collector.php

51 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4 namespace Yoast\WP\SEO\Task_List\Infrastructure\Tasks_Collectors;
5
6 use WPSEO_Utils;
7
8 /**
9 * Manages the cached collection of tasks.
10 */
11 class Cached_Tasks_Collector implements Tasks_Collector_Interface {
12
13 public const TASKS_TRANSIENT = 'wpseo_task_list_tasks';
14
15 /**
16 * Holds the tasks collector.
17 *
18 * @var Tasks_Collector
19 */
20 private $tasks_collector;
21
22 /**
23 * Constructs the cached collector.
24 *
25 * @param Tasks_Collector $tasks_collector The tasks collector.
26 */
27 public function __construct( Tasks_Collector $tasks_collector ) {
28 $this->tasks_collector = $tasks_collector;
29 }
30
31 /**
32 * Gets the tasks data.
33 *
34 * @TODO: Maybe this can be improved at some point by caching only the is_completed info instead of all the task data.
35 *
36 * @return array<string, array<string, string|bool>> The tasks data.
37 */
38 public function get_tasks_data(): array {
39 $cached_tasks_data = \get_transient( self::TASKS_TRANSIENT );
40
41 if ( $cached_tasks_data !== false ) {
42 return \json_decode( $cached_tasks_data, true );
43 }
44
45 $tasks_data = $this->tasks_collector->get_tasks_data();
46 \set_transient( self::TASKS_TRANSIENT, WPSEO_Utils::format_json_encode( $tasks_data ), \MINUTE_IN_SECONDS );
47
48 return $tasks_data;
49 }
50 }
51