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:
<?php
class Leads_Activation {
static $version_wp;
static $version_php;
static $version_lp;
static $version_cta;
public static function activate() {
self::load_static_vars();
self::run_version_checks();
self::activate_plugin();
self::run_updates();
}
public static function deactivate() {
delete_option( 'Leads_Activated');
}
public static function load_static_vars() {
self::$version_wp = '3.6';
self::$version_php = '5.2';
self::$version_lp = '1.3.6';
self::$version_cta = '2.0.0';
}
public static function activate_plugin() {
self::store_version_data();
self::set_default_settings();
self::activate_shared();
add_option( 'Leads_Activated' , true );
}
public static function run_updates() {
remove_action('updated_post_meta', array( 'Leads_Post_Type' , 'record_meta_update'), 10, 4);
$updaters = get_class_methods('Leads_Activation_Update_Routines');
$completed = ( get_option( 'leads_completed_upgrade_routines' ) ) ? get_option( 'leads_completed_upgrade_routines' ) : array();
$remaining = array_diff( $updaters , $completed );
foreach ( $remaining as $updater ) {
Leads_Activation_Update_Routines::$updater();
$completed[] = $updater;
}
update_option( 'leads_completed_upgrade_routines' , $completed );
}
public static function run_upgrade_routine_checks() {
if (isset($_GET['plugin_action']) && $_GET['plugin_action'] == 'upgrade_routines' && $_GET['plugin'] =='leads' ) {
self::run_updates();
wp_redirect(wp_get_referer());
exit;
}
$updaters = get_class_methods('Leads_Activation_Update_Routines');
$completed = ( get_option( 'leads_completed_upgrade_routines' ) ) ? get_option( 'leads_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 run_version_checks() {
global $wp_version;
if ( version_compare( phpversion(), self::$version_php, '<' ) ) {
self::abort_activation(
array(
'title' => 'Installation aborted',
'message' => __('Leads plugin could not be installed' , 'landing-pages'),
'details' => array(
__( 'Server PHP Version' , 'landing-pages' ) => phpversion(),
__( 'Required PHP Version' , 'landing-pages' ) => self::$version_php
),
'solultion' => sprintf( __( 'Please contact your hosting provider to upgrade PHP to %s or greater' , 'landing-pages' ) , self::$version_php )
)
);
}
}
public static function display_upgrade_routine_notice() {
?>
<div class="error">
<p><?php _e( 'Leads plugin requires a database upgrade. Please note that this could take awhile. ', 'inbound-pro' ); ?> <a href='?plugin=leads&plugin_action=upgrade_routines'> <?php _e('Run Upgrade Processes' , 'inbound-pro' ); ?></a></p>
</div>
<?php
}
public static function store_version_data() {
$old = get_transient('leads_current_version');
set_transient( 'leads_previous_version' , $old );
set_transient( 'leads_current_version' , WPL_CURRENT_VERSION );
}
public static function set_default_settings() {
}
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( WPL_FILE );
exit;
}
}
register_activation_hook( WPL_FILE , array( 'Leads_Activation' , 'activate' ) );
register_deactivation_hook( WPL_FILE , array( 'Leads_Activation' , 'deactivate' ) );
add_action( 'admin_init' , array( 'Leads_Activation' , 'run_upgrade_routine_checks' ) );