PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.9.4
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.9.4
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / classes / class-imagify-plugin.php

class-imagify-plugin.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.9.4, at inc/classes/class-imagify-plugin.php

170 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Job\MediaOptimization::get_instance()->init();
56 \Imagify\Stats\OptimizedMediaWithoutWebp::get_instance()->init();
57
58 if ( is_admin() ) {
59 Imagify_Notices::get_instance()->init();
60 Imagify_Admin_Ajax_Post::get_instance()->init();
61 Imagify_Settings::get_instance()->init();
62 Imagify_Views::get_instance()->init();
63 \Imagify\Imagifybeat\Core::get_instance()->init();
64 \Imagify\Imagifybeat\Actions::get_instance()->init();
65 }
66
67 if ( ! wp_doing_ajax() ) {
68 Imagify_Assets::get_instance()->init();
69 }
70
71 \Imagify\Webp\Display::get_instance()->init();
72
73 add_action( 'init', [ $this, 'maybe_activate' ] );
74
75 // Load plugin translations.
76 imagify_load_translations();
77
78 /**
79 * Fires when Imagify is fully loaded.
80 *
81 * @since 1.0
82 * @since 1.9 Added the class instance as parameter.
83 *
84 * @param \Imagify_Plugin $plugin Instance of this class.
85 */
86 do_action( 'imagify_loaded', $this );
87 }
88
89 /**
90 * Include plugin files.
91 *
92 * @since 1.9
93 * @access public
94 * @author Grégory Viguier
95 */
96 public function include_files() {
97 if ( file_exists( $this->plugin_path . 'vendor/autoload.php' ) ) {
98 require_once $this->plugin_path . 'vendor/autoload.php';
99 }
100
101 $inc_path = $this->plugin_path . 'inc/';
102
103 require_once $inc_path . 'deprecated/deprecated.php';
104 require_once $inc_path . 'deprecated/3rd-party.php';
105 require_once $inc_path . 'functions/compat.php';
106 require_once $inc_path . 'functions/common.php';
107 require_once $inc_path . 'functions/options.php';
108 require_once $inc_path . 'functions/formatting.php';
109 require_once $inc_path . 'functions/admin.php';
110 require_once $inc_path . 'functions/api.php';
111 require_once $inc_path . 'functions/media.php';
112 require_once $inc_path . 'functions/attachments.php';
113 require_once $inc_path . 'functions/process.php';
114 require_once $inc_path . 'functions/admin-ui.php';
115 require_once $inc_path . 'functions/admin-stats.php';
116 require_once $inc_path . 'functions/i18n.php';
117 require_once $inc_path . 'functions/partners.php';
118 require_once $inc_path . 'common/attachments.php';
119 require_once $inc_path . 'common/admin-bar.php';
120 require_once $inc_path . 'common/partners.php';
121 require_once $inc_path . '3rd-party/3rd-party.php';
122
123 if ( ! is_admin() ) {
124 return;
125 }
126
127 require_once $inc_path . 'admin/upgrader.php';
128 require_once $inc_path . 'admin/upload.php';
129 require_once $inc_path . 'admin/media.php';
130 require_once $inc_path . 'admin/meta-boxes.php';
131 require_once $inc_path . 'admin/custom-folders.php';
132 }
133
134 /**
135 * Trigger a hook on plugin activation after the plugin is loaded.
136 *
137 * @since 1.9
138 * @access public
139 * @see imagify_set_activation()
140 * @author Grégory Viguier
141 */
142 public function maybe_activate() {
143 if ( imagify_is_active_for_network() ) {
144 $user_id = get_site_transient( 'imagify_activation' );
145 } else {
146 $user_id = get_transient( 'imagify_activation' );
147 }
148
149 if ( ! is_numeric( $user_id ) ) {
150 return;
151 }
152
153 if ( imagify_is_active_for_network() ) {
154 delete_site_transient( 'imagify_activation' );
155 } else {
156 delete_transient( 'imagify_activation' );
157 }
158
159 /**
160 * Imagify activation.
161 *
162 * @since 1.9
163 * @author Grégory Viguier
164 *
165 * @param int $user_id ID of the user activating the plugin.
166 */
167 do_action( 'imagify_activation', (int) $user_id );
168 }
169 }
170