PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.6
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 / application / tasks / improve-content-readability.php

improve-content-readability.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.6, at src/task-list/application/tasks/improve-content-readability.php

173 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
3 namespace Yoast\WP\SEO\Task_List\Application\Tasks;
4
5 use Yoast\WP\SEO\Editors\Application\Analysis_Features\Enabled_Analysis_Features_Repository;
6 use Yoast\WP\SEO\Editors\Framework\Readability_Analysis;
7 use Yoast\WP\SEO\Helpers\Indexable_Helper;
8 use Yoast\WP\SEO\Task_List\Application\Tasks\Child_Tasks\Improve_Content_Readability_Child;
9 use Yoast\WP\SEO\Task_List\Domain\Components\Call_To_Action_Entry;
10 use Yoast\WP\SEO\Task_List\Domain\Components\Copy_Set;
11 use Yoast\WP\SEO\Task_List\Domain\Tasks\Abstract_Post_Type_Parent_Task;
12 use Yoast\WP\SEO\Task_List\Domain\Tasks\Child_Task_Interface;
13 use Yoast\WP\SEO\Task_List\Infrastructure\Indexables\Recent_Content_Indexable_Collector;
14
15 /**
16 * Represents the task for improving content readability.
17 */
18 class Improve_Content_Readability extends Abstract_Post_Type_Parent_Task {
19
20 use Recent_Content_Task_Trait;
21
22 /**
23 * The default maximum number of content items to retrieve.
24 *
25 * @var int
26 */
27 public const DEFAULT_LIMIT = 100;
28
29 /**
30 * Holds the id.
31 *
32 * @var string
33 */
34 protected $id = 'improve-content-readability';
35
36 /**
37 * Holds the priority.
38 *
39 * @var string
40 */
41 protected $priority = 'medium';
42
43 /**
44 * Holds the recent content indexable collector.
45 *
46 * @var Recent_Content_Indexable_Collector
47 */
48 private $recent_content_indexable_collector;
49
50 /**
51 * Holds the indexable helper.
52 *
53 * @var Indexable_Helper
54 */
55 private $indexable_helper;
56
57 /**
58 * Holds the enabled analysis features repository.
59 *
60 * @var Enabled_Analysis_Features_Repository
61 */
62 private $enabled_analysis_features_repository;
63
64 /**
65 * Constructs the task.
66 *
67 * @param Recent_Content_Indexable_Collector $recent_content_indexable_collector The recent content indexable collector.
68 * @param Indexable_Helper $indexable_helper The indexable helper.
69 * @param Enabled_Analysis_Features_Repository $enabled_analysis_features_repository The enabled analysis features repository.
70 */
71 public function __construct(
72 Recent_Content_Indexable_Collector $recent_content_indexable_collector,
73 Indexable_Helper $indexable_helper,
74 Enabled_Analysis_Features_Repository $enabled_analysis_features_repository
75 ) {
76 $this->recent_content_indexable_collector = $recent_content_indexable_collector;
77 $this->indexable_helper = $indexable_helper;
78 $this->enabled_analysis_features_repository = $enabled_analysis_features_repository;
79 }
80
81 /**
82 * Returns the task's link.
83 *
84 * @return string|null
85 */
86 public function get_link(): ?string {
87 return null;
88 }
89
90 /**
91 * Returns the task's call to action entry.
92 *
93 * @return Call_To_Action_Entry|null
94 */
95 public function get_call_to_action(): ?Call_To_Action_Entry {
96 return null;
97 }
98
99 /**
100 * Returns the task's copy set.
101 *
102 * @return Copy_Set
103 */
104 public function get_copy_set(): Copy_Set {
105 $post_type = \get_post_type_object( $this->get_post_type() );
106
107 return new Copy_Set(
108 /* translators: %1$s expands to the post type label this task is about */
109 \sprintf( \__( 'Improve the readability of your recent content: %1$s', 'wordpress-seo' ), $post_type->label ),
110 \sprintf(
111 /* translators: %1$s expands to an opening p tag, %2$s and %4$s expand to a closing p tag, %3$s expands to an opening p tag and opening strong tag, %5$s expands to a closing strong tag, %6$s expands to an opening strong tag, %7$s expands to a closing strong tag and closing p tag */
112 \__( '%1$sChecking your recent content\'s readability ensures it stays clear and easy to follow, improving your user experience. Follow the feedback to refine your sentence structure and word choice and maintain a high standard of engagement and comprehension.%2$s%3$sPro tip%5$s: Use %6$sAI Optimize%7$s to automatically simplify complex sentences and improve the flow of your writing.%4$s', 'wordpress-seo' ),
113 '<p>',
114 '</p>',
115 '<p><strong>',
116 '</p>',
117 '</strong>',
118 '<strong>',
119 '</strong>',
120 ),
121 );
122 }
123
124 /**
125 * Populates the child tasks by querying content modified in the last two months.
126 *
127 * @return Child_Task_Interface[]
128 */
129 public function populate_child_tasks(): array {
130 $post_type = $this->get_post_type();
131
132 if ( empty( $post_type ) ) {
133 return [];
134 }
135
136 $two_months_ago = $this->get_recency_timestamp();
137
138 $recent_content_items = $this->recent_content_indexable_collector->get_recent_content_with_readability_scores(
139 $post_type,
140 $two_months_ago,
141 self::DEFAULT_LIMIT,
142 );
143
144 $child_tasks = [];
145 foreach ( $recent_content_items as $content_item_score_data ) {
146 $child_tasks[] = new Improve_Content_Readability_Child(
147 $this,
148 $content_item_score_data,
149 );
150 }
151
152 return $child_tasks;
153 }
154
155 /**
156 * Returns whether the task is valid.
157 *
158 * @return bool
159 */
160 public function is_valid(): bool {
161 if ( ! $this->indexable_helper->should_index_indexables() ) {
162 return false;
163 }
164
165 $enabled_features = $this->enabled_analysis_features_repository->get_enabled_features()->to_array();
166 if ( ! isset( $enabled_features[ Readability_Analysis::NAME ] ) || $enabled_features[ Readability_Analysis::NAME ] === false ) {
167 return false;
168 }
169
170 return true;
171 }
172 }
173