Skip to content

Commit a2c65a6

Browse files
committed
update rewrite to handle language slug with an hyphen
1 parent d386016 commit a2c65a6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Url/Rewrite.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct() {
3838
public function sf_add_custom_rewrite_rule() {
3939
// regex match either the base endpoint or the localized endpoints.
4040
$regex = sprintf(
41-
'^%s(?:-([a-z]{2,3}))?/?$',
41+
'^%s((?:-[a-z]{2,3}){1,2})?/?$',
4242
ShoppingFeedHelper::get_public_feed_endpoint()
4343
);
4444
$query = sprintf(
@@ -72,9 +72,16 @@ public function sf_add_custom_query_vars( $vars ) {
7272
*/
7373
public function sf_parse_request() {
7474
global $wp;
75-
if ( isset( $wp->query_vars[ self::FEED_QUERY_VAR ] ) ) {
76-
$lang = ! empty( $wp->query_vars[ self::FEED_LANG_QUERY_VAR ] ) ? $wp->query_vars[ self::FEED_LANG_QUERY_VAR ] : null;
77-
ShoppingFeedHelper::get_feedbuilder_manager()->render_feed( $lang );
75+
if ( ! isset( $wp->query_vars[ self::FEED_QUERY_VAR ] ) ) {
76+
return;
7877
}
78+
79+
$lang = ! empty( $wp->query_vars[ self::FEED_LANG_QUERY_VAR ] ) ? $wp->query_vars[ self::FEED_LANG_QUERY_VAR ] : null;
80+
81+
// Remove first hyphen (-) if needed
82+
if ( ! empty( $lang ) && str_starts_with( $lang, '-' ) ) {
83+
$lang = ltrim( $lang, '-' );
84+
}
85+
ShoppingFeedHelper::get_feedbuilder_manager()->render_feed( $lang );
7986
}
8087
}

0 commit comments

Comments
 (0)