PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
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 / child-tasks / child-task-trait.php

child-task-trait.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at src/task-list/application/tasks/child-tasks/child-task-trait.php

82 lines 2.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 // phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
5 namespace Yoast\WP\SEO\Task_List\Application\Tasks\Child_Tasks;
6
7 use Yoast\WP\SEO\Task_List\Domain\Components\Copy_Set;
8 use Yoast\WP\SEO\Task_List\Domain\Data\Content_Item_Data_Interface;
9 use Yoast\WP\SEO\Task_List\Domain\Exceptions\Incorrect_Child_Trait_Usage_Exception;
10 use Yoast\WP\SEO\Task_List\Domain\Tasks\Abstract_Child_Task;
11 use Yoast\WP\SEO\Task_List\Domain\Tasks\Parent_Task_Interface;
12
13 /**
14 * Trait for shared child task functionality.
15 * Provides implementations common to all child tasks that use a Content_Item_Data_Interface.
16 */
17 trait Child_Task_Trait {
18
19 /**
20 * The content item data.
21 *
22 * @var Content_Item_Data_Interface
23 */
24 protected $content_item_data;
25
26 /**
27 * Constructs the task.
28 *
29 * @param Parent_Task_Interface $parent_task The parent task.
30 * @param Content_Item_Data_Interface $content_item_data The content item data.
31 *
32 * @throws Incorrect_Child_Trait_Usage_Exception If the class using this trait is not an Abstract_Child_Task.
33 */
34 public function __construct(
35 Parent_Task_Interface $parent_task,
36 Content_Item_Data_Interface $content_item_data
37 ) {
38 if ( ! $this instanceof Abstract_Child_Task ) {
39 throw new Incorrect_Child_Trait_Usage_Exception();
40 }
41
42 $this->parent_task = $parent_task;
43 $this->content_item_data = $content_item_data;
44 }
45
46 /**
47 * Returns the task ID.
48 *
49 * @return string
50 */
51 public function get_id(): string {
52 return $this->parent_task->get_id() . '-' . $this->content_item_data->get_content_id();
53 }
54
55 /**
56 * Returns the task's link.
57 *
58 * @return string|null
59 */
60 public function get_link(): ?string {
61 return \get_edit_post_link( $this->content_item_data->get_content_id(), '&' );
62 }
63
64 /**
65 * Returns the task's copy set.
66 *
67 * @return Copy_Set
68 */
69 public function get_copy_set(): Copy_Set {
70 $title = \html_entity_decode( $this->content_item_data->get_title(), \ENT_QUOTES, 'UTF-8' );
71 if ( $title === '' ) {
72 // Mirror WordPress' own untitled-post convention so screen readers have text content.
73 $title = \__( '(no title)', 'wordpress-seo' );
74 }
75
76 return new Copy_Set(
77 $title,
78 $this->parent_task->get_copy_set()->get_about(),
79 );
80 }
81 }
82