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

Yoast / wordpress-seo / 6638054992

25 Oct 2023 08:55AM UTC coverage: 49.106%. First build
6638054992

Pull #20653

github

vraja-pro
Merge remote-tracking branch 'origin/feature/upgrade-react-and-tests' into feature/upgrade-react-and-tests
Pull Request #20653: Feature/upgrade react and tests

64 of 157 new or added lines in 34 files covered. (40.76%)

13135 of 26748 relevant lines covered (49.11%)

3.96 hits per line

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

92.59
/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(
43
                WP_Query_Wrapper $wp_query_wrapper,
44
                Taxonomy_Helper $taxonomy
45
        ) {
46
                $this->wp_query_wrapper = $wp_query_wrapper;
47
                $this->taxonomy         = $taxonomy;
48
        }
49

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

60
                if ( $this->model->canonical ) {
12✔
61
                        return $this->model->canonical;
2✔
62
                }
63

64
                if ( ! $this->permalink ) {
10✔
65
                        return '';
2✔
66
                }
67

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

73
                return $this->permalink;
4✔
74
        }
75

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

86
                return $this->options->get( 'metadesc-tax-' . $this->model->object_sub_type );
2✔
87
        }
88

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

99
                return \get_term( \get_queried_object()->term_id, \get_queried_object()->taxonomy );
×
100
        }
101

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

113
                return $this->taxonomy->get_term_description( $this->model->object_id );
2✔
114
        }
115

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

127
                if ( $this->open_graph_description && $this->context->open_graph_enabled === true ) {
6✔
128
                        return '';
2✔
129
                }
130

131
                return $this->taxonomy->get_term_description( $this->model->object_id );
4✔
132
        }
133

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

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

148
                        return $this->filter_robots( $robots );
2✔
149
                }
150

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

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

166
                return $this->filter_robots( $robots );
8✔
167
        }
168

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

179
                if ( is_wp_error( $this->source ) ) {
4✔
NEW
180
                        return $this->model->title;
×
181
                }
182

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

189
                // Get the installation default title.
190
                $title = $this->options->get_title_default( 'title-tax-' . $this->source->taxonomy );
2✔
191

192
                return $title;
2✔
193
        }
194

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

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

212
                if ( ! isset( $query->tax_query ) ) {
14✔
213
                        return false;
×
214
                }
215

216
                if ( is_wp_error( $this->source ) ) {
14✔
NEW
217
                        return false;
×
218
                }
219

220
                $queried_terms = $query->tax_query->queried_terms;
14✔
221

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

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