| 1 |
<?php |
| 2 |
|
| 3 |
namespace Templately\Core; |
| 4 |
|
| 5 |
class Maintenance { |
| 6 |
/** |
| 7 |
* Init Maintenance |
| 8 |
* |
| 9 |
* @since 2.0.1 |
| 10 |
* @return void |
| 11 |
*/ |
| 12 |
public static function init(){ |
| 13 |
register_activation_hook( TEMPLATELY_PLUGIN_BASENAME, [ __CLASS__, 'activation' ] ); |
| 14 |
register_uninstall_hook( TEMPLATELY_PLUGIN_BASENAME, [ __CLASS__, 'uninstall' ] ); |
| 15 |
register_deactivation_hook( TEMPLATELY_PLUGIN_BASENAME, [ __CLASS__, 'deactivation' ] ); |
| 16 |
add_action( 'admin_init', [ __CLASS__, 'maybe_redirect_templately' ] ); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Runs on activation |
| 21 |
* |
| 22 |
* @since 2.0.1 |
| 23 |
*/ |
| 24 |
public static function activation( $network_wide ) { |
| 25 |
if ( wp_doing_ajax() ) { |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
if ( is_multisite() && $network_wide ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
set_transient( 'templately_activation_redirect', true, MINUTE_IN_SECONDS ); |
| 34 |
} |
| 35 |
|
| 36 |
public static function deactivation() { |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Runs on uninstallation. |
| 41 |
* |
| 42 |
* @since 2.0.1 |
| 43 |
* @return void |
| 44 |
*/ |
| 45 |
public static function uninstall(){ |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Redirect on Active |
| 51 |
*/ |
| 52 |
public static function maybe_redirect_templately() { |
| 53 |
if ( ! get_transient( 'templately_activation_redirect' ) ) { |
| 54 |
return; |
| 55 |
} |
| 56 |
if ( wp_doing_ajax() ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
delete_transient( 'templately_activation_redirect' ); |
| 61 |
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
| 62 |
return; |
| 63 |
} |
| 64 |
// Safe Redirect to Templately Page |
| 65 |
wp_safe_redirect( admin_url( 'admin.php?page=templately&path=elementor/packs' ) ); |
| 66 |
exit; |
| 67 |
} |
| 68 |
} |
| 69 |
|