Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 1. Detects Filter Everything Pro filter URLs
- *
- * @param string $element_id The current element ID.
- * @param array $uri_parts An array containing URI parts.
- * @param string $request_url The URL of the current request.
- *
- * @return string The filtered element ID.
- */
- function pm_detect_filter_everything_url( $element_id, $uri_parts, $request_url ) {
- global $permalink_manager_uris;
- if ( empty( $element_id ) && ! empty( $uri_parts['uri'] ) && strpos( $uri_parts['uri'], '/' ) !== false ) {
- $uri = $uri_parts['uri'];
- $path_segments = explode( '/', trim( $uri, '/' ) );
- $loop_counter = 0; // Counter for loop iterations
- // Loop through the path segments in reverse order
- while ( ! empty( $path_segments ) && $loop_counter < 6 ) {
- $candidate_uri = implode( '/', $path_segments );
- if ( in_array( $candidate_uri, $permalink_manager_uris ) ) {
- $new_element_id = array_search( $candidate_uri, $permalink_manager_uris );
- // Check if the new element ID contains 'tax-'
- if ( strpos( $new_element_id, 'tax-' ) !== false ) {
- $element_id = $new_element_id;
- }
- break;
- }
- // Remove the last path segment and continue the loop
- array_pop( $path_segments );
- // Increment the loop counter
- $loop_counter ++;
- }
- }
- return $element_id;
- }
- add_filter( 'permalink_manager_detected_element_id', 'pm_detect_filter_everything_url', 10, 3 );
- /**
- * 2. Detects WOOF (HUSKY – Products Filter for WooCommerce Professional) filter URLs
- *
- * @param string $element_id The current element ID.
- * @param array $uri_parts An array containing URI parts.
- * @param string $request_url The request URL.
- *
- * @return string The updated element ID.
- */
- function pm_detect_woof_filter_url( $element_id, $uri_parts, $request_url ) {
- global $permalink_manager_uris;
- // Check if the 'woof' function is available and callable
- if ( ! function_exists( 'woof' ) || ! is_callable( 'woof' ) ) {
- return $element_id;
- }
- $woof_instance = woof();
- if ( method_exists( $woof_instance, 'get_swoof_search_slug' ) ) {
- // Get the filter slug
- $filter_slug = woof()->get_swoof_search_slug();
- if ( empty( $element_id ) && ! empty( $uri_parts['uri'] ) && strpos( $uri_parts['uri'], '/' ) !== false && strpos( $uri_parts['uri'], $filter_slug ) !== false ) {
- // Extract the new URI and find the corresponding element ID
- $new_uri = substr( $uri_parts['uri'], 0, strpos( $uri_parts['uri'], "/{$filter_slug}/" ) );
- $new_element_id = array_search( $new_uri, $permalink_manager_uris );
- // Change the element ID
- if ( $new_element_id !== false ) {
- $element_id = $new_element_id;
- }
- }
- }
- return $element_id;
- }
- add_filter('permalink_manager_detected_element_id', 'pm_detect_woof_filter_url', 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement