| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
use Elementor\Core\Kits\Manager; |
| 5 |
use Elementor\Core\Upgrade\Manager as Upgrade_Manager; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Elementor maintenance. |
| 13 |
* |
| 14 |
* Elementor maintenance handler class is responsible for setting up Elementor |
| 15 |
* activation and uninstallation hooks. |
| 16 |
* |
| 17 |
* @since 1.0.0 |
| 18 |
*/ |
| 19 |
class Maintenance { |
| 20 |
|
| 21 |
/** |
| 22 |
* Activate Elementor. |
| 23 |
* |
| 24 |
* Set Elementor activation hook. |
| 25 |
* |
| 26 |
* Fired by `register_activation_hook` when the plugin is activated. |
| 27 |
* |
| 28 |
* @param bool $network_wide |
| 29 |
* @since 1.0.0 |
| 30 |
* @access public |
| 31 |
* @static |
| 32 |
*/ |
| 33 |
public static function activation( $network_wide ) { |
| 34 |
wp_clear_scheduled_hook( 'elementor/tracker/send_event' ); |
| 35 |
|
| 36 |
wp_schedule_event( time(), 'daily', 'elementor/tracker/send_event' ); |
| 37 |
flush_rewrite_rules(); |
| 38 |
|
| 39 |
if ( is_multisite() && $network_wide ) { |
| 40 |
static::create_default_kit( |
| 41 |
get_sites( [ |
| 42 |
'fields' => 'ids', |
| 43 |
] ) |
| 44 |
); |
| 45 |
|
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
static::create_default_kit(); |
| 50 |
static::insert_defaults_options(); |
| 51 |
|
| 52 |
set_transient( 'elementor_activation_redirect', true, MINUTE_IN_SECONDS ); |
| 53 |
} |
| 54 |
|
| 55 |
public static function insert_defaults_options() { |
| 56 |
$history = Upgrade_Manager::get_installs_history(); |
| 57 |
if ( empty( $history ) ) { |
| 58 |
$default_options = [ |
| 59 |
'elementor_font_display' => 'swap', |
| 60 |
]; |
| 61 |
foreach ( $default_options as $option_name => $option_value ) { |
| 62 |
if ( \Elementor\Utils::is_empty( get_option( $option_name ) ) ) { |
| 63 |
add_option( $option_name, $option_value ); |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
public static function deactivation() { |
| 70 |
Api::get_deactivation_data(); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Uninstall Elementor. |
| 75 |
* |
| 76 |
* Set Elementor uninstallation hook. |
| 77 |
* |
| 78 |
* Fired by `register_uninstall_hook` when the plugin is uninstalled. |
| 79 |
* |
| 80 |
* @since 1.0.0 |
| 81 |
* @access public |
| 82 |
* @static |
| 83 |
*/ |
| 84 |
public static function uninstall() { |
| 85 |
wp_clear_scheduled_hook( 'elementor/tracker/send_event' ); |
| 86 |
|
| 87 |
Api::get_uninstalled_data(); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Init. |
| 92 |
* |
| 93 |
* Initialize Elementor Maintenance. |
| 94 |
* |
| 95 |
* @since 1.0.0 |
| 96 |
* @access public |
| 97 |
* @static |
| 98 |
*/ |
| 99 |
public static function init() { |
| 100 |
register_activation_hook( ELEMENTOR_PLUGIN_BASE, [ __CLASS__, 'activation' ] ); |
| 101 |
register_deactivation_hook( ELEMENTOR_PLUGIN_BASE, [ __CLASS__, 'deactivation' ] ); |
| 102 |
register_uninstall_hook( ELEMENTOR_PLUGIN_BASE, [ __CLASS__, 'uninstall' ] ); |
| 103 |
|
| 104 |
add_action( 'wpmu_new_blog', function ( $site_id ) { |
| 105 |
if ( ! is_plugin_active_for_network( ELEMENTOR_PLUGIN_BASE ) ) { |
| 106 |
return; |
| 107 |
} |
| 108 |
|
| 109 |
static::create_default_kit( [ $site_id ] ); |
| 110 |
} ); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* @param array $site_ids |
| 115 |
*/ |
| 116 |
private static function create_default_kit( array $site_ids = [] ) { |
| 117 |
if ( ! empty( $site_ids ) ) { |
| 118 |
foreach ( $site_ids as $site_id ) { |
| 119 |
switch_to_blog( $site_id ); |
| 120 |
|
| 121 |
Manager::create_default_kit(); |
| 122 |
|
| 123 |
restore_current_blog(); |
| 124 |
} |
| 125 |
|
| 126 |
return; |
| 127 |
} |
| 128 |
|
| 129 |
Manager::create_default_kit(); |
| 130 |
} |
| 131 |
} |
| 132 |
|