| 1 |
<?php |
| 2 |
/** |
| 3 |
* HootKit Activation |
| 4 |
* |
| 5 |
* @package Hootkit |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace HootKit\Inc; |
| 9 |
|
| 10 |
// If this file is called directly, abort. |
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
die; |
| 13 |
} |
| 14 |
|
| 15 |
if ( ! class_exists( '\HootKit\Inc\Activation' ) ) : |
| 16 |
|
| 17 |
class Activation { |
| 18 |
|
| 19 |
/** |
| 20 |
* Class Instance |
| 21 |
*/ |
| 22 |
private static $instance; |
| 23 |
|
| 24 |
/** |
| 25 |
* Constructor |
| 26 |
*/ |
| 27 |
public function __construct() { |
| 28 |
$file = str_replace( array( |
| 29 |
'include\class-activation', |
| 30 |
'include/class-activation' |
| 31 |
), 'hootkit', __FILE__ ); |
| 32 |
|
| 33 |
// Load Text Domain |
| 34 |
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) ); |
| 35 |
|
| 36 |
// Run on plugin activation |
| 37 |
register_activation_hook( $file, array( $this, 'plugin_activate' ) ); |
| 38 |
add_action( 'plugins_loaded', array( $this, 'plugin_activate_backward' ), 0 ); |
| 39 |
|
| 40 |
// Run on plugin deactivation |
| 41 |
register_deactivation_hook( $file, array( $this, 'plugin_deactivate' ) ); |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Load Plugin Text Domain |
| 47 |
* |
| 48 |
* @since 1.0.0 |
| 49 |
* @access public |
| 50 |
* @return void |
| 51 |
*/ |
| 52 |
public function load_plugin_textdomain() { |
| 53 |
$rootdir = dirname( hootkit()->plugin_basename ); |
| 54 |
$lang_dir = apply_filters( 'hootkit_languages_directory', $rootdir . '/languages/' ); |
| 55 |
|
| 56 |
load_plugin_textdomain( |
| 57 |
hootkit()->slug, |
| 58 |
false, |
| 59 |
$lang_dir |
| 60 |
); |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Run when plugin is activated |
| 66 |
* |
| 67 |
* @since 1.1.0 |
| 68 |
* @access public |
| 69 |
* @return void |
| 70 |
*/ |
| 71 |
public function plugin_activate() { |
| 72 |
$previous_activation = get_option( 'hootkit-activate' ); |
| 73 |
if ( !$previous_activation ) { |
| 74 |
add_option( 'hootkit-activate', array( |
| 75 |
'time' => time(), |
| 76 |
'version' => hootkit()->version |
| 77 |
) ); |
| 78 |
} |
| 79 |
} |
| 80 |
/** |
| 81 |
* Set activation for version prior to 1.1.0 |
| 82 |
* |
| 83 |
* @since 2.0.0 |
| 84 |
*/ |
| 85 |
public function plugin_activate_backward() { |
| 86 |
if ( is_admin() ) { |
| 87 |
$previous_activation = get_option( 'hootkit-activate' ); |
| 88 |
if ( empty( $previous_activation ) ) { |
| 89 |
add_option( 'hootkit-activate', array( |
| 90 |
'time' => time() - ( 7 * 24 * 60 * 60 ), |
| 91 |
'version' => '2.0.0' |
| 92 |
) ); |
| 93 |
} elseif ( !\is_array( $previous_activation ) ) { |
| 94 |
update_option( 'hootkit-activate', array( |
| 95 |
'time' => $previous_activation, |
| 96 |
'version' => '2.0.0' |
| 97 |
) ); |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Run when plugin is deactivated |
| 104 |
* |
| 105 |
* @since 2.0.0 |
| 106 |
* @access public |
| 107 |
* @return void |
| 108 |
*/ |
| 109 |
public function plugin_deactivate() { |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Returns the instance |
| 114 |
*/ |
| 115 |
public static function get_instance() { |
| 116 |
if ( ! isset( self::$instance ) ) { |
| 117 |
self::$instance = new self(); |
| 118 |
} |
| 119 |
return self::$instance; |
| 120 |
} |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
Activation::get_instance(); |
| 125 |
|
| 126 |
endif; |