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 / set-search-appearance-templates.php

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

138 lines 3.5 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\Application\Tasks;
5
6 use Yoast\WP\SEO\Helpers\Options_Helper;
7 use Yoast\WP\SEO\Helpers\Route_Helper;
8 use Yoast\WP\SEO\Task_List\Domain\Components\Call_To_Action_Entry;
9 use Yoast\WP\SEO\Task_List\Domain\Components\Copy_Set;
10 use Yoast\WP\SEO\Task_List\Domain\Tasks\Abstract_Post_Type_Task;
11
12 /**
13 * Represents the task for setting search appearance templates.
14 */
15 class Set_Search_Appearance_Templates extends Abstract_Post_Type_Task {
16
17 /**
18 * Holds the id.
19 *
20 * @var string
21 */
22 protected $id = 'set-search-appearance-templates';
23
24 /**
25 * Holds the priority.
26 *
27 * @var string
28 */
29 protected $priority = 'high';
30
31 /**
32 * Holds the duration.
33 *
34 * @var int
35 */
36 protected $duration = 10;
37
38 /**
39 * Holds the post type.
40 *
41 * @var string
42 */
43 protected $post_type;
44
45 /**
46 * Holds the options helper.
47 *
48 * @var Options_Helper
49 */
50 private $options_helper;
51
52 /**
53 * Holds the route helper.
54 *
55 * @var Route_Helper
56 */
57 private $route_helper;
58
59 /**
60 * Constructs the task.
61 *
62 * @param Options_Helper $options_helper The options helper.
63 * @param Route_Helper $route_helper The route helper.
64 */
65 public function __construct(
66 Options_Helper $options_helper,
67 Route_Helper $route_helper
68 ) {
69 $this->options_helper = $options_helper;
70 $this->route_helper = $route_helper;
71 }
72
73 /**
74 * Returns whether this task is completed.
75 *
76 * @return bool Whether this task is completed.
77 */
78 public function get_is_completed(): bool {
79 $post_type = \get_post_type_object( $this->get_post_type() );
80
81 // First check if the SEO title has been customized.
82 if ( $this->options_helper->get_title_default( 'title-' . $post_type->name ) !== $this->options_helper->get( 'title-' . $post_type->name ) ) {
83 return true;
84 }
85
86 // Then check if the meta description has been customized.
87 if ( $this->options_helper->get_title_default( 'metadesc-' . $post_type->name ) !== $this->options_helper->get( 'metadesc-' . $post_type->name ) ) {
88 return true;
89 }
90
91 return false;
92 }
93
94 /**
95 * Returns the task's link.
96 *
97 * @return string|null
98 */
99 public function get_link(): ?string {
100 $post_type = \get_post_type_object( $this->get_post_type() );
101 $link = \sprintf(
102 'admin.php?page=wpseo_page_settings#/post-type/%s',
103 $this->route_helper->get_route( $post_type->name, $post_type->rewrite, $post_type->rest_base ),
104 );
105
106 return \self_admin_url( $link );
107 }
108
109 /**
110 * Returns the task's call to action entry.
111 *
112 * @return Call_To_Action_Entry|null
113 */
114 public function get_call_to_action(): ?Call_To_Action_Entry {
115 return new Call_To_Action_Entry(
116 \__( 'Set search templates', 'wordpress-seo' ),
117 'link',
118 $this->get_link(),
119 );
120 }
121
122 /**
123 * Returns the task's copy set.
124 *
125 * @return string|null
126 */
127 public function get_copy_set(): Copy_Set {
128 $post_type = \get_post_type_object( $this->get_post_type() );
129
130 return new Copy_Set(
131 /* translators: %1$s expands to the post type label this task is about */
132 \sprintf( \__( 'Set search appearance templates for your content type: %1$s', 'wordpress-seo' ), $post_type->label ),
133 /* translators: %s expands to the post type name this task is about */
134 '<p>' . \sprintf( \__( 'Generic titles and descriptions make your results unclear in search. Templates ensure every %s has a clear, click-worthy snippet automatically. Go to Search appearance, choose your post type, and set default title and meta description patterns.', 'wordpress-seo' ), $post_type->name ) . '</p>',
135 );
136 }
137 }
138