PluginProbe
Filter Everything — WordPress & WooCommerce Filters / 1.9.7
Filter Everything — WordPress & WooCommerce Filters v1.9.7
1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2.2 1.9.2.1 trunk 1.2.1 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.1 1.4.4 1.4.5 1.4.8 1.4.9 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 All 52 releases
← All changes | src/wpc-utility-functions.php +81 -3 1.9.2.11.9.7 View file →
@@ -138,9 +138,9 @@
138 138 $link = pll_home_url($lang);
139 139 }
140 140 }else{
141 141 $translated_post_types = PLL()->model->get_translated_post_types();
142 - if( isset( $translated_post_types[ $postType ] ) ){
142 + if ( array_key_exists( $postType, $translated_post_types ) || in_array( $postType, $translated_post_types, true ) ){
143 143 $link = PLL()->links_model->switch_language_in_link( $link, $pll_language );
144 144 }
145 145 }
146 146 }
@@ -184,9 +184,9 @@
184 184 // In case of Polylang plugin
185 185 $home_url = trailingslashit( get_bloginfo('url') );
186 186 if( function_exists('pll_home_url') ){
187 187 $translated_post_types = PLL()->model->get_translated_post_types();
188 - if( isset( $translated_post_types[$postType] ) ){
188 + if ( array_key_exists( $postType, $translated_post_types ) || in_array( $postType, $translated_post_types, true ) ){
189 189 $home_url = trailingslashit( pll_home_url($lang) );
190 190 }
191 191 }
192 192
@@ -202,9 +202,9 @@
202 202 $shop_permalink = get_permalink( $shop_page_id );
203 203
204 204 if( function_exists('pll_home_url') ){
205 205 $translated_post_types = PLL()->model->get_translated_post_types();
206 - if( isset( $translated_post_types['product'] ) ){
206 + if ( array_key_exists( 'product', $translated_post_types ) || in_array( 'product', $translated_post_types, true ) ){
207 207 $shop_permalink = PLL()->links_model->switch_language_in_link( $shop_permalink, $pll_language );
208 208 }
209 209 }
210 210
@@ -289,8 +289,16 @@
289 289 'fields' => 'id=>name'
290 290 );
291 291
292 292 $terms = get_terms( $args );
293 +
294 + // The taxonomy may be unavailable (e.g. WooCommerce deactivated while a
295 + // Filter Set still targets product_cat) — get_terms() then returns a
296 + // WP_Error. Treat it as "no terms" so it never propagates to filters as an array.
297 + if ( is_wp_error( $terms ) ) {
298 + $terms = array();
299 + }
300 +
293 301 $taxonomyObject = get_taxonomy( $taxonomy );
294 302
295 303 $label = isset( $taxonomyObject->labels->singular_name ) ? $taxonomyObject->labels->singular_name : flrt_ucfirst( $taxonomy );
296 304
@@ -384,5 +392,75 @@
384 392 'data-link' => ''
385 393 );
386 394
387 395 return $fields;
396 +}
397 +
398 +function flrt_filter_set_front_link($post_id)
399 +{
400 + $fss = Container::instance()->getFilterSetService();
401 + $set_settings_fields = $fss->getSettingsLocationTypeFields($post_id);
402 + $link = '';
403 + foreach ($set_settings_fields as $key => $attributes) {
404 + if ($attributes['id'] == $fss->generateFieldId('post_name')) {
405 + $current_index = isset($attributes['value']) ? $attributes['value'] : '';
406 + $options = !empty($attributes['options']) ? $attributes['options'] : [];
407 + if (isset($options[$current_index]['data-link'])) {
408 + $link = esc_attr($options[$current_index]['data-link']);
409 + }
410 + }
411 + }
412 + return $link;
413 +}
414 +
415 +/**
416 + * Front page URL for the «Select visually» container picker: the page where
417 + * the user's most likely Filter Set actually filters. Candidates in order:
418 + * a WooCommerce product Set, a post Set, any other (CPT) Set — the higher
419 + * Priority (menu_order) Set first within each group. With no resolvable Set
420 + * at all: the shop page on WooCommerce sites, the blog page otherwise.
421 + */
422 +function flrt_default_selector_page_link()
423 +{
424 + $sets = get_posts( array(
425 + 'post_type' => FLRT_FILTERS_SET_POST_TYPE,
426 + 'post_status' => 'publish',
427 + 'numberposts' => -1,
428 + 'orderby' => array( 'menu_order' => 'DESC', 'date' => 'ASC' ),
429 + ) );
430 +
431 + $woo = function_exists( 'wc_get_page_permalink' );
432 +
433 + $candidates = array( 'product' => array(), 'post' => array(), 'other' => array() );
434 + foreach ( $sets as $set ) {
435 + // Sets keep their filtered post type in post_excerpt; empty means 'post'
436 + $type = $set->post_excerpt ? $set->post_excerpt : 'post';
437 + if ( $type === 'product' && $woo ) {
438 + $candidates['product'][] = $set->ID;
439 + } elseif ( $type === 'post' ) {
440 + $candidates['post'][] = $set->ID;
441 + } else {
442 + // Without WooCommerce 'product' is just another CPT
443 + $candidates['other'][] = $set->ID;
444 + }
445 + }
446 +
447 + foreach ( array_merge( $candidates['product'], $candidates['post'], $candidates['other'] ) as $set_id ) {
448 + $link = flrt_filter_set_front_link( $set_id );
449 + if ( ! empty( $link ) ) {
450 + return $link;
451 + }
452 + }
453 +
454 + if ( $woo ) {
455 + $link = wc_get_page_permalink( 'shop' );
456 + if ( ! empty( $link ) ) {
457 + return $link;
458 + }
459 + }
460 +
461 + // get_post_type_archive_link('post') is false when the front page is
462 + // static and no posts page is assigned
463 + $link = get_post_type_archive_link( 'post' );
464 +
465 + return $link ? $link : home_url( '/' );
388 466 }