• 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

2.99
/admin/formatter/class-term-metabox-formatter.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin\Formatter
6
 */
7

8
/**
9
 * This class provides data for the term metabox by return its values for localization.
10
 */
11
class WPSEO_Term_Metabox_Formatter implements WPSEO_Metabox_Formatter_Interface {
12

13
        /**
14
         * The term the metabox formatter is for.
15
         *
16
         * @var WP_Term|stdClass
17
         */
18
        private $term;
19

20
        /**
21
         * The term's taxonomy.
22
         *
23
         * @var stdClass
24
         */
25
        private $taxonomy;
26

27
        /**
28
         * Whether we must return social templates values.
29
         *
30
         * @var bool
31
         */
32
        private $use_social_templates = false;
33

34
        /**
35
         * Array with the WPSEO_Titles options.
36
         *
37
         * @var array
38
         */
39
        protected $options;
40

41
        /**
42
         * WPSEO_Taxonomy_Scraper constructor.
43
         *
44
         * @param stdClass         $taxonomy Taxonomy.
45
         * @param WP_Term|stdClass $term     Term.
46
         */
UNCOV
47
        public function __construct( $taxonomy, $term ) {
×
UNCOV
48
                $this->taxonomy = $taxonomy;
×
UNCOV
49
                $this->term     = $term;
×
50

UNCOV
51
                $this->use_social_templates = $this->use_social_templates();
×
52
        }
53

54
        /**
55
         * Determines whether the social templates should be used.
56
         *
57
         * @return bool Whether the social templates should be used.
58
         */
59
        public function use_social_templates() {
×
60
                return WPSEO_Options::get( 'opengraph', false ) === true;
×
61
        }
62

63
        /**
64
         * Returns the translated values.
65
         *
66
         * @return array
67
         */
UNCOV
68
        public function get_values() {
×
UNCOV
69
                $values = [];
×
70

71
                // Todo: a column needs to be added on the termpages to add a filter for the keyword, so this can be used in the focus keyphrase doubles.
UNCOV
72
                if ( is_object( $this->term ) && property_exists( $this->term, 'taxonomy' ) ) {
×
73
                        $values = [
UNCOV
74
                                'search_url'                  => $this->search_url(),
×
UNCOV
75
                                'post_edit_url'               => $this->edit_url(),
×
UNCOV
76
                                'base_url'                    => $this->base_url_for_js(),
×
UNCOV
77
                                'taxonomy'                    => $this->term->taxonomy,
×
UNCOV
78
                                'keyword_usage'               => $this->get_focus_keyword_usage(),
×
UNCOV
79
                                'title_template'              => $this->get_title_template(),
×
UNCOV
80
                                'title_template_no_fallback'  => $this->get_title_template( false ),
×
UNCOV
81
                                'metadesc_template'           => $this->get_metadesc_template(),
×
UNCOV
82
                                'first_content_image'         => $this->get_image_url(),
×
UNCOV
83
                                'semrushIntegrationActive'    => 0,
×
UNCOV
84
                                'social_title_template'       => $this->get_social_title_template(),
×
UNCOV
85
                                'social_description_template' => $this->get_social_description_template(),
×
UNCOV
86
                                'social_image_template'       => $this->get_social_image_template(),
×
UNCOV
87
                                'wincherIntegrationActive'    => 0,
×
UNCOV
88
                                'isInsightsEnabled'           => $this->is_insights_enabled(),
×
89
                        ];
90
                }
91

UNCOV
92
                return $values;
×
93
        }
94

95
        /**
96
         * Gets the image URL for the term's social preview.
97
         *
98
         * @return string|null The image URL for the social preview.
99
         */
100
        protected function get_image_url() {
6✔
101
                return WPSEO_Image_Utils::get_first_content_image_for_term( $this->term->term_id );
6✔
102
        }
103

104
        /**
105
         * Returns the url to search for keyword for the taxonomy.
106
         *
107
         * @return string
108
         */
UNCOV
109
        private function search_url() {
×
UNCOV
110
                return admin_url( 'edit-tags.php?taxonomy=' . $this->term->taxonomy . '&seo_kw_filter={keyword}' );
×
111
        }
112

113
        /**
114
         * Returns the url to edit the taxonomy.
115
         *
116
         * @return string
117
         */
UNCOV
118
        private function edit_url() {
×
UNCOV
119
                return admin_url( 'term.php?action=edit&taxonomy=' . $this->term->taxonomy . '&tag_ID={id}' );
×
120
        }
121

122
        /**
123
         * Returns a base URL for use in the JS, takes permalink structure into account.
124
         *
125
         * @return string
126
         */
UNCOV
127
        private function base_url_for_js() {
×
128

UNCOV
129
                $base_url = home_url( '/', null );
×
UNCOV
130
                if ( ! WPSEO_Options::get( 'stripcategorybase', false ) ) {
×
UNCOV
131
                        if ( $this->taxonomy->rewrite ) {
×
UNCOV
132
                                $base_url = trailingslashit( $base_url . $this->taxonomy->rewrite['slug'] );
×
133
                        }
134
                }
135

UNCOV
136
                return $base_url;
×
137
        }
138

139
        /**
140
         * Counting the number of given keyword used for other term than given term_id.
141
         *
142
         * @return array
143
         */
UNCOV
144
        private function get_focus_keyword_usage() {
×
UNCOV
145
                $focuskw = WPSEO_Taxonomy_Meta::get_term_meta( $this->term, $this->term->taxonomy, 'focuskw' );
×
146

UNCOV
147
                return WPSEO_Taxonomy_Meta::get_keyword_usage( $focuskw, $this->term->term_id, $this->term->taxonomy );
×
148
        }
149

150
        /**
151
         * Retrieves the title template.
152
         *
153
         * @param bool $fallback Whether to return the hardcoded fallback if the template value is empty.
154
         *
155
         * @return string The title template.
156
         */
UNCOV
157
        private function get_title_template( $fallback = true ) {
×
UNCOV
158
                $title = $this->get_template( 'title' );
×
159

UNCOV
160
                if ( $title === '' && $fallback === true ) {
×
161
                        /* translators: %s expands to the variable used for term title. */
UNCOV
162
                        $archives = sprintf( __( '%s Archives', 'wordpress-seo' ), '%%term_title%%' );
×
UNCOV
163
                        return $archives . ' %%page%% %%sep%% %%sitename%%';
×
164
                }
165

UNCOV
166
                return $title;
×
167
        }
168

169
        /**
170
         * Retrieves the metadesc template.
171
         *
172
         * @return string The metadesc template.
173
         */
UNCOV
174
        private function get_metadesc_template() {
×
UNCOV
175
                return $this->get_template( 'metadesc' );
×
176
        }
177

178
        /**
179
         * Retrieves the social title template.
180
         *
181
         * @return string The social title template.
182
         */
183
        private function get_social_title_template() {
×
184
                if ( $this->use_social_templates ) {
×
185
                        return $this->get_social_template( 'title' );
×
186
                }
187

188
                return '';
×
189
        }
190

191
        /**
192
         * Retrieves the social description template.
193
         *
194
         * @return string The social description template.
195
         */
196
        private function get_social_description_template() {
×
197
                if ( $this->use_social_templates ) {
×
198
                        return $this->get_social_template( 'description' );
×
199
                }
200

201
                return '';
×
202
        }
203

204
        /**
205
         * Retrieves the social image template.
206
         *
207
         * @return string The social description template.
208
         */
209
        private function get_social_image_template() {
×
210
                if ( $this->use_social_templates ) {
×
211
                        return $this->get_social_template( 'image-url' );
×
212
                }
213

214
                return '';
×
215
        }
216

217
        /**
218
         * Retrieves a template.
219
         *
220
         * @param string $template_option_name The name of the option in which the template you want to get is saved.
221
         *
222
         * @return string
223
         */
UNCOV
224
        private function get_template( $template_option_name ) {
×
UNCOV
225
                $needed_option = $template_option_name . '-tax-' . $this->term->taxonomy;
×
UNCOV
226
                return WPSEO_Options::get( $needed_option, '' );
×
227
        }
228

229
        /**
230
         * Retrieves a social template.
231
         *
232
         * @param string $template_option_name The name of the option in which the template you want to get is saved.
233
         *
234
         * @return string
235
         */
236
        private function get_social_template( $template_option_name ) {
×
237
                /**
238
                 * Filters the social template value for a given taxonomy.
239
                 *
240
                 * @param string $template             The social template value, defaults to empty string.
241
                 * @param string $template_option_name The subname of the option in which the template you want to get is saved.
242
                 * @param string $taxonomy             The name of the taxonomy.
243
                 */
244
                return apply_filters( 'wpseo_social_template_taxonomy', '', $template_option_name, $this->term->taxonomy );
×
245
        }
246

247
        /**
248
         * Determines whether the insights feature is enabled for this taxonomy.
249
         *
250
         * @return bool
251
         */
252
        protected function is_insights_enabled() {
×
253
                return WPSEO_Options::get( 'enable_metabox_insights', false );
×
254
        }
255
}
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