• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 42ac58cfbf18724862036a3b2cb2b547525075c2

12 Mar 2026 09:57AM UTC coverage: 50.9%. First build
42ac58cfbf18724862036a3b2cb2b547525075c2

push

github

web-flow
Merge pull request #23019 from Yoast/917-nice-to-have-add-task-to-remove-sample-page

917 add task to remove sample page

24 of 38 new or added lines in 2 files covered. (63.16%)

19113 of 37550 relevant lines covered (50.9%)

4.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/task-list/application/tasks/delete-sample-page.php
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 {
6✔
45
                $page = $this->get_sample_page();
6✔
46

47
                if ( $page === null ) {
6✔
48
                        return true;
2✔
49
                }
50

51
                return $page->post_date !== $page->post_modified;
4✔
52
        }
53

54
        /**
55
         * Returns the task's link.
56
         *
57
         * @return string|null
58
         */
59
        public function get_link(): ?string {
6✔
60
                return null;
6✔
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 {
6✔
71
                $page = $this->get_sample_page();
6✔
72

73
                if ( $page !== null ) {
6✔
74
                        $result = \wp_delete_post( $page->ID );
4✔
75

76
                        if ( ! $result ) {
4✔
77
                                throw new Complete_Sample_Page_Task_Exception();
2✔
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
         */
NEW
87
        private function get_sample_page(): ?WP_Post {
×
NEW
88
                $pages = \get_posts(
×
NEW
89
                        [
×
NEW
90
                                'name'        => 'sample-page',
×
NEW
91
                                'post_type'   => 'page',
×
NEW
92
                                'post_status' => 'publish',
×
NEW
93
                                'numberposts' => 1,
×
NEW
94
                        ],
×
NEW
95
                );
×
96

NEW
97
                if ( empty( $pages ) || $pages[0] instanceof WP_Post === false ) {
×
NEW
98
                        return null;
×
99
                }
100

NEW
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 {
6✔
110
                return new Call_To_Action_Entry(
6✔
111
                        \__( 'Delete for me', 'wordpress-seo' ),
6✔
112
                        'delete',
6✔
113
                        $this->get_link(),
6✔
114
                );
6✔
115
        }
116

117
        /**
118
         * Returns the task's copy set.
119
         *
120
         * @return Copy_Set
121
         */
122
        public function get_copy_set(): Copy_Set {
6✔
123
                return new Copy_Set(
6✔
124
                        \__( 'Remove the "Sample Page"', 'wordpress-seo' ),
6✔
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>',
6✔
126
                );
6✔
127
        }
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc