| 1 |
<?php |
| 2 |
|
| 3 |
namespace QuadLayers\QuadMenu; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
die( '-1' ); |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Activation Class ex QuadMenu_Activation |
| 11 |
*/ |
| 12 |
class Activation { |
| 13 |
|
| 14 |
protected static $instance; |
| 15 |
|
| 16 |
function __construct() { |
| 17 |
|
| 18 |
add_action( 'admin_init', array( __CLASS__, 'redirect' ) ); |
| 19 |
|
| 20 |
add_action( 'after_switch_theme', array( __CLASS__, 'do_compiler' ) ); |
| 21 |
|
| 22 |
add_action( 'after_switch_theme', array( __CLASS__, 'do_redirect' ) ); |
| 23 |
|
| 24 |
add_action( 'quadmenu_activation', array( __CLASS__, 'do_compiler' ) ); |
| 25 |
|
| 26 |
add_action( 'quadmenu_activation', array( __CLASS__, 'do_redirect' ) ); |
| 27 |
|
| 28 |
add_action( 'quadmenu_activation', array( __CLASS__, 'do_rating' ) ); |
| 29 |
|
| 30 |
add_action( 'upgrader_process_complete', array( __CLASS__, 'update' ), 10, 2 ); |
| 31 |
} |
| 32 |
|
| 33 |
static function update( $upgrader_object, $options ) { |
| 34 |
|
| 35 |
if ( $options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] ) ) { |
| 36 |
|
| 37 |
foreach ( $options['plugins'] as $plugin ) { |
| 38 |
if ( $plugin == QUADMENU_PLUGIN_BASENAME ) { |
| 39 |
self::do_compiler(); |
| 40 |
self::do_redirect(); |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
static function redirect() { |
| 47 |
|
| 48 |
if ( is_network_admin() ) { |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
if ( ! get_transient( '_quadmenu_redirect' ) ) { |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
delete_transient( '_quadmenu_redirect' ); |
| 57 |
|
| 58 |
wp_redirect( admin_url( 'admin.php?page=' . QUADMENU_PANEL ) ); |
| 59 |
} |
| 60 |
|
| 61 |
static function do_compiler() { |
| 62 |
update_option( '_quadmenu_compiler', true ); |
| 63 |
} |
| 64 |
|
| 65 |
static function do_redirect() { |
| 66 |
set_transient( '_quadmenu_redirect', true, 30 ); |
| 67 |
} |
| 68 |
|
| 69 |
static function do_rating() { |
| 70 |
set_transient( '_quadmenu_first_rating', true, MONTH_IN_SECONDS ); |
| 71 |
} |
| 72 |
|
| 73 |
static function activation() { |
| 74 |
do_action( 'quadmenu_activation' ); |
| 75 |
} |
| 76 |
|
| 77 |
public static function instance() { |
| 78 |
if ( is_null( self::$instance ) ) { |
| 79 |
self::$instance = new self(); |
| 80 |
} |
| 81 |
return self::$instance; |
| 82 |
} |
| 83 |
} |
| 84 |
|