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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / class-wc-breadcrumb.php
woocommerce / includes Last commit date
abstracts 1 month ago admin 1 week ago blocks 11 months ago cli 1 month ago customizer 4 months ago data-stores 1 month ago emails 6 days ago export 1 year ago gateways 1 month ago import 3 months ago integrations 2 months ago interfaces 4 months ago legacy 4 months ago libraries 1 month ago log-handlers 1 year ago payment-tokens 5 years ago product-usage 1 year ago queue 4 months ago react-admin 1 month ago rest-api 1 month ago shipping 3 months ago shortcodes 1 month ago theme-support 2 years ago tracks 1 month ago traits 5 years ago walkers 5 years ago wccom-site 1 month ago widgets 2 months ago class-wc-ajax.php 1 month ago class-wc-auth.php 1 year ago class-wc-autoloader.php 9 months ago class-wc-background-emailer.php 2 months ago class-wc-background-updater.php 5 years ago class-wc-brands-brand-settings-manager.php 1 year ago class-wc-brands-coupons.php 1 year ago class-wc-brands.php 1 month ago class-wc-breadcrumb.php 4 months ago class-wc-cache-helper.php 1 month ago class-wc-cart-fees.php 2 years ago class-wc-cart-session.php 3 months ago class-wc-cart-totals.php 11 months ago class-wc-cart.php 1 month ago class-wc-checkout.php 1 month ago class-wc-cli.php 10 months ago class-wc-comments.php 4 months ago class-wc-countries.php 2 months ago class-wc-coupon.php 2 months ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 1 year ago class-wc-customer.php 2 days ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 3 years ago class-wc-datetime.php 4 years ago class-wc-deprecated-action-hooks.php 2 years ago class-wc-deprecated-filter-hooks.php 3 months ago class-wc-discounts.php 11 months ago class-wc-download-handler.php 1 month ago class-wc-emails.php 1 month ago class-wc-embed.php 1 year ago class-wc-form-handler.php 4 months ago class-wc-frontend-scripts.php 2 months ago class-wc-geo-ip.php 9 months ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 2 months ago class-wc-https.php 3 years ago class-wc-install.php 1 week ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 2 years ago class-wc-logger.php 4 months ago class-wc-meta-data.php 1 month ago class-wc-order-factory.php 2 months ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 5 months ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 1 month ago class-wc-order-item-shipping.php 5 months ago class-wc-order-item-tax.php 1 month ago class-wc-order-item.php 1 month ago class-wc-order-query.php 1 month ago class-wc-order-refund.php 1 year ago class-wc-order.php 1 month ago class-wc-payment-gateways.php 1 month ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 2 months ago class-wc-post-types.php 1 month ago class-wc-privacy-background-process.php 1 year ago class-wc-privacy-erasers.php 10 months ago class-wc-privacy-exporters.php 4 years ago class-wc-privacy.php 1 year ago class-wc-product-attribute.php 4 months ago class-wc-product-download.php 4 months ago class-wc-product-external.php 1 year ago class-wc-product-factory.php 3 months ago class-wc-product-grouped.php 3 months ago class-wc-product-query.php 4 months ago class-wc-product-simple.php 11 months ago class-wc-product-variable.php 1 month ago class-wc-product-variation.php 1 month ago class-wc-query.php 1 month ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 3 years ago class-wc-regenerate-images.php 2 years ago class-wc-register-wp-admin-settings.php 5 years ago class-wc-rest-authentication.php 2 years ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 3 months ago class-wc-shipping-rate.php 1 year ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 7 months ago class-wc-shipping.php 2 months ago class-wc-shortcodes.php 1 year ago class-wc-structured-data.php 1 month ago class-wc-tax.php 2 months ago class-wc-template-loader.php 7 months ago class-wc-tracker.php 1 month ago class-wc-validation.php 2 years ago class-wc-webhook.php 1 month ago class-woocommerce.php 2 days ago wc-account-functions.php 1 month ago wc-attribute-functions.php 1 month ago wc-brands-functions.php 1 year ago wc-cart-functions.php 1 month ago wc-conditional-functions.php 11 months ago wc-core-functions.php 2 months ago wc-coupon-functions.php 5 months ago wc-deprecated-functions.php 1 month ago wc-formatting-functions.php 1 month ago wc-interactivity-api-functions.php 2 months ago wc-notice-functions.php 5 months ago wc-order-functions.php 1 month ago wc-order-item-functions.php 3 years ago wc-order-step-logger-functions.php 4 months ago wc-page-functions.php 1 month ago wc-product-functions.php 2 months ago wc-rest-functions.php 7 months ago wc-stock-functions.php 7 months ago wc-template-functions.php 1 month ago wc-template-hooks.php 10 months ago wc-term-functions.php 2 months ago wc-update-functions.php 1 week ago wc-user-functions.php 1 month ago wc-webhook-functions.php 1 month ago wc-widget-functions.php 5 years ago
class-wc-breadcrumb.php
434 lines
1 <?php
2 /**
3 * WC_Breadcrumb class.
4 *
5 * @package WooCommerce\Classes
6 * @version 2.3.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * Breadcrumb class.
13 */
14 class WC_Breadcrumb {
15
16 /**
17 * Breadcrumb trail.
18 *
19 * @var array
20 */
21 protected $crumbs = array();
22
23 /**
24 * Add a crumb so we don't get lost.
25 *
26 * @param string $name Name.
27 * @param string $link Link.
28 * @return void
29 */
30 public function add_crumb( $name, $link = '' ) {
31 $this->crumbs[] = array(
32 wp_strip_all_tags( $name ),
33 $link,
34 );
35 }
36
37 /**
38 * Reset crumbs.
39 *
40 * @return void
41 */
42 public function reset() {
43 $this->crumbs = array();
44 }
45
46 /**
47 * Get the breadcrumb.
48 *
49 * @return array
50 */
51 public function get_breadcrumb() {
52 return apply_filters( 'woocommerce_get_breadcrumb', $this->crumbs, $this );
53 }
54
55 /**
56 * Generate breadcrumb trail.
57 *
58 * @return array of breadcrumbs
59 */
60 public function generate() {
61 $conditionals = array(
62 'is_home',
63 'is_404',
64 'is_attachment',
65 'is_single',
66 'is_product_category',
67 'is_product_tag',
68 'is_shop',
69 'is_page',
70 'is_post_type_archive',
71 'is_category',
72 'is_tag',
73 'is_author',
74 'is_date',
75 'is_tax',
76 );
77
78 if ( ( ! is_front_page() && ! ( is_post_type_archive() && intval( get_option( 'page_on_front' ) ) === wc_get_page_id( 'shop' ) ) ) || is_paged() ) {
79 foreach ( $conditionals as $conditional ) {
80 if ( call_user_func( $conditional ) ) {
81 call_user_func( array( $this, 'add_crumbs_' . substr( $conditional, 3 ) ) );
82 break;
83 }
84 }
85
86 $this->search_trail();
87 $this->paged_trail();
88
89 return $this->get_breadcrumb();
90 }
91
92 return array();
93 }
94
95 /**
96 * Prepend the shop page to shop breadcrumbs.
97 *
98 * @return void
99 */
100 protected function prepend_shop_page() {
101 $permalinks = wc_get_permalink_structure();
102 $shop_page_id = wc_get_page_id( 'shop' );
103 $shop_page = get_post( $shop_page_id );
104
105 // If permalinks contain the shop page in the URI prepend the breadcrumb with shop.
106 if ( $shop_page_id && $shop_page && isset( $permalinks['product_base'] ) && strstr( $permalinks['product_base'], '/' . $shop_page->post_name ) && intval( get_option( 'page_on_front' ) ) !== $shop_page_id ) {
107 $this->add_crumb( get_the_title( $shop_page ), get_permalink( $shop_page ) );
108 }
109 }
110
111 /**
112 * Is home trail..
113 *
114 * @return void
115 */
116 protected function add_crumbs_home() {
117 $this->add_crumb( single_post_title( '', false ) );
118 }
119
120 /**
121 * 404 trail.
122 *
123 * @return void
124 */
125 protected function add_crumbs_404() {
126 $this->add_crumb( __( 'Error 404', 'woocommerce' ) );
127 }
128
129 /**
130 * Attachment trail.
131 *
132 * @return void
133 */
134 protected function add_crumbs_attachment() {
135 global $post;
136
137 $this->add_crumbs_single( $post->post_parent, get_permalink( $post->post_parent ) );
138 $this->add_crumb( get_the_title(), get_permalink() );
139 }
140
141 /**
142 * Single post trail.
143 *
144 * @param int $post_id Post ID.
145 * @param string $permalink Post permalink.
146 * @return void
147 */
148 protected function add_crumbs_single( $post_id = 0, $permalink = '' ) {
149 if ( ! $post_id ) {
150 global $post;
151 } else {
152 $post = get_post( $post_id ); // WPCS: override ok.
153 }
154
155 if ( ! $permalink ) {
156 $permalink = get_permalink( $post );
157 }
158
159 if ( 'product' === get_post_type( $post ) ) {
160 $this->prepend_shop_page();
161
162 $terms = wc_get_product_terms(
163 $post->ID,
164 'product_cat',
165 apply_filters(
166 'woocommerce_breadcrumb_product_terms_args',
167 array(
168 'orderby' => 'parent',
169 'order' => 'DESC',
170 )
171 )
172 );
173
174 if ( $terms ) {
175 $main_term = apply_filters( 'woocommerce_breadcrumb_main_term', $terms[0], $terms );
176 $this->term_ancestors( $main_term->term_id, 'product_cat' );
177 $this->add_crumb( $main_term->name, get_term_link( $main_term ) );
178 }
179 } elseif ( 'post' !== get_post_type( $post ) ) {
180 $post_type = get_post_type_object( get_post_type( $post ) );
181
182 if ( ! empty( $post_type->has_archive ) ) {
183 $this->add_crumb( $post_type->labels->singular_name, get_post_type_archive_link( get_post_type( $post ) ) );
184 }
185 } else {
186 $cat = current( get_the_category( $post ) );
187 if ( $cat ) {
188 $this->term_ancestors( $cat->term_id, 'category' );
189 $this->add_crumb( $cat->name, get_term_link( $cat ) );
190 }
191 }
192
193 $this->add_crumb( get_the_title( $post ), $permalink );
194 }
195
196 /**
197 * Page trail.
198 *
199 * @return void
200 */
201 protected function add_crumbs_page() {
202 global $post;
203
204 if ( $post->post_parent ) {
205 $parent_crumbs = array();
206 $parent_id = $post->post_parent;
207
208 while ( $parent_id ) {
209 $page = get_post( $parent_id );
210 $parent_id = $page->post_parent;
211 $parent_crumbs[] = array( get_the_title( $page->ID ), get_permalink( $page->ID ) );
212 }
213
214 $parent_crumbs = array_reverse( $parent_crumbs );
215
216 foreach ( $parent_crumbs as $crumb ) {
217 $this->add_crumb( $crumb[0], $crumb[1] );
218 }
219 }
220
221 // On WC endpoints, get_the_title() returns the endpoint title (via wc_page_endpoint_title filter).
222 // Use post_title directly to avoid duplicates like "Orders / Orders" instead of "My Account / Orders".
223 $permalink = get_permalink();
224 if ( is_wc_endpoint_url() ) {
225 $this->add_crumb( $post->post_title, $permalink ? $permalink : '' );
226 } else {
227 $this->add_crumb( get_the_title(), $permalink ? $permalink : '' );
228 }
229
230 $this->endpoint_trail();
231 }
232
233 /**
234 * Product category trail.
235 *
236 * @return void
237 */
238 protected function add_crumbs_product_category() {
239 $current_term = $GLOBALS['wp_query']->get_queried_object();
240
241 $this->prepend_shop_page();
242 $this->term_ancestors( $current_term->term_id, 'product_cat' );
243 $this->add_crumb( $current_term->name, get_term_link( $current_term, 'product_cat' ) );
244 }
245
246 /**
247 * Product tag trail.
248 *
249 * @return void
250 */
251 protected function add_crumbs_product_tag() {
252 $current_term = $GLOBALS['wp_query']->get_queried_object();
253
254 $this->prepend_shop_page();
255
256 /* translators: %s: product tag */
257 $this->add_crumb( sprintf( __( 'Products tagged &ldquo;%s&rdquo;', 'woocommerce' ), $current_term->name ), get_term_link( $current_term, 'product_tag' ) );
258 }
259
260 /**
261 * Shop breadcrumb.
262 *
263 * @return void
264 */
265 protected function add_crumbs_shop() {
266 if ( intval( get_option( 'page_on_front' ) ) === wc_get_page_id( 'shop' ) ) {
267 return;
268 }
269
270 $_name = wc_get_page_id( 'shop' ) ? get_the_title( wc_get_page_id( 'shop' ) ) : '';
271
272 if ( ! $_name ) {
273 $product_post_type = get_post_type_object( 'product' );
274 $_name = $product_post_type->labels->name;
275 }
276
277 $this->add_crumb( $_name, get_post_type_archive_link( 'product' ) );
278 }
279
280 /**
281 * Post type archive trail.
282 *
283 * @return void
284 */
285 protected function add_crumbs_post_type_archive() {
286 $post_type = get_post_type_object( get_post_type() );
287
288 if ( $post_type ) {
289 $this->add_crumb( $post_type->labels->name, get_post_type_archive_link( get_post_type() ) );
290 }
291 }
292
293 /**
294 * Category trail.
295 *
296 * @return void
297 */
298 protected function add_crumbs_category() {
299 $this_category = get_category( $GLOBALS['wp_query']->get_queried_object() );
300
301 if ( is_wp_error( $this_category ) || ! $this_category ) {
302 return;
303 }
304
305 if ( 0 !== intval( $this_category->parent ) ) {
306 $this->term_ancestors( $this_category->term_id, 'category' );
307 }
308
309 $this->add_crumb( single_cat_title( '', false ), get_category_link( $this_category->term_id ) );
310 }
311
312 /**
313 * Tag trail.
314 *
315 * @return void
316 */
317 protected function add_crumbs_tag() {
318 $queried_object = $GLOBALS['wp_query']->get_queried_object();
319
320 /* translators: %s: tag name */
321 $this->add_crumb( sprintf( __( 'Posts tagged &ldquo;%s&rdquo;', 'woocommerce' ), single_tag_title( '', false ) ), get_tag_link( $queried_object->term_id ) );
322 }
323
324 /**
325 * Add crumbs for date based archives.
326 *
327 * @return void
328 */
329 protected function add_crumbs_date() {
330 if ( is_year() || is_month() || is_day() ) {
331 $this->add_crumb( get_the_time( 'Y' ), get_year_link( get_the_time( 'Y' ) ) );
332 }
333 if ( is_month() || is_day() ) {
334 $this->add_crumb( get_the_time( 'F' ), get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) );
335 }
336 if ( is_day() ) {
337 $this->add_crumb( get_the_time( 'd' ) );
338 }
339 }
340
341 /**
342 * Add crumbs for taxonomies.
343 *
344 * @return void
345 */
346 protected function add_crumbs_tax() {
347 $this_term = $GLOBALS['wp_query']->get_queried_object();
348 $taxonomy = get_taxonomy( $this_term->taxonomy );
349
350 if ( 'product_brand' !== $this_term->taxonomy ) {
351 $this->add_crumb( $taxonomy->labels->name );
352 }
353
354 if ( 0 !== intval( $this_term->parent ) ) {
355 $this->term_ancestors( $this_term->term_id, $this_term->taxonomy );
356 }
357
358 $this->add_crumb( single_term_title( '', false ), get_term_link( $this_term->term_id, $this_term->taxonomy ) );
359 }
360
361 /**
362 * Add a breadcrumb for author archives.
363 *
364 * @return void
365 */
366 protected function add_crumbs_author() {
367 global $author;
368
369 $userdata = get_userdata( $author );
370
371 /* translators: %s: author name */
372 $this->add_crumb( sprintf( __( 'Author: %s', 'woocommerce' ), $userdata->display_name ) );
373 }
374
375 /**
376 * Add crumbs for a term.
377 *
378 * @param int $term_id Term ID.
379 * @param string $taxonomy Taxonomy.
380 * @return void
381 */
382 protected function term_ancestors( $term_id, $taxonomy ) {
383 $ancestors = get_ancestors( $term_id, $taxonomy );
384 $ancestors = array_reverse( $ancestors );
385
386 foreach ( $ancestors as $ancestor ) {
387 $ancestor = get_term( $ancestor, $taxonomy );
388
389 if ( ! is_wp_error( $ancestor ) && $ancestor ) {
390 $this->add_crumb( $ancestor->name, get_term_link( $ancestor ) );
391 }
392 }
393 }
394
395 /**
396 * Endpoints.
397 *
398 * @return void
399 */
400 protected function endpoint_trail() {
401 $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
402 $endpoint = is_wc_endpoint_url() ? WC()->query->get_current_endpoint() : '';
403 $endpoint_title = $endpoint ? WC()->query->get_endpoint_title( $endpoint, $action ) : '';
404
405 if ( $endpoint_title ) {
406 $this->add_crumb( $endpoint_title );
407 }
408 }
409
410 /**
411 * Add a breadcrumb for search results.
412 *
413 * @return void
414 */
415 protected function search_trail() {
416 if ( is_search() ) {
417 /* translators: %s: search term */
418 $this->add_crumb( sprintf( __( 'Search results for &ldquo;%s&rdquo;', 'woocommerce' ), get_search_query() ), remove_query_arg( 'paged' ) );
419 }
420 }
421
422 /**
423 * Add a breadcrumb for pagination.
424 *
425 * @return void
426 */
427 protected function paged_trail() {
428 if ( get_query_var( 'paged' ) && 'subcategories' !== woocommerce_get_loop_display_mode() ) {
429 /* translators: %d: page number */
430 $this->add_crumb( sprintf( __( 'Page %d', 'woocommerce' ), get_query_var( 'paged' ) ) );
431 }
432 }
433 }
434