public static function stop_experiment($exp_id, $exp_type) { try { $exp = NelioABExperimentsManager::get_experiment_by_id($exp_id, $exp_type); $exp->stop(); NelioABExperimentsManager::update_running_experiments_cache('now'); } catch (Exception $e) { require_once NELIOAB_ADMIN_DIR . '/error-controller.php'; NelioABErrorController::build($e); } }
/** * Activates Nelio A/B Testing * * This function is called by the "registed_activation_hook". It is the * opposite of the nelioab_deactivate_plugin function. Its aim is to make sure * that alternatives (draft post/pages with a metatype) are not visible in the * admin area, but can be editted and used. * * We also make sure that it's called after an update. * * @return void * * @since PHPDOC */ function nelioab_activate_plugin() { /** @var wpdb $wpdb */ global $wpdb; // Old Stuff Compa: rename the meta key that identifies post/page alternatives... $wpdb->update($wpdb->postmeta, array('meta_key' => '_is_nelioab_alternative'), array('meta_key' => 'is_nelioab_alternative')); // We remove all information about "_is_nelioab_alternative" for posts whose // IDs are less than 15. In previous versions of the plugin, Title experiments // marked those posts as alternatives (negative IDs from -1 to -15 were used // and WordPress interpreted them as positive IDs). $query = '' . 'DELETE FROM ' . $wpdb->postmeta . ' WHERE ' . 'post_id < 15 AND meta_key = \'_is_nelioab_alternative\''; $wpdb->query($query); // Showing previous page and post alternatives require_once NELIOAB_UTILS_DIR . '/wp-helper.php'; $cpts = NelioABWpHelper::get_custom_post_types(); $post_types = array('post', 'page'); foreach ($cpts as $post_type) { array_push($post_types, $post_type->name); } $query = 'UPDATE ' . $wpdb->posts . ' SET post_type = %s WHERE post_type = %s'; // execute the query foreach ($post_types as $post_type) { $wpdb->query($wpdb->prepare($query, $post_type, 'nelioab_alt_' . $post_type)); } // Recover previous widget alternatives require_once NELIOAB_EXP_CONTROLLERS_DIR . '/widget-experiment-controller.php'; NelioABWidgetExpAdminController::restore_alternative_widget_backup(); // Recover previous menu alternatives require_once NELIOAB_EXP_CONTROLLERS_DIR . '/menu-experiment-controller.php'; NelioABMenuExpAdminController::restore_alternative_menu_backup(); // Make sure that the cache uses new classes require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; NelioABExperimentsManager::update_running_experiments_cache('now'); // Save the latest version we use for "(re)activating" the plugin and // show the welcome message $version = get_option('nelioab_last_version_installed', false); update_option('nelioab_last_version_installed', NELIOAB_PLUGIN_VERSION); // Prepare the code for showing the welcome message if (!is_network_admin() && !isset($_GET['activate-multi'])) { if (NELIOAB_PLUGIN_VERSION === $version) { set_transient('_nelioab_welcome_user', 'nelioab-reactivated', 30); } else { if (NELIOAB_PLUGIN_VERSION !== $version) { set_transient('_nelioab_welcome_user', 'nelioab-updated', 30); } else { set_transient('_nelioab_welcome_user', 'nelioab-installed', 30); } } } }