| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); |
| 3 |
|
| 4 |
/** |
| 5 |
* Main plugin class. |
| 6 |
*/ |
| 7 |
class Imagify_Plugin { |
| 8 |
/** |
| 9 |
* Absolute path to the plugin (with trailing slash). |
| 10 |
* |
| 11 |
* @var string |
| 12 |
* @since 1.9 |
| 13 |
* @access private |
| 14 |
* @author Grégory Viguier |
| 15 |
*/ |
| 16 |
private $plugin_path; |
| 17 |
|
| 18 |
/** |
| 19 |
* Require files. |
| 20 |
* |
| 21 |
* @since 1.9 |
| 22 |
* @access public |
| 23 |
* @author Grégory Viguier |
| 24 |
* |
| 25 |
* @param array $plugin_args { |
| 26 |
* An array of arguments. |
| 27 |
* |
| 28 |
* @type string $plugin_path Absolute path to the plugin (with trailing slash). |
| 29 |
* } |
| 30 |
*/ |
| 31 |
public function __construct( $plugin_args ) { |
| 32 |
$this->plugin_path = $plugin_args['plugin_path']; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Plugin init. |
| 37 |
* |
| 38 |
* @since 1.9 |
| 39 |
* @access public |
| 40 |
* @author Grégory Viguier |
| 41 |
*/ |
| 42 |
public function init() { |
| 43 |
$this->include_files(); |
| 44 |
|
| 45 |
class_alias( '\\Imagify\\Traits\\InstanceGetterTrait', '\\Imagify\\Traits\\FakeSingletonTrait' ); |
| 46 |
|
| 47 |
Imagify_Auto_Optimization::get_instance()->init(); |
| 48 |
Imagify_Options::get_instance()->init(); |
| 49 |
Imagify_Data::get_instance()->init(); |
| 50 |
Imagify_Folders_DB::get_instance()->init(); |
| 51 |
Imagify_Files_DB::get_instance()->init(); |
| 52 |
Imagify_Cron_Library_Size::get_instance()->init(); |
| 53 |
Imagify_Cron_Rating::get_instance()->init(); |
| 54 |
Imagify_Cron_Sync_Files::get_instance()->init(); |
| 55 |
\Imagify\Auth\Basic::get_instance()->init(); |
| 56 |
\Imagify\Job\MediaOptimization::get_instance()->init(); |
| 57 |
\Imagify\Stats\OptimizedMediaWithoutWebp::get_instance()->init(); |
| 58 |
|
| 59 |
if ( is_admin() ) { |
| 60 |
Imagify_Notices::get_instance()->init(); |
| 61 |
Imagify_Admin_Ajax_Post::get_instance()->init(); |
| 62 |
Imagify_Settings::get_instance()->init(); |
| 63 |
Imagify_Views::get_instance()->init(); |
| 64 |
\Imagify\Imagifybeat\Core::get_instance()->init(); |
| 65 |
\Imagify\Imagifybeat\Actions::get_instance()->init(); |
| 66 |
} |
| 67 |
|
| 68 |
if ( ! wp_doing_ajax() ) { |
| 69 |
Imagify_Assets::get_instance()->init(); |
| 70 |
} |
| 71 |
|
| 72 |
\Imagify\Webp\Display::get_instance()->init(); |
| 73 |
|
| 74 |
add_action( 'init', [ $this, 'maybe_activate' ] ); |
| 75 |
|
| 76 |
// Load plugin translations. |
| 77 |
imagify_load_translations(); |
| 78 |
|
| 79 |
/** |
| 80 |
* Fires when Imagify is fully loaded. |
| 81 |
* |
| 82 |
* @since 1.0 |
| 83 |
* @since 1.9 Added the class instance as parameter. |
| 84 |
* |
| 85 |
* @param \Imagify_Plugin $plugin Instance of this class. |
| 86 |
*/ |
| 87 |
do_action( 'imagify_loaded', $this ); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Include plugin files. |
| 92 |
* |
| 93 |
* @since 1.9 |
| 94 |
* @access public |
| 95 |
* @author Grégory Viguier |
| 96 |
*/ |
| 97 |
public function include_files() { |
| 98 |
if ( file_exists( $this->plugin_path . 'vendor/autoload.php' ) ) { |
| 99 |
require_once $this->plugin_path . 'vendor/autoload.php'; |
| 100 |
} |
| 101 |
|
| 102 |
$instance_getter_path = $this->plugin_path . 'classes/Traits/InstanceGetterTrait.php'; |
| 103 |
|
| 104 |
if ( file_exists( $instance_getter_path . '.suspected' ) && ! file_exists( $instance_getter_path ) ) { |
| 105 |
// Trolling greedy antiviruses. |
| 106 |
require_once $instance_getter_path . '.suspected'; |
| 107 |
} |
| 108 |
|
| 109 |
$inc_path = $this->plugin_path . 'inc/'; |
| 110 |
|
| 111 |
require_once $inc_path . 'deprecated/deprecated.php'; |
| 112 |
require_once $inc_path . 'deprecated/3rd-party.php'; |
| 113 |
require_once $inc_path . 'functions/compat.php'; |
| 114 |
require_once $inc_path . 'functions/common.php'; |
| 115 |
require_once $inc_path . 'functions/options.php'; |
| 116 |
require_once $inc_path . 'functions/formatting.php'; |
| 117 |
require_once $inc_path . 'functions/admin.php'; |
| 118 |
require_once $inc_path . 'functions/api.php'; |
| 119 |
require_once $inc_path . 'functions/media.php'; |
| 120 |
require_once $inc_path . 'functions/attachments.php'; |
| 121 |
require_once $inc_path . 'functions/process.php'; |
| 122 |
require_once $inc_path . 'functions/admin-ui.php'; |
| 123 |
require_once $inc_path . 'functions/admin-stats.php'; |
| 124 |
require_once $inc_path . 'functions/i18n.php'; |
| 125 |
require_once $inc_path . 'functions/partners.php'; |
| 126 |
require_once $inc_path . 'common/attachments.php'; |
| 127 |
require_once $inc_path . 'common/admin-bar.php'; |
| 128 |
require_once $inc_path . 'common/partners.php'; |
| 129 |
require_once $inc_path . '3rd-party/3rd-party.php'; |
| 130 |
|
| 131 |
if ( ! is_admin() ) { |
| 132 |
return; |
| 133 |
} |
| 134 |
|
| 135 |
require_once $inc_path . 'admin/upgrader.php'; |
| 136 |
require_once $inc_path . 'admin/upload.php'; |
| 137 |
require_once $inc_path . 'admin/media.php'; |
| 138 |
require_once $inc_path . 'admin/meta-boxes.php'; |
| 139 |
require_once $inc_path . 'admin/custom-folders.php'; |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Trigger a hook on plugin activation after the plugin is loaded. |
| 144 |
* |
| 145 |
* @since 1.9 |
| 146 |
* @access public |
| 147 |
* @see imagify_set_activation() |
| 148 |
* @author Grégory Viguier |
| 149 |
*/ |
| 150 |
public function maybe_activate() { |
| 151 |
if ( imagify_is_active_for_network() ) { |
| 152 |
$user_id = get_site_transient( 'imagify_activation' ); |
| 153 |
} else { |
| 154 |
$user_id = get_transient( 'imagify_activation' ); |
| 155 |
} |
| 156 |
|
| 157 |
if ( ! is_numeric( $user_id ) ) { |
| 158 |
return; |
| 159 |
} |
| 160 |
|
| 161 |
if ( imagify_is_active_for_network() ) { |
| 162 |
delete_site_transient( 'imagify_activation' ); |
| 163 |
} else { |
| 164 |
delete_transient( 'imagify_activation' ); |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* Imagify activation. |
| 169 |
* |
| 170 |
* @since 1.9 |
| 171 |
* @author Grégory Viguier |
| 172 |
* |
| 173 |
* @param int $user_id ID of the user activating the plugin. |
| 174 |
*/ |
| 175 |
do_action( 'imagify_activation', (int) $user_id ); |
| 176 |
} |
| 177 |
} |
| 178 |
|