• 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

0.0
/admin/class-admin-recommended-replace-vars.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin
6
 */
7

8
/**
9
 * Determines the recommended replacement variables based on the context.
10
 */
11
class WPSEO_Admin_Recommended_Replace_Vars {
12

13
        /**
14
         * The recommended replacement variables.
15
         *
16
         * @var array
17
         */
18
        protected $recommended_replace_vars = [
19
                // Posts types.
20
                'page'                     => [ 'sitename', 'title', 'sep', 'primary_category' ],
21
                'post'                     => [ 'sitename', 'title', 'sep', 'primary_category' ],
22
                // Homepage.
23
                'homepage'                 => [ 'sitename', 'sitedesc', 'sep' ],
24
                // Custom post type.
25
                'custom_post_type'         => [ 'sitename', 'title', 'sep' ],
26

27
                // Taxonomies.
28
                'category'                 => [ 'sitename', 'term_title', 'sep', 'term_hierarchy' ],
29
                'post_tag'                 => [ 'sitename', 'term_title', 'sep' ],
30
                'post_format'              => [ 'sitename', 'term_title', 'sep', 'page' ],
31

32
                // Custom taxonomy.
33
                'term-in-custom-taxonomy'  => [ 'sitename', 'term_title', 'sep', 'term_hierarchy' ],
34

35
                // Settings - archive pages.
36
                'author_archive'           => [ 'sitename', 'title', 'sep', 'page' ],
37
                'date_archive'             => [ 'sitename', 'sep', 'date', 'page' ],
38
                'custom-post-type_archive' => [ 'sitename', 'title', 'sep', 'page' ],
39

40
                // Settings - special pages.
41
                'search'                   => [ 'sitename', 'searchphrase', 'sep', 'page' ],
42
                '404'                      => [ 'sitename', 'sep' ],
43
        ];
44

45
        /**
46
         * Determines the page type of the current term.
47
         *
48
         * @param string $taxonomy The taxonomy name.
49
         *
50
         * @return string The page type.
51
         */
UNCOV
52
        public function determine_for_term( $taxonomy ) {
×
UNCOV
53
                $recommended_replace_vars = $this->get_recommended_replacevars();
×
UNCOV
54
                if ( array_key_exists( $taxonomy, $recommended_replace_vars ) ) {
×
UNCOV
55
                        return $taxonomy;
×
56
                }
57

58
                return 'term-in-custom-taxonomy';
×
59
        }
60

61
        /**
62
         * Determines the page type of the current post.
63
         *
64
         * @param WP_Post $post A WordPress post instance.
65
         *
66
         * @return string The page type.
67
         */
UNCOV
68
        public function determine_for_post( $post ) {
×
UNCOV
69
                if ( $post instanceof WP_Post === false ) {
×
UNCOV
70
                        return 'post';
×
71
                }
72

UNCOV
73
                if ( $post->post_type === 'page' && $this->is_homepage( $post ) ) {
×
UNCOV
74
                        return 'homepage';
×
75
                }
76

UNCOV
77
                $recommended_replace_vars = $this->get_recommended_replacevars();
×
UNCOV
78
                if ( array_key_exists( $post->post_type, $recommended_replace_vars ) ) {
×
UNCOV
79
                        return $post->post_type;
×
80
                }
81

UNCOV
82
                return 'custom_post_type';
×
83
        }
84

85
        /**
86
         * Determines the page type for a post type.
87
         *
88
         * @param string $post_type The name of the post_type.
89
         * @param string $fallback  The page type to fall back to.
90
         *
91
         * @return string The page type.
92
         */
UNCOV
93
        public function determine_for_post_type( $post_type, $fallback = 'custom_post_type' ) {
×
UNCOV
94
                $page_type                   = $post_type;
×
UNCOV
95
                $recommended_replace_vars    = $this->get_recommended_replacevars();
×
UNCOV
96
                $has_recommended_replacevars = $this->has_recommended_replace_vars( $recommended_replace_vars, $page_type );
×
97

UNCOV
98
                if ( ! $has_recommended_replacevars ) {
×
UNCOV
99
                        return $fallback;
×
100
                }
101

UNCOV
102
                return $page_type;
×
103
        }
104

105
        /**
106
         * Determines the page type for an archive page.
107
         *
108
         * @param string $name     The name of the archive.
109
         * @param string $fallback The page type to fall back to.
110
         *
111
         * @return string The page type.
112
         */
UNCOV
113
        public function determine_for_archive( $name, $fallback = 'custom-post-type_archive' ) {
×
UNCOV
114
                $page_type                   = $name . '_archive';
×
UNCOV
115
                $recommended_replace_vars    = $this->get_recommended_replacevars();
×
UNCOV
116
                $has_recommended_replacevars = $this->has_recommended_replace_vars( $recommended_replace_vars, $page_type );
×
117

UNCOV
118
                if ( ! $has_recommended_replacevars ) {
×
UNCOV
119
                        return $fallback;
×
120
                }
121

UNCOV
122
                return $page_type;
×
123
        }
124

125
        /**
126
         * Retrieves the recommended replacement variables for the given page type.
127
         *
128
         * @param string $page_type The page type.
129
         *
130
         * @return array The recommended replacement variables.
131
         */
UNCOV
132
        public function get_recommended_replacevars_for( $page_type ) {
×
UNCOV
133
                $recommended_replace_vars     = $this->get_recommended_replacevars();
×
UNCOV
134
                $has_recommended_replace_vars = $this->has_recommended_replace_vars( $recommended_replace_vars, $page_type );
×
135

UNCOV
136
                if ( ! $has_recommended_replace_vars ) {
×
UNCOV
137
                        return [];
×
138
                }
139

UNCOV
140
                return $recommended_replace_vars[ $page_type ];
×
141
        }
142

143
        /**
144
         * Retrieves the recommended replacement variables.
145
         *
146
         * @return array The recommended replacement variables.
147
         */
148
        public function get_recommended_replacevars() {
×
149
                /**
150
                 * Filter: Adds the possibility to add extra recommended replacement variables.
151
                 *
152
                 * @param array $additional_replace_vars Empty array to add the replacevars to.
153
                 */
154
                $recommended_replace_vars = apply_filters( 'wpseo_recommended_replace_vars', $this->recommended_replace_vars );
×
155

156
                if ( ! is_array( $recommended_replace_vars ) ) {
×
157
                        return $this->recommended_replace_vars;
×
158
                }
159

160
                return $recommended_replace_vars;
×
161
        }
162

163
        /**
164
         * Returns whether the given page type has recommended replace vars.
165
         *
166
         * @param array  $recommended_replace_vars The recommended replace vars
167
         *                                         to check in.
168
         * @param string $page_type                The page type to check.
169
         *
170
         * @return bool True if there are associated recommended replace vars.
171
         */
172
        private function has_recommended_replace_vars( $recommended_replace_vars, $page_type ) {
×
173
                if ( ! isset( $recommended_replace_vars[ $page_type ] ) ) {
×
174
                        return false;
×
175
                }
176

177
                if ( ! is_array( $recommended_replace_vars[ $page_type ] ) ) {
×
178
                        return false;
×
179
                }
180

181
                return true;
×
182
        }
183

184
        /**
185
         * Determines whether or not a post is the homepage.
186
         *
187
         * @param WP_Post $post The WordPress global post object.
188
         *
189
         * @return bool True if the given post is the homepage.
190
         */
UNCOV
191
        private function is_homepage( $post ) {
×
UNCOV
192
                if ( $post instanceof WP_Post === false ) {
×
193
                        return false;
×
194
                }
195

196
                /*
197
                 * The page on front returns a string with normal WordPress interaction, while the post ID is an int.
198
                 * This way we make sure we always compare strings.
199
                 */
UNCOV
200
                $post_id       = (int) $post->ID;
×
UNCOV
201
                $page_on_front = (int) get_option( 'page_on_front' );
×
202

UNCOV
203
                return get_option( 'show_on_front' ) === 'page' && $page_on_front === $post_id;
×
204
        }
205
}
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