Commit ecd82528 authored by Kenny Hall's avatar Kenny Hall

Added a cache busting method that runs on plugin activation to see if we need...

Added a cache busting method that runs on plugin activation to see if we need to update our promotions.
parent e0e7ecef
Pipeline #1854 passed with stage
in 38 seconds
......@@ -44,22 +44,22 @@ class NF_PromotionManager
****************************************************************************/
private function is_layout_styles_active()
{
return class_exists( 'NF_Layouts' );
return class_exists( 'NF_Layouts', false );
}
private function is_conditional_logic_active()
{
return class_exists( 'NF_ConditionalLogic' );
return class_exists( 'NF_ConditionalLogic', false );
}
private function is_multi_part_active()
{
return class_exists( 'NF_MultiPart' );
return class_exists( 'NF_MultiPart', false );
}
private function is_file_uploads_active()
{
return class_exists( 'NF_FU_File_Uploads ' );
return class_exists( 'NF_FU_File_Uploads', false );
}
/**
......
......@@ -456,6 +456,8 @@ if( get_option( 'ninja_forms_load_deprecated', FALSE ) && ! ( isset( $_POST[ 'nf
add_action( 'admin_init', array( self::$instance, 'admin_init' ), 5 );
add_action( 'nf_weekly_promotion_update', array( self::$instance, 'nf_run_promotion_manager' ) );
add_action( 'activated_plugin', array( self::$instance, 'nf_bust_promotion_cache_on_plugin_activation' ), 10, 2 );
// Checks php version and..
if( PHP_VERSION < 5.6 ) {
......@@ -472,6 +474,7 @@ if( get_option( 'ninja_forms_load_deprecated', FALSE ) && ! ( isset( $_POST[ 'nf
public function init()
{
do_action( 'nf_init', self::$instance );
}
public function admin_init()
......@@ -625,6 +628,54 @@ if( get_option( 'ninja_forms_load_deprecated', FALSE ) && ! ( isset( $_POST[ 'nf
update_option( 'nf_active_promotions', $promomotions, false );
}
/**
* Listens for plugin activation and runs check to see if any
* promotions need to be added or removed.
*
* @return void
*/
public function nf_bust_promotion_cache_on_plugin_activation( $plugin, $network_activation )
{
$addons_with_promotions = $this->get_promotion_addons_lookup_table();
$plugin = explode( '/', $plugin );
$this->nf_maybe_bust_promotion_cache( $addons_with_promotions, $plugin[ 0 ] );
}
/**
* Build a look up table for the add-ons that have promotions.
* TODO: maybe come up with a better name for this class.
*
* @return array of promotions.
*/
public function get_promotion_addons_lookup_table()
{
$nf_promotion_addons = array(
'ninja-forms-conditional-logic',
'ninja-forms-uploads',
'ninja-forms-multi-part',
'ninja-forms-layout-styles',
'ninja-shop',
'sendwp'
);
return $nf_promotion_addons;
}
/**
* Loops over our add-ons that have promotions and
* runs the promotion manager class.
*
* @return void
*/
public function nf_maybe_bust_promotion_cache( $promo_addons, $plugin_being_activated )
{
foreach( $promo_addons as $addon ) {
if( $addon == $plugin_being_activated ) {
$this->nf_run_promotion_manager();
}
}
}
public function admin_notices()
{
// Notices filter and run the notices function.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment