Skip to content

Commit

Permalink
Fix feed rewrite uri in case of custom permalink + generate empty fil…
Browse files Browse the repository at this point in the history
…e when no products founds
  • Loading branch information
Sami Kerboute committed Jun 9, 2020
1 parent 4ae0a1b commit ba083ab
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/Feed/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ public function render( $no_cache = false ) {
public function generate() {
$products_list = Products::get_instance()->get_list();

if ( empty( $products_list ) ) {
return new WP_Error( 'shopping_feed_generation_error_no_product', 'No product to export' );
}

try {
$this->generator->write( $products_list );
$uri = Uri::get_full_path();
Expand Down
4 changes: 2 additions & 2 deletions src/ShoppingFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ public static function activate() {
if ( defined( 'WC_VERSION' ) ) {
Actions::register_feed_generation();
Actions::register_get_orders();
flush_rewrite_rules();
}
flush_rewrite_rules();
}

/**
Expand All @@ -221,8 +221,8 @@ public static function deactivate() {
if ( defined( 'WC_VERSION' ) ) {
Actions::clean_feed_generation();
Actions::clean_get_orders();
flush_rewrite_rules();
}
flush_rewrite_rules();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/ShoppingFeedHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public static function get_feed_filename() {
* @return string
*/
public static function get_public_feed_endpoint() {
return Rewrite::FEED_PARAM;
global $wp_rewrite;
return $wp_rewrite->root . Rewrite::FEED_PARAM;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Url/Rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ public function __construct() {
* Add new pretty url to getting the feed
*/
public function sf_add_custom_rewrite_rule() {
global $wp_rewrite;
$endpoint = ShoppingFeedHelper::get_public_feed_endpoint();
$regex = '^' . $wp_rewrite->root . $endpoint . '$';
add_rewrite_rule(
"$endpoint$",
$regex,
array( self::FEED_PARAM => true ),
'top'
);
Expand Down

0 comments on commit ba083ab

Please sign in to comment.