PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
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 / delete-sample-page.php

delete-sample-page.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.5, at src/task-list/application/tasks/delete-sample-page.php

129 lines 2.8 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 WP_Post;
7 use Yoast\WP\SEO\Task_List\Domain\Components\Call_To_Action_Entry;
8 use Yoast\WP\SEO\Task_List\Domain\Components\Copy_Set;
9 use Yoast\WP\SEO\Task_List\Domain\Exceptions\Complete_Sample_Page_Task_Exception;
10 use Yoast\WP\SEO\Task_List\Domain\Tasks\Abstract_Task;
11 use Yoast\WP\SEO\Task_List\Domain\Tasks\Completeable_Task_Interface;
12
13 /**
14 * Represents the task for deleting the sample page.
15 */
16 class Delete_Sample_Page extends Abstract_Task implements Completeable_Task_Interface {
17
18 /**
19 * Holds the id.
20 *
21 * @var string
22 */
23 protected $id = 'delete-sample-page';
24
25 /**
26 * Holds the priority.
27 *
28 * @var string
29 */
30 protected $priority = 'medium';
31
32 /**
33 * Holds the duration.
34 *
35 * @var int
36 */
37 protected $duration = 1;
38
39 /**
40 * Returns whether this task is completed.
41 *
42 * @return bool Whether this task is completed.
43 */
44 public function get_is_completed(): bool {
45 $page = $this->get_sample_page();
46
47 if ( $page === null ) {
48 return true;
49 }
50
51 return $page->post_date !== $page->post_modified;
52 }
53
54 /**
55 * Returns the task's link.
56 *
57 * @return string|null
58 */
59 public function get_link(): ?string {
60 return null;
61 }
62
63 /**
64 * Completes a task.
65 *
66 * @return void
67 *
68 * @throws Complete_Sample_Page_Task_Exception If the Sample Page could not be deleted.
69 */
70 public function complete_task(): void {
71 $page = $this->get_sample_page();
72
73 if ( $page !== null ) {
74 $result = \wp_delete_post( $page->ID );
75
76 if ( ! $result ) {
77 throw new Complete_Sample_Page_Task_Exception();
78 }
79 }
80 }
81
82 /**
83 * Returns the sample page if it exists and is published.
84 *
85 * @return WP_Post|null The sample page or null if not found.
86 */
87 private function get_sample_page(): ?WP_Post {
88 $pages = \get_posts(
89 [
90 'name' => 'sample-page',
91 'post_type' => 'page',
92 'post_status' => 'publish',
93 'numberposts' => 1,
94 ],
95 );
96
97 if ( empty( $pages ) || $pages[0] instanceof WP_Post === false ) {
98 return null;
99 }
100
101 return $pages[0];
102 }
103
104 /**
105 * Returns the task's call to action entry.
106 *
107 * @return Call_To_Action_Entry|null
108 */
109 public function get_call_to_action(): ?Call_To_Action_Entry {
110 return new Call_To_Action_Entry(
111 \__( 'Delete for me', 'wordpress-seo' ),
112 'delete',
113 $this->get_link(),
114 );
115 }
116
117 /**
118 * Returns the task's copy set.
119 *
120 * @return Copy_Set
121 */
122 public function get_copy_set(): Copy_Set {
123 return new Copy_Set(
124 \__( 'Remove the "Sample Page"', 'wordpress-seo' ),
125 '<p>' . \__( 'Leaving placeholder content makes your site look unfinished and untrustworthy. Removing it keeps your site clean and professional for visitors and search engines.', 'wordpress-seo' ) . '</p>',
126 );
127 }
128 }
129