admin-templates
1 year ago
base
1 year ago
container
1 year ago
controls
1 year ago
editor-templates
1 year ago
elements
1 year ago
interfaces
1 year ago
libraries
1 year ago
managers
1 year ago
settings
1 year ago
template-library
1 year ago
widgets
1 year ago
api.php
2 years ago
autoloader.php
1 year ago
beta-testers.php
3 years ago
compatibility.php
1 year ago
conditions.php
3 years ago
db.php
2 years ago
editor-assets-api.php
1 year ago
embed.php
1 year ago
fonts.php
1 year ago
frontend.php
1 year ago
heartbeat.php
3 years ago
maintenance-mode.php
2 years ago
maintenance.php
3 years ago
plugin.php
1 year ago
preview.php
1 year ago
rollback.php
3 years ago
shapes.php
1 year ago
stylesheet.php
1 year ago
tracker.php
2 years ago
user.php
2 years ago
utils.php
1 year ago
maintenance.php
124 lines
| 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 | * @since 1.0.0 |
| 29 | * @access public |
| 30 | * @static |
| 31 | */ |
| 32 | public static function activation( $network_wide ) { |
| 33 | wp_clear_scheduled_hook( 'elementor/tracker/send_event' ); |
| 34 | |
| 35 | wp_schedule_event( time(), 'daily', 'elementor/tracker/send_event' ); |
| 36 | flush_rewrite_rules(); |
| 37 | |
| 38 | if ( is_multisite() && $network_wide ) { |
| 39 | static::create_default_kit( |
| 40 | get_sites( [ |
| 41 | 'fields' => 'ids', |
| 42 | ] ) |
| 43 | ); |
| 44 | |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | static::create_default_kit(); |
| 49 | static::insert_defaults_options(); |
| 50 | |
| 51 | set_transient( 'elementor_activation_redirect', true, MINUTE_IN_SECONDS ); |
| 52 | } |
| 53 | |
| 54 | public static function insert_defaults_options() { |
| 55 | $history = Upgrade_Manager::get_installs_history(); |
| 56 | if ( empty( $history ) ) { |
| 57 | $default_options = [ |
| 58 | 'elementor_font_display' => 'swap', |
| 59 | ]; |
| 60 | foreach ( $default_options as $option_name => $option_value ) { |
| 61 | if ( \Elementor\Utils::is_empty( get_option( $option_name ) ) ) { |
| 62 | add_option( $option_name, $option_value ); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Uninstall Elementor. |
| 70 | * |
| 71 | * Set Elementor uninstallation hook. |
| 72 | * |
| 73 | * Fired by `register_uninstall_hook` when the plugin is uninstalled. |
| 74 | * |
| 75 | * @since 1.0.0 |
| 76 | * @access public |
| 77 | * @static |
| 78 | */ |
| 79 | public static function uninstall() { |
| 80 | wp_clear_scheduled_hook( 'elementor/tracker/send_event' ); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Init. |
| 85 | * |
| 86 | * Initialize Elementor Maintenance. |
| 87 | * |
| 88 | * @since 1.0.0 |
| 89 | * @access public |
| 90 | * @static |
| 91 | */ |
| 92 | public static function init() { |
| 93 | register_activation_hook( ELEMENTOR_PLUGIN_BASE, [ __CLASS__, 'activation' ] ); |
| 94 | register_uninstall_hook( ELEMENTOR_PLUGIN_BASE, [ __CLASS__, 'uninstall' ] ); |
| 95 | |
| 96 | add_action( 'wpmu_new_blog', function ( $site_id ) { |
| 97 | if ( ! is_plugin_active_for_network( ELEMENTOR_PLUGIN_BASE ) ) { |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | static::create_default_kit( [ $site_id ] ); |
| 102 | } ); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @param array $site_ids |
| 107 | */ |
| 108 | private static function create_default_kit( array $site_ids = [] ) { |
| 109 | if ( ! empty( $site_ids ) ) { |
| 110 | foreach ( $site_ids as $site_id ) { |
| 111 | switch_to_blog( $site_id ); |
| 112 | |
| 113 | Manager::create_default_kit(); |
| 114 | |
| 115 | restore_current_blog(); |
| 116 | }; |
| 117 | |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | Manager::create_default_kit(); |
| 122 | } |
| 123 | } |
| 124 |