From ee7db46934b173e6eb887dbf1b15d1a2d8f64187 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 14 Feb 2014 10:43:15 +0000 Subject: [PATCH] Force a valid base when saving permalinks --- includes/admin/class-wc-admin-permalink-settings.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin-permalink-settings.php b/includes/admin/class-wc-admin-permalink-settings.php index 62678156af4..7d6333963a4 100644 --- a/includes/admin/class-wc-admin-permalink-settings.php +++ b/includes/admin/class-wc-admin-permalink-settings.php @@ -176,7 +176,16 @@ class WC_Admin_Permalink_Settings { $product_permalink = wc_clean( $_POST['product_permalink'] ); if ( $product_permalink == 'custom' ) { - $product_permalink = wc_clean( $_POST['product_permalink_structure'] ); + // Get permalink without slashes + $product_permalink = trim( wc_clean( $_POST['product_permalink_structure'] ), '/' ); + + // This is an invalid base structure and breaks pages + if ( '%product_cat%' == $product_permalink ) { + $product_permalink = _x( 'product', 'slug', 'woocommerce' ) . '/' . $product_permalink; + } + + // Prepending slash + $product_permalink = '/' . $product_permalink; } elseif ( empty( $product_permalink ) ) { $product_permalink = false; }