balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

maintenance.php (2146B)


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