PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.21
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.21
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / includes / class-wpo-activation.php

class-wpo-activation.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.21, at includes/class-wpo-activation.php

88 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) die('Access denied.');
3
4 if (!class_exists('WPO_Activation')) :
5
6 class WPO_Activation {
7
8 /**
9 * Actions to be performed upon plugin activation
10 */
11 public static function actions() {
12 if (is_multisite() && !is_network_admin()) {
13 self::deactivate_and_die();
14 }
15
16 if (!self::is_reactivated()) {
17 self::set_as_newly_activated();
18 }
19
20 WP_Optimize()->get_options()->set_default_options();
21 WP_Optimize()->get_minify()->plugin_activate();
22 WP_Optimize()->get_gzip_compression()->restore();
23 WP_Optimize()->get_browser_cache()->restore();
24
25 self::init_batch_processing();
26
27 if (self::is_premium()) {
28 self::init_premium();
29 }
30 }
31
32 /**
33 * When non network admin tries to activate plugin, deactivate it and die with a message
34 */
35 private static function deactivate_and_die() {
36 deactivate_plugins(plugin_basename(WPO_PLUGIN_MAIN_PATH . 'wp-optimize.php'));
37 wp_die(__('Only Network Administrator can activate WP-Optimize plugin.', 'wp-optimize') .
38 ' <a href="' . admin_url('plugins.php') . '">' . __('go back', 'wp-optimize') . '</a>');
39 }
40
41 /**
42 * Decides whether the plugin is newly installed and activated or already installed and reactivated
43 *
44 * @return mixed
45 */
46 private static function is_reactivated() {
47 return WP_Optimize()->get_options()->get_option('last-optimized', false);
48 }
49
50 /**
51 * Set plugin option `newly-activated` as `true`
52 */
53 private static function set_as_newly_activated() {
54 WP_Optimize()->get_options()->update_option('newly-activated', true);
55 }
56
57 /**
58 * Make use of Task Manager library
59 */
60 private static function init_batch_processing() {
61 if (!class_exists('Updraft_Tasks_Activation')) {
62 require_once(WPO_PLUGIN_MAIN_PATH . 'vendor/team-updraft/common-libs/src/updraft-tasks/class-updraft-tasks-activation.php');
63 }
64 Updraft_Tasks_Activation::init(WPO_PLUGIN_SLUG);
65 Updraft_Tasks_Activation::reinstall_if_needed();
66 }
67
68 /**
69 * Decides whether activate plugin is premium version or not
70 *
71 * @return bool
72 */
73 private static function is_premium() {
74 return file_exists(WPO_PLUGIN_MAIN_PATH . 'premium.php');
75 }
76
77 /**
78 * Run premium plugin activation actions
79 */
80 private static function init_premium() {
81 if (!class_exists('WP_Optimize_Premium')) {
82 include_once(WPO_PLUGIN_MAIN_PATH . 'premium.php');
83 }
84 WP_Optimize_Premium()->plugin_activation_actions();
85 }
86 }
87 endif;
88