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

Yoast / wordpress-seo / dd6e866a9e6d253114633104d9e3858d807178ba

19 Jun 2024 10:03AM UTC coverage: 48.628% (-4.3%) from 52.936%
dd6e866a9e6d253114633104d9e3858d807178ba

push

github

web-flow
Merge pull request #21431 from Yoast/21429-update-copy-in-the-introduction-and-consent-modals

Updates the copy for the introduction and consent modals

7441 of 13454 branches covered (55.31%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 2 files covered. (0.0%)

3718 existing lines in 107 files now uncovered.

25100 of 53464 relevant lines covered (46.95%)

62392.47 hits per line

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

98.0
/src/builders/indexable-home-page-builder.php
1
<?php
2

3
namespace Yoast\WP\SEO\Builders;
4

5
use Yoast\WP\SEO\Helpers\Options_Helper;
6
use Yoast\WP\SEO\Helpers\Post_Helper;
7
use Yoast\WP\SEO\Helpers\Url_Helper;
8
use Yoast\WP\SEO\Models\Indexable;
9
use Yoast\WP\SEO\Values\Indexables\Indexable_Builder_Versions;
10

11
/**
12
 * Homepage Builder for the indexables.
13
 *
14
 * Formats the homepage meta to indexable format.
15
 */
16
class Indexable_Home_Page_Builder {
17

18
        use Indexable_Social_Image_Trait;
19

20
        /**
21
         * The options helper.
22
         *
23
         * @var Options_Helper
24
         */
25
        protected $options;
26

27
        /**
28
         * The URL helper.
29
         *
30
         * @var Url_Helper
31
         */
32
        protected $url_helper;
33

34
        /**
35
         * The latest version of the Indexable-Home-Page-Builder.
36
         *
37
         * @var int
38
         */
39
        protected $version;
40

41
        /**
42
         * Holds the taxonomy helper instance.
43
         *
44
         * @var Post_Helper
45
         */
46
        protected $post_helper;
47

48
        /**
49
         * Indexable_Home_Page_Builder constructor.
50
         *
51
         * @param Options_Helper             $options     The options helper.
52
         * @param Url_Helper                 $url_helper  The url helper.
53
         * @param Indexable_Builder_Versions $versions    Knows the latest version of each Indexable type.
54
         * @param Post_Helper                $post_helper The post helper.
55
         */
56
        public function __construct(
6✔
57
                Options_Helper $options,
58
                Url_Helper $url_helper,
59
                Indexable_Builder_Versions $versions,
60
                Post_Helper $post_helper
61
        ) {
3✔
62
                $this->options     = $options;
6✔
63
                $this->url_helper  = $url_helper;
6✔
64
                $this->version     = $versions->get_latest_version_for_type( 'home-page' );
6✔
65
                $this->post_helper = $post_helper;
6✔
66
        }
3✔
67

68
        /**
69
         * Formats the data.
70
         *
71
         * @param Indexable $indexable The indexable to format.
72
         *
73
         * @return Indexable The extended indexable.
74
         */
75
        public function build( $indexable ) {
6✔
76
                $indexable->object_type      = 'home-page';
6✔
77
                $indexable->title            = $this->options->get( 'title-home-wpseo' );
6✔
78
                $indexable->breadcrumb_title = $this->options->get( 'breadcrumbs-home' );
6✔
79
                $indexable->permalink        = $this->url_helper->home();
6✔
80
                $indexable->blog_id          = \get_current_blog_id();
6✔
81
                $indexable->description      = $this->options->get( 'metadesc-home-wpseo' );
6✔
82
                if ( empty( $indexable->description ) ) {
6✔
UNCOV
83
                        $indexable->description = \get_bloginfo( 'description' );
×
84
                }
85

86
                $indexable->is_robots_noindex = \get_option( 'blog_public' ) === '0';
6✔
87

88
                $indexable->open_graph_title       = $this->options->get( 'open_graph_frontpage_title' );
6✔
89
                $indexable->open_graph_image       = $this->options->get( 'open_graph_frontpage_image' );
6✔
90
                $indexable->open_graph_image_id    = $this->options->get( 'open_graph_frontpage_image_id' );
6✔
91
                $indexable->open_graph_description = $this->options->get( 'open_graph_frontpage_desc' );
6✔
92

93
                // Reset the OG image source & meta.
94
                $indexable->open_graph_image_source = null;
6✔
95
                $indexable->open_graph_image_meta   = null;
6✔
96

97
                // When the image or image id is set.
98
                if ( $indexable->open_graph_image || $indexable->open_graph_image_id ) {
6✔
99
                        $indexable->open_graph_image_source = 'set-by-user';
6✔
100

101
                        $this->set_open_graph_image_meta_data( $indexable );
6✔
102
                }
103

104
                $timestamps                      = $this->get_object_timestamps();
6✔
105
                $indexable->object_published_at  = $timestamps->published_at;
6✔
106
                $indexable->object_last_modified = $timestamps->last_modified;
6✔
107

108
                $indexable->version = $this->version;
6✔
109

110
                return $indexable;
6✔
111
        }
112

113
        /**
114
         * Returns the timestamps for the homepage.
115
         *
116
         * @return object An object with last_modified and published_at timestamps.
117
         */
118
        protected function get_object_timestamps() {
6✔
119
                global $wpdb;
6✔
120
                $post_statuses = $this->post_helper->get_public_post_statuses();
6✔
121

122
                $replacements   = [];
6✔
123
                $replacements[] = 'post_modified_gmt';
6✔
124
                $replacements[] = 'post_date_gmt';
6✔
125
                $replacements[] = $wpdb->posts;
6✔
126
                $replacements[] = 'post_status';
6✔
127
                $replacements   = \array_merge( $replacements, $post_statuses );
6✔
128
                $replacements[] = 'post_password';
6✔
129
                $replacements[] = 'post_type';
6✔
130

131
                //phpcs:disable WordPress.DB.PreparedSQLPlaceholders -- %i placeholder is still not recognized.
132
                //phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
133
                //phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
134
                return $wpdb->get_row(
6✔
135
                        $wpdb->prepare(
6✔
136
                                '
3✔
137
                        SELECT MAX(p.%i) AS last_modified, MIN(p.%i) AS published_at
138
                        FROM %i AS p
139
                        WHERE p.%i IN (' . \implode( ', ', \array_fill( 0, \count( $post_statuses ), '%s' ) ) . ")
6✔
140
                                AND p.%i = ''
141
                                AND p.%i = 'post'
142
                        ",
3✔
143
                                $replacements
6✔
144
                        )
3✔
145
                );
3✔
146
                //phpcs:enable
147
        }
148
}
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

© 2025 Coveralls, Inc