| 1 |
<?php |
| 2 |
/** |
| 3 |
* Fired during plugin activation |
| 4 |
* |
| 5 |
* @link http://rextheme.com/ |
| 6 |
* @since 8.0.0 |
| 7 |
* |
| 8 |
* @package Wpvr |
| 9 |
* @subpackage Wpvr/includes |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Fired during plugin activation. |
| 14 |
* |
| 15 |
* This class defines all code necessary to run during the plugin's activation. |
| 16 |
* |
| 17 |
* @since 8.0.0 |
| 18 |
* @package Wpvr |
| 19 |
* @subpackage Wpvr/includes |
| 20 |
* @author Rextheme <support@rextheme.com> |
| 21 |
*/ |
| 22 |
class Wpvr_Activator { |
| 23 |
|
| 24 |
/** |
| 25 |
* Short Description. (use period) |
| 26 |
* |
| 27 |
* Long Description. |
| 28 |
* |
| 29 |
* @since 8.0.0 |
| 30 |
*/ |
| 31 |
public static function activate() { |
| 32 |
self::set_wpvr_activation_transients(); |
| 33 |
self::update_wpvr_version(); |
| 34 |
self::update_installed_time(); |
| 35 |
if (!get_option('wpvr_plugin_installed')) { |
| 36 |
global $wpdb; |
| 37 |
$existing_items = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'wpvr_item'"); |
| 38 |
if ($existing_items == 0) { |
| 39 |
self::create_wpvr_sample_tour(); |
| 40 |
} |
| 41 |
update_option('wpvr_plugin_installed', time()); |
| 42 |
} |
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
/** |
| 48 |
* Update WPVR version to current. |
| 49 |
* |
| 50 |
* @since 1.0.0 |
| 51 |
*/ |
| 52 |
private static function update_wpvr_version() |
| 53 |
{ |
| 54 |
update_site_option('wpvr_version', WPVR_VERSION); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
/** |
| 61 |
* See if we need to redirect the admin to setup wizard or not. |
| 62 |
* |
| 63 |
* @since 1.0.0 |
| 64 |
*/ |
| 65 |
private static function set_wpvr_activation_transients() |
| 66 |
{ |
| 67 |
if (self::is_new_install()) { |
| 68 |
set_transient('_wpvr_activation_redirect', 1, 30); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Brand new install of WPVR |
| 74 |
* |
| 75 |
* @return bool |
| 76 |
* @since 1.0.0 |
| 77 |
*/ |
| 78 |
public static function is_new_install() |
| 79 |
{ |
| 80 |
return is_null(get_site_option('wpvr_version', null)); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
/** |
| 86 |
* Retrieve the time when WPVR is installed |
| 87 |
* |
| 88 |
* @return int|mixed|void |
| 89 |
* @since 2.0.0 |
| 90 |
*/ |
| 91 |
public static function get_installed_time() { |
| 92 |
$installed_time = get_option( 'wpvr_installed_time' ); |
| 93 |
if ( ! $installed_time ) { |
| 94 |
$installed_time = time(); |
| 95 |
update_site_option( 'wpvr_installed_time', $installed_time ); |
| 96 |
} |
| 97 |
return $installed_time; |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Update the time when WPVR is installed |
| 102 |
* |
| 103 |
* @since 2.0.0 |
| 104 |
*/ |
| 105 |
public static function update_installed_time() { |
| 106 |
self::get_installed_time(); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Create a sample tour for the user |
| 111 |
* |
| 112 |
* @since 8.5.21 |
| 113 |
*/ |
| 114 |
public static function create_wpvr_sample_tour(){ |
| 115 |
require_once WPVR_PLUGIN_DIR_PATH . 'admin/classes/class-wpvr-sample-tour.php'; |
| 116 |
$sample_tour_instance = new WPVR_Sample_Tour(); |
| 117 |
$wpvr_is_run_in_wp_playground = $sample_tour_instance->wpvr_is_playground(); |
| 118 |
if ($wpvr_is_run_in_wp_playground) { |
| 119 |
return; |
| 120 |
} |
| 121 |
$sample_tour_instance->create_sample_tour(); |
| 122 |
} |
| 123 |
} |
| 124 |
|