| 1 |
<?php |
| 2 |
/** |
| 3 |
* Logic to run on plugin install. |
| 4 |
* |
| 5 |
* @package Search_Replace_WPCode |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Class WPCode_Install. |
| 14 |
*/ |
| 15 |
class WSRW_Install { |
| 16 |
|
| 17 |
/** |
| 18 |
* WSRW_Install constructor. |
| 19 |
*/ |
| 20 |
public function __construct() { |
| 21 |
register_activation_hook( WSRW_FILE, array( $this, 'activate' ) ); |
| 22 |
add_action( 'admin_init', array( $this, 'maybe_run_install' ) ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Activation hook. |
| 27 |
* |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
public function activate() { |
| 31 |
// Use an action to have a single activation hook plugin-wide. |
| 32 |
do_action( 'wsrw_plugin_activation' ); |
| 33 |
|
| 34 |
set_transient( 'wsrw_just_activated', class_exists( 'WSRW_License' ) ? 'pro' : 'lite', 60 ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Install routine to run on plugin activation. |
| 39 |
* Runs on admin_init so that we also handle updates. |
| 40 |
* The ihaf_activated option was used by IHAF 1.6 and the key "lite" is for the activation date |
| 41 |
* of that version of the plugin. In the WPCode plugin we use the "wpcode" key, so we have the update date |
| 42 |
* and install the demo data. |
| 43 |
* |
| 44 |
* @return void |
| 45 |
*/ |
| 46 |
public function maybe_run_install() { |
| 47 |
if ( ! is_admin() ) { |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
$activated = get_option( 'wsrw_activated', array() ); |
| 52 |
|
| 53 |
if ( ! is_array( $activated ) ) { |
| 54 |
$activated = array(); |
| 55 |
} |
| 56 |
|
| 57 |
if ( empty( $activated['wsrw'] ) ) { |
| 58 |
$activated['wsrw'] = time(); |
| 59 |
|
| 60 |
update_option( 'wsrw_activated', $activated ); |
| 61 |
|
| 62 |
do_action( 'wsrw_install' ); |
| 63 |
} |
| 64 |
|
| 65 |
// Maybe run manually just one time. |
| 66 |
$install = get_option( 'wsrw_install', false ); |
| 67 |
|
| 68 |
if ( ! empty( $install ) ) { |
| 69 |
$this->activate(); |
| 70 |
delete_option( 'wsrw_install' ); |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
new WSRW_Install(); |
| 76 |
|