| 1 |
<?php |
| 2 |
/** |
| 3 |
* Statify: Statify_Install class |
| 4 |
* |
| 5 |
* This file contains the derived class for the plugin's installation features. |
| 6 |
* |
| 7 |
* @package Statify |
| 8 |
* @since 0.1 |
| 9 |
*/ |
| 10 |
|
| 11 |
// Quit if accessed outside WP context. |
| 12 |
defined( 'ABSPATH' ) || exit; |
| 13 |
|
| 14 |
/** |
| 15 |
* Statify_Install |
| 16 |
* |
| 17 |
* @since 0.1 |
| 18 |
* @version 2016-12-20 |
| 19 |
*/ |
| 20 |
class Statify_Install { |
| 21 |
|
| 22 |
/** |
| 23 |
* Plugin activation handler. |
| 24 |
* |
| 25 |
* @since 0.1.0 |
| 26 |
* |
| 27 |
* @param bool $network_wide Whether the plugin was activated network-wide or not. |
| 28 |
*/ |
| 29 |
public static function init( $network_wide = false ) { |
| 30 |
|
| 31 |
if ( $network_wide && is_multisite() ) { |
| 32 |
$sites = get_sites(); |
| 33 |
|
| 34 |
// Create tables for each site in a network. |
| 35 |
foreach ( $sites as $site ) { |
| 36 |
// Convert object to array. |
| 37 |
$site = (array) $site; |
| 38 |
|
| 39 |
switch_to_blog( $site['blog_id'] ); |
| 40 |
self::_apply(); |
| 41 |
} |
| 42 |
|
| 43 |
restore_current_blog(); |
| 44 |
} else { |
| 45 |
self::_apply(); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Sets up the plugin for a newly created site on Multisite. |
| 51 |
* |
| 52 |
* @since 1.4.4 |
| 53 |
* |
| 54 |
* @param int $site_id Site ID. |
| 55 |
*/ |
| 56 |
public function init_site( $site_id ) { |
| 57 |
|
| 58 |
switch_to_blog( (int) $site_id ); |
| 59 |
|
| 60 |
self::_apply(); |
| 61 |
|
| 62 |
restore_current_blog(); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Creates the database tables needed for the plugin. |
| 67 |
* |
| 68 |
* @since 0.1.0 |
| 69 |
* @version 1.4.0 |
| 70 |
*/ |
| 71 |
private static function _apply() { |
| 72 |
|
| 73 |
// Cleanup any leftover transients. |
| 74 |
delete_transient( 'statify_data' ); |
| 75 |
|
| 76 |
// Set up the cron event. |
| 77 |
if ( ! wp_next_scheduled( 'statify_cleanup' ) ) { |
| 78 |
wp_schedule_event( |
| 79 |
time(), |
| 80 |
'daily', |
| 81 |
'statify_cleanup' |
| 82 |
); |
| 83 |
} |
| 84 |
|
| 85 |
// Create the actual tables. |
| 86 |
Statify_Table::init(); |
| 87 |
Statify_Table::create(); |
| 88 |
} |
| 89 |
} |
| 90 |
|