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

Yoast / wordpress-seo / f44229b0911ab3251ebf3aec976097d0ed682dee

24 Mar 2025 06:25PM UTC coverage: 48.68% (-0.03%) from 48.71%
f44229b0911ab3251ebf3aec976097d0ed682dee

push

github

web-flow
Merge pull request #22139 from Yoast/JRF/CSQA/remove-unused-use-statements

CS/QA: remove unused import use statements

16083 of 33038 relevant lines covered (48.68%)

3.61 hits per line

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

93.65
/src/presentations/indexable-term-archive-presentation.php
1
<?php
2

3
namespace Yoast\WP\SEO\Presentations;
4

5
use WP_Term;
6
use Yoast\WP\SEO\Helpers\Taxonomy_Helper;
7
use Yoast\WP\SEO\Wrappers\WP_Query_Wrapper;
8

9
/**
10
 * Class Indexable_Term_Archive_Presentation.
11
 *
12
 * Presentation object for indexables.
13
 *
14
 * @property WP_Term $source
15
 */
16
class Indexable_Term_Archive_Presentation extends Indexable_Presentation {
17

18
        use Archive_Adjacent;
19

20
        /**
21
         * Holds the WP query wrapper instance.
22
         *
23
         * @var WP_Query_Wrapper
24
         */
25
        private $wp_query_wrapper;
26

27
        /**
28
         * Holds the taxonomy helper instance.
29
         *
30
         * @var Taxonomy_Helper
31
         */
32
        private $taxonomy;
33

34
        /**
35
         * Indexable_Post_Type_Presentation constructor.
36
         *
37
         * @codeCoverageIgnore
38
         *
39
         * @param WP_Query_Wrapper $wp_query_wrapper The wp query wrapper.
40
         * @param Taxonomy_Helper  $taxonomy         The Taxonomy helper.
41
         */
42
        public function __construct( WP_Query_Wrapper $wp_query_wrapper, Taxonomy_Helper $taxonomy ) {
43
                $this->wp_query_wrapper = $wp_query_wrapper;
44
                $this->taxonomy         = $taxonomy;
45
        }
46

47
        /**
48
         * Generates the canonical.
49
         *
50
         * @return string The canonical.
51
         */
52
        public function generate_canonical() {
14✔
53
                if ( $this->is_multiple_terms_query() ) {
14✔
54
                        return '';
2✔
55
                }
56

57
                if ( $this->model->canonical ) {
12✔
58
                        return $this->model->canonical;
2✔
59
                }
60

61
                if ( ! $this->permalink ) {
10✔
62
                        return '';
2✔
63
                }
64

65
                $current_page = $this->pagination->get_current_archive_page_number();
8✔
66
                if ( $current_page > 1 ) {
8✔
67
                        return $this->pagination->get_paginated_url( $this->permalink, $current_page );
4✔
68
                }
69

70
                return $this->permalink;
4✔
71
        }
72

73
        /**
74
         * Generates the meta description.
75
         *
76
         * @return string The meta description.
77
         */
78
        public function generate_meta_description() {
4✔
79
                if ( $this->model->description ) {
4✔
80
                        return $this->model->description;
2✔
81
                }
82

83
                return $this->options->get( 'metadesc-tax-' . $this->model->object_sub_type );
2✔
84
        }
85

86
        /**
87
         * Generates the source.
88
         *
89
         * @return array The source.
90
         */
91
        public function generate_source() {
2✔
92
                if ( ! empty( $this->model->object_id ) || \get_queried_object() === null ) {
2✔
93
                        return \get_term( $this->model->object_id, $this->model->object_sub_type );
2✔
94
                }
95

96
                return \get_term( \get_queried_object()->term_id, \get_queried_object()->taxonomy );
×
97
        }
98

99
        /**
100
         * Generates the Open Graph description.
101
         *
102
         * @return string The Open Graph description.
103
         */
104
        public function generate_open_graph_description() {
8✔
105
                $open_graph_description = parent::generate_open_graph_description();
8✔
106
                if ( $open_graph_description ) {
8✔
107
                        return $open_graph_description;
6✔
108
                }
109

110
                return $this->taxonomy->get_term_description( $this->model->object_id );
2✔
111
        }
112

113
        /**
114
         * Generates the Twitter description.
115
         *
116
         * @return string The Twitter description.
117
         */
118
        public function generate_twitter_description() {
8✔
119
                $twitter_description = parent::generate_twitter_description();
8✔
120
                if ( $twitter_description ) {
8✔
121
                        return $twitter_description;
2✔
122
                }
123

124
                if ( $this->open_graph_description && $this->context->open_graph_enabled === true ) {
6✔
125
                        return '';
2✔
126
                }
127

128
                return $this->taxonomy->get_term_description( $this->model->object_id );
4✔
129
        }
130

131
        /**
132
         * Generates the robots value.
133
         *
134
         * @return array The robots value.
135
         */
136
        public function generate_robots() {
10✔
137
                $robots = $this->get_base_robots();
10✔
138

139
                /**
140
                 * If its a multiple terms archive page return a noindex.
141
                 */
142
                if ( $this->current_page->is_multiple_terms_page() ) {
10✔
143
                        $robots['index'] = 'noindex';
2✔
144

145
                        return $this->filter_robots( $robots );
2✔
146
                }
147

148
                /**
149
                 * First we get the no index option for this taxonomy, because it can be overwritten the indexable value for
150
                 * this specific term.
151
                 */
152
                if ( \is_wp_error( $this->source ) || ! $this->taxonomy->is_indexable( $this->source->taxonomy ) ) {
8✔
153
                        $robots['index'] = 'noindex';
4✔
154
                }
155

156
                /**
157
                 * Overwrite the index directive when there is a term specific directive set.
158
                 */
159
                if ( $this->model->is_robots_noindex !== null ) {
8✔
160
                        $robots['index'] = ( $this->model->is_robots_noindex ) ? 'noindex' : 'index';
4✔
161
                }
162

163
                return $this->filter_robots( $robots );
8✔
164
        }
165

166
        /**
167
         * Generates the title.
168
         *
169
         * @return string The title.
170
         */
171
        public function generate_title() {
6✔
172
                if ( $this->model->title ) {
6✔
173
                        return $this->model->title;
2✔
174
                }
175

176
                if ( \is_wp_error( $this->source ) ) {
4✔
177
                        return $this->model->title;
×
178
                }
179

180
                // Get the SEO title as entered in Search Appearance.
181
                $title = $this->options->get( 'title-tax-' . $this->source->taxonomy );
4✔
182
                if ( $title ) {
4✔
183
                        return $title;
2✔
184
                }
185

186
                // Get the installation default title.
187
                $title = $this->options->get_title_default( 'title-tax-' . $this->source->taxonomy );
2✔
188

189
                return $title;
2✔
190
        }
191

192
        /**
193
         * Generates the Open Graph type.
194
         *
195
         * @return string The Open Graph type.
196
         */
197
        public function generate_open_graph_type() {
2✔
198
                return 'article';
2✔
199
        }
200

201
        /**
202
         * Checks if term archive query is for multiple terms (/term-1,term-2/ or /term-1+term-2/).
203
         *
204
         * @return bool Whether the query contains multiple terms.
205
         */
206
        protected function is_multiple_terms_query() {
14✔
207
                $query = $this->wp_query_wrapper->get_query();
14✔
208

209
                if ( ! isset( $query->tax_query ) ) {
14✔
210
                        return false;
×
211
                }
212

213
                if ( \is_wp_error( $this->source ) ) {
14✔
214
                        return false;
×
215
                }
216

217
                $queried_terms = $query->tax_query->queried_terms;
14✔
218

219
                if ( empty( $queried_terms[ $this->source->taxonomy ]['terms'] ) ) {
14✔
220
                        return false;
12✔
221
                }
222

223
                return \count( $queried_terms[ $this->source->taxonomy ]['terms'] ) > 1;
2✔
224
        }
225
}
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