From 0a7a0c1090d689b1d2fb08bfd03f397402779368 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Mon, 17 Jan 2022 23:29:52 -0600 Subject: [PATCH 01/12] Determine if there is an existing taxonomy query before facets inject one. --- includes/classes/Feature/Facets/Facets.php | 31 +++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/includes/classes/Feature/Facets/Facets.php b/includes/classes/Feature/Facets/Facets.php index ca732ebb4f..9ff22e0b80 100644 --- a/includes/classes/Feature/Facets/Facets.php +++ b/includes/classes/Feature/Facets/Facets.php @@ -324,12 +324,15 @@ public function facet_query( $query ) { } foreach ( $selected_filters['taxonomies'] as $taxonomy => $filter ) { - $tax_query[] = [ - 'taxonomy' => isset( $attribute_taxonomies[ $taxonomy ] ) ? $attribute_taxonomies[ $taxonomy ] : $taxonomy, - 'field' => 'slug', - 'terms' => array_keys( $filter['terms'] ), - 'operator' => ( 'any' === $settings['match_type'] ) ? 'or' : 'and', - ]; + $tax = isset( $attribute_taxonomies[ $taxonomy ] ) ? $attribute_taxonomies[ $taxonomy ] : $taxonomy; + if ( ! $this->has_taxonomy_query( $tax_query, $tax ) ) { + $tax_query[] = [ + 'taxonomy' => $tax, + 'field' => 'slug', + 'terms' => array_keys( $filter['terms'] ), + 'operator' => ( 'any' === $settings['match_type'] ) ? 'or' : 'and', + ]; + } } if ( ! empty( $selected_filters['taxonomies'] ) && 'any' === $settings['match_type'] ) { @@ -339,6 +342,22 @@ public function facet_query( $query ) { $query->set( 'tax_query', $tax_query ); } + /** + * Determine if we have a taxonomy query before attempting to add a new one for each filter. + * + * @param $tax_query array The current tax_query. + * @param $taxonomy string WP Taxonomy. + * @return bool true or false. + */ + function has_taxonomy_query( $tax_query, $taxonomy ) { + foreach ( $tax_query as $query ) { + if ( is_array( $query ) && $taxonomy === $query['taxonomy'] ) { + return true; + } + } + return false; + } + /** * Hacky. Save aggregation data for later in a global * From 7df736d78c40cb56a7080006d416ce2f8370bea9 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Tue, 18 Jan 2022 00:31:48 -0600 Subject: [PATCH 02/12] Change function name --- includes/classes/Feature/Facets/Facets.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/classes/Feature/Facets/Facets.php b/includes/classes/Feature/Facets/Facets.php index 9ff22e0b80..d3c5a027b7 100644 --- a/includes/classes/Feature/Facets/Facets.php +++ b/includes/classes/Feature/Facets/Facets.php @@ -325,7 +325,7 @@ public function facet_query( $query ) { foreach ( $selected_filters['taxonomies'] as $taxonomy => $filter ) { $tax = isset( $attribute_taxonomies[ $taxonomy ] ) ? $attribute_taxonomies[ $taxonomy ] : $taxonomy; - if ( ! $this->has_taxonomy_query( $tax_query, $tax ) ) { + if ( ! $this->has_pre_existing_taxonomy_query( $tax_query, $tax ) ) { $tax_query[] = [ 'taxonomy' => $tax, 'field' => 'slug', @@ -343,13 +343,13 @@ public function facet_query( $query ) { } /** - * Determine if we have a taxonomy query before attempting to add a new one for each filter. + * Determine if we already have a taxonomy query before attempting to add a new one for each filter. * * @param $tax_query array The current tax_query. * @param $taxonomy string WP Taxonomy. * @return bool true or false. */ - function has_taxonomy_query( $tax_query, $taxonomy ) { + function has_pre_existing_taxonomy_query( $tax_query, $taxonomy ) { foreach ( $tax_query as $query ) { if ( is_array( $query ) && $taxonomy === $query['taxonomy'] ) { return true; From c4ab614691f7fb33d232dea339b1fef2690e5081 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Wed, 19 Jan 2022 09:51:41 -0600 Subject: [PATCH 03/12] Lint fixes --- includes/classes/Feature/Facets/Facets.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/classes/Feature/Facets/Facets.php b/includes/classes/Feature/Facets/Facets.php index d3c5a027b7..e7ba3fe848 100644 --- a/includes/classes/Feature/Facets/Facets.php +++ b/includes/classes/Feature/Facets/Facets.php @@ -345,11 +345,11 @@ public function facet_query( $query ) { /** * Determine if we already have a taxonomy query before attempting to add a new one for each filter. * - * @param $tax_query array The current tax_query. - * @param $taxonomy string WP Taxonomy. + * @param array $tax_query The current tax_query. + * @param string $taxonomy WP Taxonomy. * @return bool true or false. */ - function has_pre_existing_taxonomy_query( $tax_query, $taxonomy ) { + public function has_pre_existing_taxonomy_query( $tax_query, $taxonomy ) { foreach ( $tax_query as $query ) { if ( is_array( $query ) && $taxonomy === $query['taxonomy'] ) { return true; From a5cc89840a7ac43937d70577f68967b2c16cd3cf Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Tue, 15 Feb 2022 11:29:21 -0600 Subject: [PATCH 04/12] Revert "Lint fixes" This reverts commit c4ab614691f7fb33d232dea339b1fef2690e5081. --- includes/classes/Feature/Facets/Facets.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/classes/Feature/Facets/Facets.php b/includes/classes/Feature/Facets/Facets.php index e7ba3fe848..d3c5a027b7 100644 --- a/includes/classes/Feature/Facets/Facets.php +++ b/includes/classes/Feature/Facets/Facets.php @@ -345,11 +345,11 @@ public function facet_query( $query ) { /** * Determine if we already have a taxonomy query before attempting to add a new one for each filter. * - * @param array $tax_query The current tax_query. - * @param string $taxonomy WP Taxonomy. + * @param $tax_query array The current tax_query. + * @param $taxonomy string WP Taxonomy. * @return bool true or false. */ - public function has_pre_existing_taxonomy_query( $tax_query, $taxonomy ) { + function has_pre_existing_taxonomy_query( $tax_query, $taxonomy ) { foreach ( $tax_query as $query ) { if ( is_array( $query ) && $taxonomy === $query['taxonomy'] ) { return true; From 0c5848a7ccdc1b6fc3a922be96b1194c10ea34b2 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Tue, 15 Feb 2022 11:29:30 -0600 Subject: [PATCH 05/12] Revert "Change function name" This reverts commit 7df736d78c40cb56a7080006d416ce2f8370bea9. --- includes/classes/Feature/Facets/Facets.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/classes/Feature/Facets/Facets.php b/includes/classes/Feature/Facets/Facets.php index d3c5a027b7..9ff22e0b80 100644 --- a/includes/classes/Feature/Facets/Facets.php +++ b/includes/classes/Feature/Facets/Facets.php @@ -325,7 +325,7 @@ public function facet_query( $query ) { foreach ( $selected_filters['taxonomies'] as $taxonomy => $filter ) { $tax = isset( $attribute_taxonomies[ $taxonomy ] ) ? $attribute_taxonomies[ $taxonomy ] : $taxonomy; - if ( ! $this->has_pre_existing_taxonomy_query( $tax_query, $tax ) ) { + if ( ! $this->has_taxonomy_query( $tax_query, $tax ) ) { $tax_query[] = [ 'taxonomy' => $tax, 'field' => 'slug', @@ -343,13 +343,13 @@ public function facet_query( $query ) { } /** - * Determine if we already have a taxonomy query before attempting to add a new one for each filter. + * Determine if we have a taxonomy query before attempting to add a new one for each filter. * * @param $tax_query array The current tax_query. * @param $taxonomy string WP Taxonomy. * @return bool true or false. */ - function has_pre_existing_taxonomy_query( $tax_query, $taxonomy ) { + function has_taxonomy_query( $tax_query, $taxonomy ) { foreach ( $tax_query as $query ) { if ( is_array( $query ) && $taxonomy === $query['taxonomy'] ) { return true; From 4c3e27a3e976d73ceb3ea68ecf2be5000d669284 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Tue, 15 Feb 2022 11:29:39 -0600 Subject: [PATCH 06/12] Revert "Determine if there is an existing taxonomy query before facets inject one." This reverts commit 0a7a0c1090d689b1d2fb08bfd03f397402779368. --- includes/classes/Feature/Facets/Facets.php | 31 +++++----------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/includes/classes/Feature/Facets/Facets.php b/includes/classes/Feature/Facets/Facets.php index 9ff22e0b80..ca732ebb4f 100644 --- a/includes/classes/Feature/Facets/Facets.php +++ b/includes/classes/Feature/Facets/Facets.php @@ -324,15 +324,12 @@ public function facet_query( $query ) { } foreach ( $selected_filters['taxonomies'] as $taxonomy => $filter ) { - $tax = isset( $attribute_taxonomies[ $taxonomy ] ) ? $attribute_taxonomies[ $taxonomy ] : $taxonomy; - if ( ! $this->has_taxonomy_query( $tax_query, $tax ) ) { - $tax_query[] = [ - 'taxonomy' => $tax, - 'field' => 'slug', - 'terms' => array_keys( $filter['terms'] ), - 'operator' => ( 'any' === $settings['match_type'] ) ? 'or' : 'and', - ]; - } + $tax_query[] = [ + 'taxonomy' => isset( $attribute_taxonomies[ $taxonomy ] ) ? $attribute_taxonomies[ $taxonomy ] : $taxonomy, + 'field' => 'slug', + 'terms' => array_keys( $filter['terms'] ), + 'operator' => ( 'any' === $settings['match_type'] ) ? 'or' : 'and', + ]; } if ( ! empty( $selected_filters['taxonomies'] ) && 'any' === $settings['match_type'] ) { @@ -342,22 +339,6 @@ public function facet_query( $query ) { $query->set( 'tax_query', $tax_query ); } - /** - * Determine if we have a taxonomy query before attempting to add a new one for each filter. - * - * @param $tax_query array The current tax_query. - * @param $taxonomy string WP Taxonomy. - * @return bool true or false. - */ - function has_taxonomy_query( $tax_query, $taxonomy ) { - foreach ( $tax_query as $query ) { - if ( is_array( $query ) && $taxonomy === $query['taxonomy'] ) { - return true; - } - } - return false; - } - /** * Hacky. Save aggregation data for later in a global * From 2c1326c97ea9df0fcb158dd444c4bc736adfc4a6 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Tue, 15 Feb 2022 11:34:15 -0600 Subject: [PATCH 07/12] Change filter name to filterable EP identifier --- includes/classes/Feature/Facets/Facets.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/includes/classes/Feature/Facets/Facets.php b/includes/classes/Feature/Facets/Facets.php index ca732ebb4f..858c6690fe 100644 --- a/includes/classes/Feature/Facets/Facets.php +++ b/includes/classes/Feature/Facets/Facets.php @@ -391,9 +391,18 @@ public function get_selected() { $allowed_args = $this->get_allowed_query_args(); + /** + * Filter the facet filter name that's added to the URL + * + * @hook ep_facet_filter_name + * @param {string} Facet filter name + * @return {string} New facet filter name + */ + $filter_name = apply_filters( 'ep_facet_filter_name', 'ep_filter_' ); + foreach ( $_GET as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification if ( 0 === strpos( $key, 'filter_' ) ) { - $taxonomy = str_replace( 'filter_', '', $key ); + $taxonomy = str_replace( $filter_name, '', $key ); $filters['taxonomies'][ $taxonomy ] = array( 'terms' => array_fill_keys( array_map( 'trim', explode( ',', trim( $value, ',' ) ) ), true ), @@ -418,12 +427,21 @@ public function get_selected() { public function build_query_url( $filters ) { $query_param = array(); + /** + * Filter the facet filter name that's added to the URL + * + * @hook ep_facet_filter_name + * @param {string} Facet filter name + * @return {string} New facet filter name + */ + $filter_name = apply_filters( 'ep_facet_filter_name', 'ep_filter_' ); + if ( ! empty( $filters['taxonomies'] ) ) { $tax_filters = $filters['taxonomies']; foreach ( $tax_filters as $taxonomy => $filter ) { if ( ! empty( $filter['terms'] ) ) { - $query_param[ 'filter_' . $taxonomy ] = implode( ',', array_keys( $filter['terms'] ) ); + $query_param[ $filter_name . $taxonomy ] = implode( ',', array_keys( $filter['terms'] ) ); } } } From 19176b212e06b22a882d0268aa55d730db2925a2 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Mon, 21 Feb 2022 14:42:18 -0600 Subject: [PATCH 08/12] Account for filter change in unit tests --- tests/php/features/TestFacet.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/php/features/TestFacet.php b/tests/php/features/TestFacet.php index bb24bb273f..93dba823f8 100644 --- a/tests/php/features/TestFacet.php +++ b/tests/php/features/TestFacet.php @@ -43,15 +43,15 @@ public function tearDown() { public function testGetSelected() { $facet_feature = Features::factory()->get_registered_feature( 'facets' ); - parse_str( 'filter_taxonomy=dolor', $_GET ); + parse_str( 'ep_filter_taxonomy=dolor', $_GET ); $selected = $facet_feature->get_selected(); $this->assertSelectedTax( [ 'dolor' => true ], 'taxonomy', $selected ); - parse_str( 'filter_taxonomy=dolor,sit', $_GET ); + parse_str( 'ep_filter_taxonomy=dolor,sit', $_GET ); $selected = $facet_feature->get_selected(); $this->assertSelectedTax( [ 'dolor' => true, 'sit' => true ], 'taxonomy', $selected ); - parse_str( 'filter_taxonomy=dolor,sit&filter_othertax=amet', $_GET ); + parse_str( 'ep_filter_taxonomy=dolor,sit&ep_filter_othertax=amet', $_GET ); $selected = $facet_feature->get_selected(); $this->assertIsArray( $selected ); @@ -62,13 +62,13 @@ public function testGetSelected() { $this->assertSame( [ 'dolor' => true, 'sit' => true ], $selected['taxonomies']['taxonomy']['terms'] ); $this->assertSame( [ 'amet' => true ], $selected['taxonomies']['othertax']['terms'] ); - parse_str( 's=searchterm&filter_taxonomy=dolor', $_GET ); + parse_str( 's=searchterm&ep_filter_taxonomy=dolor', $_GET ); $selected = $facet_feature->get_selected(); $this->assertSelectedTax( [ 'dolor' => true ], 'taxonomy', $selected ); $this->assertArrayHasKey( 's', $selected ); $this->assertSame( 'searchterm', $selected['s'] ); - parse_str( 'post_type=posttype&filter_taxonomy=dolor', $_GET ); + parse_str( 'post_type=posttype&ep_filter_taxonomy=dolor', $_GET ); $selected = $facet_feature->get_selected(); $this->assertSelectedTax( [ 'dolor' => true ], 'taxonomy', $selected ); $this->assertArrayHasKey( 'post_type', $selected ); @@ -95,10 +95,10 @@ public function testBuildQueryUrl() { ] ]; - $this->assertEquals( '/?filter_category=augue', $facet_feature->build_query_url( $filters ) ); + $this->assertEquals( '/?ep_filter_category=augue', $facet_feature->build_query_url( $filters ) ); $filters['s'] = 'dolor'; - $this->assertEquals( '/?filter_category=augue&s=dolor', $facet_feature->build_query_url( $filters ) ); + $this->assertEquals( '/?ep_filter_category=augue&s=dolor', $facet_feature->build_query_url( $filters ) ); unset( $filters['s'] ); $filters = [ @@ -112,12 +112,12 @@ public function testBuildQueryUrl() { ] ]; - $this->assertEquals( '/?filter_category=augue%2Cconsectetur', $facet_feature->build_query_url( $filters ) ); + $this->assertEquals( '/?ep_filter_category=augue%2Cconsectetur', $facet_feature->build_query_url( $filters ) ); $_SERVER['REQUEST_URI'] = 'test/page/1'; $filters['s'] = 'dolor'; - $this->assertEquals( 'test/?filter_category=augue%2Cconsectetur&s=dolor', $facet_feature->build_query_url( $filters ) ); + $this->assertEquals( 'test/?ep_filter_category=augue%2Cconsectetur&s=dolor', $facet_feature->build_query_url( $filters ) ); } /** From d52de3391ec4ce023592619b37b13b7f81de2a6a Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Mon, 21 Feb 2022 14:50:44 -0600 Subject: [PATCH 09/12] Change filter name --- tests/php/features/TestFacet.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/php/features/TestFacet.php b/tests/php/features/TestFacet.php index 93dba823f8..265841d72a 100644 --- a/tests/php/features/TestFacet.php +++ b/tests/php/features/TestFacet.php @@ -43,15 +43,15 @@ public function tearDown() { public function testGetSelected() { $facet_feature = Features::factory()->get_registered_feature( 'facets' ); - parse_str( 'ep_filter_taxonomy=dolor', $_GET ); + parse_str( 'filter_taxonomy=dolor', $_GET ); $selected = $facet_feature->get_selected(); $this->assertSelectedTax( [ 'dolor' => true ], 'taxonomy', $selected ); - parse_str( 'ep_filter_taxonomy=dolor,sit', $_GET ); + parse_str( 'filter_taxonomy=dolor,sit', $_GET ); $selected = $facet_feature->get_selected(); $this->assertSelectedTax( [ 'dolor' => true, 'sit' => true ], 'taxonomy', $selected ); - parse_str( 'ep_filter_taxonomy=dolor,sit&ep_filter_othertax=amet', $_GET ); + parse_str( 'filter_taxonomy=dolor,sit&filter_othertax=amet', $_GET ); $selected = $facet_feature->get_selected(); $this->assertIsArray( $selected ); @@ -62,13 +62,13 @@ public function testGetSelected() { $this->assertSame( [ 'dolor' => true, 'sit' => true ], $selected['taxonomies']['taxonomy']['terms'] ); $this->assertSame( [ 'amet' => true ], $selected['taxonomies']['othertax']['terms'] ); - parse_str( 's=searchterm&ep_filter_taxonomy=dolor', $_GET ); + parse_str( 's=searchterm&filter_taxonomy=dolor', $_GET ); $selected = $facet_feature->get_selected(); $this->assertSelectedTax( [ 'dolor' => true ], 'taxonomy', $selected ); $this->assertArrayHasKey( 's', $selected ); $this->assertSame( 'searchterm', $selected['s'] ); - parse_str( 'post_type=posttype&ep_filter_taxonomy=dolor', $_GET ); + parse_str( 'post_type=posttype&filter_taxonomy=dolor', $_GET ); $selected = $facet_feature->get_selected(); $this->assertSelectedTax( [ 'dolor' => true ], 'taxonomy', $selected ); $this->assertArrayHasKey( 'post_type', $selected ); From ebe77f83ec77e12da75d6199d3922d93670f5210 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Mon, 21 Feb 2022 15:05:56 -0600 Subject: [PATCH 10/12] Fix unit tests --- includes/classes/Feature/Facets/Facets.php | 4 ++-- tests/php/features/TestFacet.php | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/classes/Feature/Facets/Facets.php b/includes/classes/Feature/Facets/Facets.php index 858c6690fe..5af46ce46d 100644 --- a/includes/classes/Feature/Facets/Facets.php +++ b/includes/classes/Feature/Facets/Facets.php @@ -401,8 +401,8 @@ public function get_selected() { $filter_name = apply_filters( 'ep_facet_filter_name', 'ep_filter_' ); foreach ( $_GET as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification - if ( 0 === strpos( $key, 'filter_' ) ) { - $taxonomy = str_replace( $filter_name, '', $key ); + if ( 0 === strpos( $key, $filter_name ) ) { + $taxonomy = str_replace( $filter_name , '', $key ); $filters['taxonomies'][ $taxonomy ] = array( 'terms' => array_fill_keys( array_map( 'trim', explode( ',', trim( $value, ',' ) ) ), true ), diff --git a/tests/php/features/TestFacet.php b/tests/php/features/TestFacet.php index 265841d72a..93dba823f8 100644 --- a/tests/php/features/TestFacet.php +++ b/tests/php/features/TestFacet.php @@ -43,15 +43,15 @@ public function tearDown() { public function testGetSelected() { $facet_feature = Features::factory()->get_registered_feature( 'facets' ); - parse_str( 'filter_taxonomy=dolor', $_GET ); + parse_str( 'ep_filter_taxonomy=dolor', $_GET ); $selected = $facet_feature->get_selected(); $this->assertSelectedTax( [ 'dolor' => true ], 'taxonomy', $selected ); - parse_str( 'filter_taxonomy=dolor,sit', $_GET ); + parse_str( 'ep_filter_taxonomy=dolor,sit', $_GET ); $selected = $facet_feature->get_selected(); $this->assertSelectedTax( [ 'dolor' => true, 'sit' => true ], 'taxonomy', $selected ); - parse_str( 'filter_taxonomy=dolor,sit&filter_othertax=amet', $_GET ); + parse_str( 'ep_filter_taxonomy=dolor,sit&ep_filter_othertax=amet', $_GET ); $selected = $facet_feature->get_selected(); $this->assertIsArray( $selected ); @@ -62,13 +62,13 @@ public function testGetSelected() { $this->assertSame( [ 'dolor' => true, 'sit' => true ], $selected['taxonomies']['taxonomy']['terms'] ); $this->assertSame( [ 'amet' => true ], $selected['taxonomies']['othertax']['terms'] ); - parse_str( 's=searchterm&filter_taxonomy=dolor', $_GET ); + parse_str( 's=searchterm&ep_filter_taxonomy=dolor', $_GET ); $selected = $facet_feature->get_selected(); $this->assertSelectedTax( [ 'dolor' => true ], 'taxonomy', $selected ); $this->assertArrayHasKey( 's', $selected ); $this->assertSame( 'searchterm', $selected['s'] ); - parse_str( 'post_type=posttype&filter_taxonomy=dolor', $_GET ); + parse_str( 'post_type=posttype&ep_filter_taxonomy=dolor', $_GET ); $selected = $facet_feature->get_selected(); $this->assertSelectedTax( [ 'dolor' => true ], 'taxonomy', $selected ); $this->assertArrayHasKey( 'post_type', $selected ); From ca5063c9b4d0696c1a43062f1e1275c9578a6152 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Mon, 21 Feb 2022 15:24:20 -0600 Subject: [PATCH 11/12] Fix linting --- includes/classes/Feature/Facets/Facets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/Feature/Facets/Facets.php b/includes/classes/Feature/Facets/Facets.php index 5af46ce46d..ab8f81f59c 100644 --- a/includes/classes/Feature/Facets/Facets.php +++ b/includes/classes/Feature/Facets/Facets.php @@ -402,7 +402,7 @@ public function get_selected() { foreach ( $_GET as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification if ( 0 === strpos( $key, $filter_name ) ) { - $taxonomy = str_replace( $filter_name , '', $key ); + $taxonomy = str_replace( $filter_name, '', $key ); $filters['taxonomies'][ $taxonomy ] = array( 'terms' => array_fill_keys( array_map( 'trim', explode( ',', trim( $value, ',' ) ) ), true ), From 1f082cbea61f778d7f2cdc9a5eba03c2418e73fc Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Mon, 21 Feb 2022 18:36:02 -0600 Subject: [PATCH 12/12] Unify filter into get_filter_name() method --- includes/classes/Feature/Facets/Facets.php | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/includes/classes/Feature/Facets/Facets.php b/includes/classes/Feature/Facets/Facets.php index ab8f81f59c..560457e3d6 100644 --- a/includes/classes/Feature/Facets/Facets.php +++ b/includes/classes/Feature/Facets/Facets.php @@ -390,15 +390,7 @@ public function get_selected() { ); $allowed_args = $this->get_allowed_query_args(); - - /** - * Filter the facet filter name that's added to the URL - * - * @hook ep_facet_filter_name - * @param {string} Facet filter name - * @return {string} New facet filter name - */ - $filter_name = apply_filters( 'ep_facet_filter_name', 'ep_filter_' ); + $filter_name = $this->get_filter_name(); foreach ( $_GET as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification if ( 0 === strpos( $key, $filter_name ) ) { @@ -427,21 +419,12 @@ public function get_selected() { public function build_query_url( $filters ) { $query_param = array(); - /** - * Filter the facet filter name that's added to the URL - * - * @hook ep_facet_filter_name - * @param {string} Facet filter name - * @return {string} New facet filter name - */ - $filter_name = apply_filters( 'ep_facet_filter_name', 'ep_filter_' ); - if ( ! empty( $filters['taxonomies'] ) ) { $tax_filters = $filters['taxonomies']; foreach ( $tax_filters as $taxonomy => $filter ) { if ( ! empty( $filter['terms'] ) ) { - $query_param[ $filter_name . $taxonomy ] = implode( ',', array_keys( $filter['terms'] ) ); + $query_param[ $this->get_filter_name() . $taxonomy ] = implode( ',', array_keys( $filter['terms'] ) ); } } } @@ -532,4 +515,21 @@ public function get_allowed_query_args() { */ return apply_filters( 'ep_facet_allowed_query_args', $args ); } + + /** + * Get the facet filter name. + * + * @return string The filter name. + */ + protected function get_filter_name() { + /** + * Filter the facet filter name that's added to the URL + * + * @hook ep_facet_filter_name + * @since 4.0.0 + * @param {string} Facet filter name + * @return {string} New facet filter name + */ + return apply_filters( 'ep_facet_filter_name', 'ep_filter_' ); + } }