PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.4
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-seo.php

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

174 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\Keyphrase_Analysis;
7 use Yoast\WP\SEO\Helpers\Indexable_Helper;
8 use Yoast\WP\SEO\Task_List\Application\Tasks\Child_Tasks\Improve_Content_SEO_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 SEO.
17 */
18 class Improve_Content_SEO 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-seo';
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 // @TODO: the copy in the task is very much WIP from the designing team, so let's deal with that later on.
106 $post_type = \get_post_type_object( $this->get_post_type() );
107
108 return new Copy_Set(
109 /* translators: %1$s expands to the post type label this task is about */
110 \sprintf( \__( 'Improve the SEO of your recent content: %1$s', 'wordpress-seo' ), $post_type->label ),
111 \sprintf(
112 /* 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 */
113 \__( '%1$sBy aligning your content with search intent and focus keyphrases, you make it easier for people and AI systems to find your website, improving your organic visibility. Use the recommendations in the SEO analysis to strengthen your technical performance and ranking potential.%2$s%3$sPro tip%5$s: Use %6$sAI Generate%7$s to quickly generate high quality meta descriptions and keyphrase-rich headers that rank well.%4$s', 'wordpress-seo' ),
114 '<p>',
115 '</p>',
116 '<p><strong>',
117 '</p>',
118 '</strong>',
119 '<strong>',
120 '</strong>',
121 ),
122 );
123 }
124
125 /**
126 * Populates the child tasks by querying content modified in the last two months.
127 *
128 * @return Child_Task_Interface[]
129 */
130 public function populate_child_tasks(): array {
131 $post_type = $this->get_post_type();
132
133 if ( empty( $post_type ) ) {
134 return [];
135 }
136
137 $two_months_ago = $this->get_recency_timestamp();
138
139 $recent_content_items = $this->recent_content_indexable_collector->get_recent_content_with_seo_scores(
140 $post_type,
141 $two_months_ago,
142 self::DEFAULT_LIMIT,
143 );
144
145 $child_tasks = [];
146 foreach ( $recent_content_items as $content_item_score_data ) {
147 $child_tasks[] = new Improve_Content_SEO_Child(
148 $this,
149 $content_item_score_data,
150 );
151 }
152
153 return $child_tasks;
154 }
155
156 /**
157 * Returns whether the task is valid.
158 *
159 * @return bool
160 */
161 public function is_valid(): bool {
162 if ( ! $this->indexable_helper->should_index_indexables() ) {
163 return false;
164 }
165
166 $enabled_features = $this->enabled_analysis_features_repository->get_enabled_features()->to_array();
167 if ( ! isset( $enabled_features[ Keyphrase_Analysis::NAME ] ) || $enabled_features[ Keyphrase_Analysis::NAME ] === false ) {
168 return false;
169 }
170
171 return true;
172 }
173 }
174