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: 289: 290: 291: 292: 293: 294: 295: 296: 297:
<?php
class Landing_Pages_Activation {
static $version_wp;
static $version_php;
static $version_cta;
static $version_leads;
static $version_lpah;
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( 'Landing_Pages_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() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
public static function load_static_vars() {
self::$version_wp = '3.6';
self::$version_php = '5.2';
self::$version_cta = '1.2.1';
self::$version_leads = '1.2.1';
self::$version_lpah = '1.0.8';
}
public static function activate_plugin() {
self::store_version_data();
self::set_default_settings();
self::activate_shared();
do_action( 'activate_landing_pages' );
}
public static function run_updates() {
$updaters = get_class_methods('Landing_Pages_Activation_Update_Routines');
$completed = ( get_option( 'lp_completed_upgrade_routines' ) ) ? get_option( 'lp_completed_upgrade_routines' ) : array();
$remaining = array_diff( $updaters , $completed );
foreach ( $remaining as $updater ) {
Landing_Pages_Activation_Update_Routines::$updater();
$completed[] = $updater;
}
update_option( 'lp_completed_upgrade_routines' , $completed );
}
public static function run_upgrade_routine_checks() {
if (isset($_GET['plugin_action']) && $_GET['plugin_action'] == 'upgrade_routines' && $_GET['plugin'] =='landing-pages' ) {
self::run_updates();
wp_redirect(wp_get_referer());
exit;
}
$updaters = get_class_methods('Landing_Pages_Activation_Update_Routines');
$completed = ( get_option( 'lp_completed_upgrade_routines' ) ) ? get_option( 'lp_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( 'Landing Pages plugin requires a database upgrade:', 'inbound-pro' ); ?> <a href='?plugin=landing-pages&plugin_action=upgrade_routines'><?php _e('Upgrade database now' , 'inbound-pro' ); ?></a></p>
</div>
<?php
}
public static function store_version_data() {
$old = get_transient('lp_current_version');
set_transient( 'lp_previous_version' , $old );
set_transient( 'lp_current_version' , LANDINGPAGES_CURRENT_VERSION );
}
public static function set_default_settings() {
add_option( 'lp_global_css', '', '', 'no' );
add_option( 'lp_global_js', '', '', 'no' );
add_option( 'lp_global_lp_slug', 'go', '', 'no' );
update_option( 'lp_activate_rewrite_check', '1');
set_transient( '_landing_page_activation_redirect', true, 30 );
}
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( LANDINGPAGES_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' => __('Landing Plugin could not be installed' , 'landing-pages'),
'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' => __('Landing Plugin could not be installed' , 'landing-pages'),
'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('WP_CTA_CURRENT_VERSION') && version_compare( WP_CTA_CURRENT_VERSION , self::$version_cta , '<' ) ) {
self::abort_activation( array(
'title' => 'Installation aborted',
'message' => __('Landing Plugin could not be installed' , 'landing-pages'),
'details' => array(
__( 'Calls to Action Version' , 'inbound-pro' ) => WP_CTA_CURRENT_VERSION,
__( 'Required Calls to Action Version' , 'inbound-pro' ) => self::$version_cta
),
'solution' => sprintf( __( 'Please update Calls to Action to version %s or greater.' , 'inbound-pro' ) , self::$version_cta )
)
);
}
if ( defined('WPL_CURRENT_VERSION') && version_compare( WPL_CURRENT_VERSION , self::$version_leads , '<' ) ) {
self::abort_activation( array(
'title' => 'Installation aborted',
'message' => __('Landing Plugin could not be installed' , 'landing-pages'),
'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 )
)
);
}
if ( defined('LP_HOMEPAGE_CURRENT_VERSION') && version_compare( LP_HOMEPAGE_CURRENT_VERSION , self::$version_lpah , '<' ) ) {
self::abort_activation( array(
'title' => 'Installation aborted',
'message' => __('Landing Plugin could not be installed' , 'landing-pages'),
'details' => array(
__( 'Extension: Landing Page as Homepage' , 'inbound-pro' ) => LP_HOMEPAGE_CURRENT_VERSION,
__( 'Required extension version' , 'inbound-pro' ) => self::$version_lpah
),
'solution' => sprintf( __( 'Please update extension to version %s or greater.' , 'inbound-pro' ) , self::$version_lpah )
)
);
}
}
public static function flush_permalinks() {
if ( !get_option( 'lp_activate_rewrite_check' ) ) {
return;
}
flush_rewrite_rules( true );
delete_option( 'lp_activate_rewrite_check' );
}
public static function permastruct_check() {
if ( '' == get_option( 'permalink_structure' ) ) {
?>
<div class="error">
<p><?php _e( 'Landing Pages plugin requires you to use a non default permlaink structure. Please head into your pemalink settings and choose an option besides \'default\'.' , 'landing-pages'); ?></p>
</div>
<?php
}
}
}
register_activation_hook( LANDINGPAGES_FILE , array( 'Landing_Pages_Activation' , 'activate' ) );
register_deactivation_hook( LANDINGPAGES_FILE , array( 'Landing_Pages_Activation' , 'deactivate' ) );
new Landing_Pages_Activation;