addQueryArgFilter('speedycache_pro_updater_filter_args');
// Show the text to install the license key
add_filter('puc_manual_final_check_link-speedycache-pro', 'speedycache_pro_updater_check_link', 10, 1);
if(!is_admin() && !current_user_can('activate_plugins')){
return;
}
include_once SPEEDYCACHE_PRO_DIR . '/main/admin.php';
add_action('admin_notices', 'speedycachepro_free_version_nag');
}
// Nag when plugins dont have same version.
function speedycachepro_free_version_nag(){
if(!defined('SPEEDYCACHE_VERSION')){
return;
}
$dismissed_free = (int) get_option('speedycache_version_free_nag');
$dismissed_pro = (int) get_option('speedycache_version_pro_nag');
// Checking if time has passed since the dismiss.
if(!empty($dismissed_free) && time() < $dismissed_pro && !empty($dismissed_pro) && time() < $dismissed_pro){
return;
}
$showing_error = false;
if(version_compare(SPEEDYCACHE_VERSION, SPEEDYCACHE_PRO_VERSION) > 0 && (empty($dismissed_pro) || time() > $dismissed_pro)){
$showing_error = true;
echo '
'.esc_html__('You are using an older version of SpeedyCache Pro. We recommend updating to the latest version to ensure seamless and uninterrupted use of the application.', 'speedycache').'
';
}elseif(version_compare(SPEEDYCACHE_VERSION, SPEEDYCACHE_PRO_VERSION) < 0 && (empty($dismissed_free) || time() > $dismissed_free)){
$showing_error = true;
echo '
'.esc_html__('You are using an older version of SpeedyCache. We recommend updating to the latest free version to ensure smooth and uninterrupted use of the application.', 'speedycache').'
';
}
if(!empty($showing_error)){
wp_register_script('speedycache-pro-version-notice', '', array('jquery'), SPEEDYCACHE_PRO_VERSION, true );
wp_enqueue_script('speedycache-pro-version-notice');
wp_add_inline_script('speedycache-pro-version-notice', '
function speedycache_pro_dismiss_notice(e){
e.preventDefault();
let target = jQuery(e.target);
if(!target.hasClass("notice-dismiss")){
return;
}
let jEle = target.closest("#speedycache-pro-version-notice"),
type = jEle.data("type");
jEle.slideUp();
jQuery.post("'.admin_url('admin-ajax.php').'", {
security : "'.wp_create_nonce('speedycache_version_notice').'",
action: "speedycache_pro_version_notice",
type: type
}, function(res){
if(!res["success"]){
alert(res["data"]);
}
}).fail(function(data){
alert("There seems to be some issue dismissing this alert");
});
}');
}
}
// Version nag ajax
function speedycache_pro_version_notice(){
check_admin_referer('speedycache_version_notice', 'security');
if(!current_user_can('activate_plugins')){
wp_send_json_error(__('You do not have required access to do this action', 'speedycache'));
}
$type = '';
if(!empty($_REQUEST['type'])){
$type = sanitize_text_field(wp_unslash($_REQUEST['type']));
}
if(empty($type)){
wp_send_json_error(__('Unknown version difference type', 'speedycache'));
}
update_option('speedycache_version_'. $type .'_nag', time() + WEEK_IN_SECONDS);
wp_send_json_success();
}
add_action('wp_ajax_speedycache_pro_version_notice', 'speedycache_pro_version_notice');
//register_deactivation_hook( __FILE__, '\SpeedyCache\Install::deactivate');
// Load WP CLI command(s) on demand.
if(defined('WP_CLI') && !empty(WP_CLI) && defined('SPEEDYCACHE_PRO')){
include_once SPEEDYCACHE_PRO_DIR.'/main/cli.php';
}