/** * Save the settings */ private function save() { // We need to save the options ourselves; settings api does not trigger save for the permalinks page if (isset($_POST['permalink_structure']) || isset($_POST['category_base']) && isset($_POST['product_permalink'])) { // Cat and tag bases $categorySlug = trim(strip_tags($_POST['jigoshop_product_category_slug'])); $tagSlug = trim(strip_tags($_POST['jigoshop_product_tag_slug'])); $permalinks = $this->options->get('permalinks'); $helpers = $this->wp->getHelpers(); $permalinks['category'] = $helpers->untrailingslashit($categorySlug); $permalinks['tag'] = $helpers->untrailingslashit($tagSlug); // Product base $product_permalink = trim(strip_tags($_POST['product_permalink'])); if ($product_permalink == 'custom') { // Get permalink without slashes $product_permalink = trim(strip_tags($_POST['product_permalink_structure']), '/'); // This is an invalid base structure and breaks pages if ('%' . Types::PRODUCT_CATEGORY . '%' == $product_permalink) { $product_permalink = _x('product', 'slug', 'jigoshop') . '/' . $product_permalink; } } elseif (empty($product_permalink)) { $product_permalink = false; } $permalinks['product'] = $helpers->untrailingslashit($product_permalink); // Shop base may require verbose page rules if nesting pages $shopPageId = $this->options->getPageId(FrontendPages::SHOP); $shop_permalink = urldecode($shopPageId > 0 && $this->wp->getPost($shopPageId) ? $this->wp->getPageUri($shopPageId) : _x('shop', 'default-slug', 'jigoshop')); if ($shopPageId && trim($permalinks['product'], '/') === $shop_permalink) { $permalinks['verbose'] = true; } $this->options->update('permalinks', $permalinks); $this->options->saveOptions(); $this->wp->getRewrite()->flush_rules(); } }
public function fix($rules) { $wp_rewrite = $this->wp->getRewrite(); $permalink = $this->options->get('permalinks.product'); // Fix the rewrite rules when the product permalink have %product_category% flag if (preg_match('`/(.+)(/%' . Types::PRODUCT_CATEGORY . '%)`', $permalink, $matches)) { foreach ($rules as $rule => $rewrite) { if (preg_match('`^' . preg_quote($matches[1], '`') . '/\\(`', $rule) && preg_match('/^(index\\.php\\?' . Types::PRODUCT_CATEGORY . ')(?!(.*' . Types::PRODUCT . '))/', $rewrite)) { unset($rules[$rule]); } } } // If the shop page is used as the base, we need to enable verbose rewrite rules or sub pages will 404 if ($this->options->get('permalinks.verbose')) { $page_rewrite_rules = $wp_rewrite->page_rewrite_rules(); $rules = array_merge($page_rewrite_rules, $rules); } return $rules; }
/** * Adds rewrite endpoint for processing Jigoshop APIs */ public function addRewrite() { $this->wp->addRewriteRule($this->wp->getRewrite()->root . 'api/v([0-9])/([0-9a-zA-Z/]+)(\\.json|\\.xml)?$', sprintf('index.php?%s=$matches[1]&%s=/$matches[2]&%s=$matches[3]', self::QUERY_VERSION, self::QUERY_URI, self::QUERY_FORMAT), 'top'); }