1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288:
<?php
if ( !class_exists('CTA_Activation') ) {
class CTA_Activation {
static $version_wp;
static $version_php;
static $version_lp;
static $version_leads;
public function __construct() {
self::load_hooks();
}
public static function load_hooks() {
if (!is_admin()) {
return;
}
add_action('admin_notices', array(__CLASS__, 'permastruct_check'));
add_action('admin_init', array(__CLASS__, 'flush_permalinks'), 11 );
add_action( 'admin_init', array( 'CTA_Activation', 'run_upgrade_routine_checks'));
}
public static function activate() {
self::load_static_vars();
self::run_version_checks();
self::activate_plugin();
self::run_updates();
}
public static function deactivate() {
}
public static function load_static_vars() {
self::$version_wp = '3.6';
self::$version_php = '5.3';
self::$version_lp = '1.3.6';
self::$version_leads = '1.2.1';
}
public static function activate_plugin() {
global $wpdb;
self::store_version_data();
self::set_default_settings();
self::activate_shared();
update_option( 'wp_cta_flush_permalinks', true, true);
}
public static function run_updates() {
$updaters = get_class_methods('CTA_Activation_Update_Routines');
$completed = ( get_option( 'cta_completed_upgrade_routines' ) ) ? get_option( 'cta_completed_upgrade_routines' ) : array();
$remaining = array_diff( $updaters, $completed );
foreach ( $remaining as $updater ) {
CTA_Activation_Update_Routines::$updater();
$completed[] = $updater;
}
update_option( 'cta_completed_upgrade_routines', $completed );
}
public static function run_upgrade_routine_checks() {
if (isset($_GET['plugin_action']) && $_GET['plugin_action'] == 'upgrade_routines' && $_GET['plugin'] =='cta' ) {
self::run_updates();
wp_redirect(wp_get_referer());
exit;
}
$updaters = get_class_methods('CTA_Activation_Update_Routines');
$completed = ( get_option( 'cta_completed_upgrade_routines' ) ) ? get_option( 'cta_completed_upgrade_routines' ) : array();
$remaining = array_diff( $updaters, $completed );
if (count($remaining)>0) {
add_action( 'admin_notices', array(__CLASS__, 'display_upgrade_routine_notice'));
}
}
public static function display_upgrade_routine_notice() {
?>
<div class="error">
<p><?php _e( 'Calls to Action plugin requires a database upgrade:', 'inbound-pro' ); ?> <a href='?plugin=cta&plugin_action=upgrade_routines'><?php _e('Upgrade Database Now', 'inbound-pro' ); ?></a></p>
</div>
<?php
}
public static function store_version_data() {
$old = get_transient('cta_current_version');
set_transient( 'cta_previous_version', $old );
set_transient( 'cta_current_version', WP_CTA_CURRENT_VERSION );
}
public static function set_default_settings() {
add_option( 'wp_cta_global_record_admin_actions', '1', '', 'no' );
add_option( 'wp_cta_global_wp_cta_slug', 'cta', '', 'no' );
update_option( 'wp_cta_activate_rewrite_check', '1');
}
public static function activate_shared() {
update_option( 'Inbound_Activate', true );
}
public static function abort_activation( $args ) {
echo $args['title'] . '<br>';
echo $args['message'] . '<br>';
echo 'Details:<br>';
print_r ($args['details']);
echo '<br>';
echo $args['solution'];
deactivate_plugins( WP_CTA_FILE );
exit;
}
public static function run_version_checks() {
global $wp_version;
if ( version_compare( phpversion(), self::$version_php, '<' ) ) {
self::abort_activation(
array(
'title' => 'Installation aborted',
'message' => __('Calls to Action plugin could not be installed', 'inbound-pro'),
'details' => array(
__( 'Server PHP Version', 'inbound-pro' ) => phpversion(),
__( 'Required PHP Version', 'inbound-pro' ) => self::$version_php
),
'solution' => sprintf( __( 'Please contact your hosting provider to upgrade PHP to %s or greater', 'inbound-pro'), self::$version_php )
)
);
}
if ( version_compare( $wp_version, self::$version_wp, '<' ) ) {
self::abort_activation( array(
'title' => 'Installation aborted',
'message' => __('Calls to Action plugin could not be installed', 'inbound-pro'),
'details' => array(
__( 'WordPress Version', 'inbound-pro' ) => $wp_version,
__( 'Required WordPress Version', 'inbound-pro' ) => self::$version_wp
),
'solution' => sprintf( __( 'Please update landing pages to version %s or greater.', 'inbound-pro'), self::$version_wp )
)
);
}
if ( defined('LANDINGPAGES_CURRENT_VERSION') && version_compare( LANDINGPAGES_CURRENT_VERSION, self::$version_lp, '<' ) ) {
self::abort_activation( array(
'title' => 'Installation aborted',
'message' => __('Calls to Action plugin could not be installed', 'inbound-pro'),
'details' => array(
__( 'Calls to Action Version', 'inbound-pro' ) => LANDINGPAGES_CURRENT_VERSION,
__( 'Required Calls to Action Version', 'inbound-pro' ) => self::$version_lp
),
'solution' => sprintf( __( 'Please update Calls to Action to version %s or greater.', 'inbound-pro'), self::$version_lp )
)
);
}
if ( defined('WPL_CURRENT_VERSION') && version_compare( WPL_CURRENT_VERSION, self::$version_leads, '<' ) ) {
self::abort_activation( array(
'title' => 'Installation aborted',
'message' => __('Calls to Action plugin could not be installed', 'inbound-pro'),
'details' => array(
__( 'Leads Version', 'inbound-pro' ) => WPL_CURRENT_VERSION,
__( 'Required Leads Version', 'inbound-pro' ) => self::$version_leads
),
'solution' => sprintf( __( 'Please update Leads to version %s or greater.', 'inbound-pro'), self::$version_leads )
)
);
}
}
public static function flush_permalinks() {
if ( !get_option( 'wp_cta_flush_permalinks' ) ) {
return;
}
flush_rewrite_rules( true );
delete_option( 'wp_cta_flush_permalinks' );
}
public static function permastruct_check() {
if ( '' == get_option( 'permalink_structure' ) ) {
?>
<div class="error">
<p><?php _e( 'Calls To Action plugin requires you to use a non default permlaink structure. Please head into your pemalink settings and choose an option besides \'default\'.', 'cta'); ?></p>
</div>
<?php
}
}
}
register_activation_hook( WP_CTA_FILE, array( 'CTA_Activation', 'activate'));
register_deactivation_hook( WP_CTA_FILE, array( 'CTA_Activation', 'deactivate'));
new CTA_Activation;
}