Skip to content

Commit

Permalink
add option for disabling existing feed
Browse files Browse the repository at this point in the history
  • Loading branch information
haszari committed May 7, 2021
1 parent fe14d3c commit c711a0a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
23 changes: 23 additions & 0 deletions facebook-commerce.php
Expand Up @@ -40,6 +40,9 @@ class WC_Facebookcommerce_Integration extends WC_Integration {
/** @var string the WordPress option name where the external merchant settings ID is stored */
const OPTION_EXTERNAL_MERCHANT_SETTINGS_ID = 'wc_facebook_external_merchant_settings_id';

/** @var string Option name for disabling feed. */
const OPTION_LEGACY_FEED_FILE_GENERATION_ENABLED = 'wc_facebook_legacy_feed_file_generation_enabled';

/** @var string the WordPress option name where the feed ID is stored */
const OPTION_FEED_ID = 'wc_facebook_feed_id';

Expand Down Expand Up @@ -3175,6 +3178,26 @@ public function is_product_sync_enabled() {
return (bool) apply_filters( 'wc_facebook_is_product_sync_enabled', 'yes' === get_option( self::SETTING_ENABLE_PRODUCT_SYNC, 'yes' ), $this );
}

/**
* Return true if (legacy) feed generation is enabled.
*
* Feed generation for product sync is enabled by default, and generally recommended.
* Large stores, or stores running on shared hosting (low resources) may have issues
* with feed generation. This option allows those stores to disable generation to
* work around the issue.
*
* Note - this is temporary. In a future release, an improved feed system will be
* implemented, which should work well for all stores. This option will not disable
* the new improved implementation.
*
* @since 2.5.0
*
* @return bool
*/
public function is_legacy_feed_file_generation_enabled() {
return (bool) ( 'yes' === get_option( self::OPTION_LEGACY_FEED_FILE_GENERATION_ENABLED, 'yes' ) );
}


/**
* Determines whether the scheduled re-sync is enabled.
Expand Down
12 changes: 8 additions & 4 deletions includes/Products/Feed.php
Expand Up @@ -158,10 +158,14 @@ public function regenerate_feed() {
*/
public function schedule_feed_generation() {

$integration = facebook_for_woocommerce()->get_integration();

// only schedule if configured
if ( ! $integration || ! $integration->is_configured() || ! $integration->is_product_sync_enabled() ) {
$integration = facebook_for_woocommerce()->get_integration();
$configured_ok = $integration && $integration->is_configured();

// Only schedule feed job if store has not opted out of product sync.
$store_allows_sync = $configured_ok && $integration->is_product_sync_enabled();
// Only schedule if has not opted out of feed generation (e.g. large stores).
$store_allows_feed = $configured_ok && $integration->is_legacy_feed_file_generation_enabled();
if ( ! $store_allows_sync || ! $store_allows_feed ) {
as_unschedule_all_actions( self::GENERATE_FEED_ACTION );
return;
}
Expand Down

0 comments on commit c711a0a

Please sign in to comment.