PluginProbe
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress / 4.1.1
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress v4.1.1
4.1.1 4.1.0 4.0.1 4.0.0 3.3.1 3.3.0 trunk 1.0.0 2.0.0 2.1.0 3.0.0 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8
quickwebp / includes / class-quickwebp.php

class-quickwebp.php in QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress 4.1.1, at includes/class-quickwebp.php

287 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The file that defines the core plugin class
5 *
6 * A class definition that includes attributes and functions used across both the
7 * public-facing side of the site and the admin area.
8 *
9 * @link http://webdeclic.com
10 * @since 1.0.0
11 *
12 * @package Quickwebp
13 * @subpackage Quickwebp/includes
14 */
15
16 /**
17 * The core plugin class.
18 *
19 * This is used to define internationalization, admin-specific hooks, and
20 * public-facing site hooks.
21 *
22 * Also maintains the unique identifier of this plugin as well as the current
23 * version of the plugin.
24 *
25 * @since 1.0.0
26 * @package Quickwebp
27 * @subpackage Quickwebp/includes
28 * @author Webdeclic <contact@webdeclic.com>
29 */
30 class Quickwebp {
31
32 /**
33 * The loader that's responsible for maintaining and registering all hooks that power
34 * the plugin.
35 *
36 * @since 1.0.0
37 * @access protected
38 * @var Quickwebp_Loader $loader Maintains and registers all hooks for the plugin.
39 */
40 protected $loader;
41
42 /**
43 * The unique identifier of this plugin.
44 *
45 * @since 1.0.0
46 * @access protected
47 * @var string $plugin_name The string used to uniquely identify this plugin.
48 */
49 protected $plugin_name;
50
51 /**
52 * The current version of the plugin.
53 *
54 * @since 1.0.0
55 * @access protected
56 * @var string $version The current version of the plugin.
57 */
58 protected $version;
59
60 /**
61 * Define the core functionality of the plugin.
62 *
63 * Set the plugin name and the plugin version that can be used throughout the plugin.
64 * Load the dependencies, define the locale, and set the hooks for the admin area and
65 * the public-facing side of the site.
66 *
67 * @since 1.0.0
68 */
69 public function __construct() {
70 if ( defined( 'QUICKWEBP_VERSION' ) ) {
71 $this->version = QUICKWEBP_VERSION;
72 } else {
73 $this->version = '1.0.0';
74 }
75 $this->plugin_name = 'quickwebp';
76
77 $this->load_dependencies();
78 $this->set_locale();
79 $this->define_admin_hooks();
80 $this->define_public_hooks();
81
82 }
83
84 /**
85 * Load the required dependencies for this plugin.
86 *
87 * Include the following files that make up the plugin:
88 *
89 * - Quickwebp_Loader. Orchestrates the hooks of the plugin.
90 * - Quickwebp_i18n. Defines internationalization functionality.
91 * - Quickwebp_Admin. Defines all hooks for the admin area.
92 * - Quickwebp_Public. Defines all hooks for the public side of the site.
93 *
94 * Create an instance of the loader which will be used to register the hooks
95 * with WordPress.
96 *
97 * @since 1.0.0
98 * @access private
99 */
100 private function load_dependencies() {
101
102 /**
103 * The class responsible for loading composer dependencies.
104 */
105 require_once QUICKWEBP_PLUGIN_PATH . 'includes/vendor/autoload.php';
106
107 /**
108 * The class responsible for orchestrating the actions and filters of the
109 * core plugin.
110 */
111 require_once QUICKWEBP_PLUGIN_PATH . 'includes/class-quickwebp-loader.php';
112
113 /**
114 * The global functions for this plugin
115 */
116 require_once QUICKWEBP_PLUGIN_PATH . 'includes/global-functions.php';
117
118 /**
119 * The class responsible for defining internationalization functionality
120 * of the plugin.
121 */
122 require_once QUICKWEBP_PLUGIN_PATH . 'includes/class-quickwebp-i18n.php';
123
124 /**
125 * The class responsible of settings.
126 */
127 require_once QUICKWEBP_PLUGIN_PATH . 'admin/class-settings.php';
128
129 /**
130 * The core functionality for image optimizing
131 */
132 require_once QUICKWEBP_PLUGIN_PATH . 'admin/class-image-optimizer.php';
133
134 /**
135 * The core functionality for wp media extending
136 */
137 require_once QUICKWEBP_PLUGIN_PATH . 'admin/class-wp-media-extends.php';
138
139 /**
140 * The class responsible of cron job.
141 */
142 require_once QUICKWEBP_PLUGIN_PATH . 'admin/class-cron-job.php';
143
144 /**
145 * The class responsible for handling the surecart.
146 */
147 require_once QUICKWEBP_PLUGIN_PATH . 'admin/class-surecart.php';
148
149 /**
150 * The class responsible for handling the migration.
151 */
152 require_once QUICKWEBP_PLUGIN_PATH . 'admin/class-migration.php';
153
154 /**
155 * The handle the front-end display functionality of the plugin.
156 */
157 require_once QUICKWEBP_PLUGIN_PATH . 'public/class-display-webp.php';
158
159 $this->loader = new Quickwebp_Loader();
160
161 }
162
163 /**
164 * Define the locale for this plugin for internationalization.
165 *
166 * Uses the Quickwebp_i18n class in order to set the domain and to register the hook
167 * with WordPress.
168 *
169 * @since 1.0.0
170 * @access private
171 */
172 private function set_locale() {
173
174 $plugin_i18n = new Quickwebp_i18n();
175
176 $this->loader->add_action( 'init', $plugin_i18n, 'load_plugin_textdomain' );
177
178 }
179
180 /**
181 * Register all of the hooks related to the admin area functionality
182 * of the plugin.
183 *
184 * @since 1.0.0
185 * @access private
186 */
187 private function define_admin_hooks() {
188
189 $quickwebp_settings = new Quickwebp_Settings( $this->get_plugin_name(), $this->get_version() );
190 $this->loader->add_action( 'admin_enqueue_scripts', $quickwebp_settings, 'enqueue_scripts_styles' );
191 $this->loader->add_action( 'admin_menu', $quickwebp_settings, 'add_settings_menu' );
192 $this->loader->add_action( 'admin_init', $quickwebp_settings, 'dismiss_avif_notice' );
193 $this->loader->add_action( 'admin_notices', $quickwebp_settings, 'render_avif_notice' );
194 $this->loader->add_filter( 'plugin_action_links', $quickwebp_settings, 'add_settings_link', 10, 2 );
195 $this->loader->add_filter( 'sanitize_option_quickwebp_settings_conversion_display_webp_mode', $quickwebp_settings, 'add_rewrite_rules', 5 );
196 $this->loader->add_filter( 'sanitize_option_quickwebp_settings_conversion_display_webp_mode', $quickwebp_settings, 'sanitize_display_mode_for_consistency', 10, 3 );
197
198 $quickwebp_image_optimizer = new Quickwebp_Image_Optimizer( $this->get_plugin_name(), $this->get_version() );
199 $this->loader->add_filter( 'wp_handle_upload_prefilter', $quickwebp_image_optimizer, 'image_optimization' );
200 $this->loader->add_filter( 'wp_generate_attachment_metadata', $quickwebp_image_optimizer, 'add_already_optimized_meta', 10, 3 );
201 $this->loader->add_filter( 'wp_generate_attachment_metadata', $quickwebp_image_optimizer, 'save_original_image', 10, 3 );
202 $this->loader->add_filter( 'wp_generate_attachment_metadata', $quickwebp_image_optimizer, 'add_data_to_attachment', 10, 3 );
203 $this->loader->add_filter( 'big_image_size_threshold', $quickwebp_image_optimizer, 'change_wp_max_size', PHP_INT_MAX, 2 );
204 $this->loader->add_filter( 'wp_editor_set_quality', $quickwebp_image_optimizer, 'change_wp_quality', PHP_INT_MAX );
205 $this->loader->add_action( 'wp_ajax_image_optimization_ajax', $quickwebp_image_optimizer, 'image_optimization_ajax' );
206 $this->loader->add_action( 'wp_ajax_single_optimization_ajax', $quickwebp_image_optimizer, 'single_optimization_ajax' );
207 $this->loader->add_action( 'wp_ajax_undo_single_optimization_ajax', $quickwebp_image_optimizer, 'undo_single_optimization_ajax' );
208 $this->loader->add_action( 'delete_attachment', $quickwebp_image_optimizer, 'before_delete_attachment' );
209 $this->loader->add_action( 'wp_ajax_get_image_data_for_preview', $quickwebp_image_optimizer, 'get_image_data_for_preview_ajax' );
210
211 $quickwebp_wp_media_extends = new Quickwebp_Wp_Media_Extends( $this->get_plugin_name(), $this->get_version() );
212 $this->loader->add_action( 'admin_enqueue_scripts', $quickwebp_wp_media_extends, 'enqueue_scripts' );
213 $this->loader->add_filter( 'attachment_fields_to_edit', $quickwebp_wp_media_extends, 'add_attachment_fields_to_edit', PHP_INT_MAX, 2 );
214 $this->loader->add_filter( 'manage_media_columns', $quickwebp_wp_media_extends, 'add_media_columns');
215 $this->loader->add_action( 'manage_media_custom_column', $quickwebp_wp_media_extends, 'add_media_custom_column', 10, 2 );
216 $this->loader->add_action( 'attachment_submitbox_misc_actions', $quickwebp_wp_media_extends, 'add_attachment_submitbox_misc_actions', PHP_INT_MAX );
217
218 $quickwebp_cron_job = new Quickwebp_Cron_Job( $this->get_plugin_name(), $this->get_version() );
219 $this->loader->add_filter( 'cron_schedules', $quickwebp_cron_job, 'crons_registrations' );
220 $this->loader->add_action( 'quickwebp_bulk_optimization_hook', $quickwebp_cron_job, 'excute_bulk_optimization' );
221 $this->loader->add_action( 'wp_ajax_start_bulk_optimization', $quickwebp_cron_job, 'start_bulk_optimization' );
222 $this->loader->add_action( 'wp_ajax_stop_bulk_optimization', $quickwebp_cron_job, 'stop_bulk_optimization' );
223 $this->loader->add_action( 'wp_ajax_check_bulk_optimization_progress', $quickwebp_cron_job, 'check_bulk_optimization_progress' );
224
225 $quickwebp_surecart = new Quickwebp_Surecart();
226 $this->loader->add_action( 'init', $quickwebp_surecart, 'init_surecart' );
227 $this->loader->add_action( 'admin_enqueue_scripts', $quickwebp_surecart, 'enqueue_scripts_styles' );
228
229 $quickwebp_migration = new Quickwebp_Migration();
230 $this->loader->add_action( 'admin_init', $quickwebp_migration, 'init_migration' );
231 }
232
233 /**
234 * Register all of the hooks related to the public-facing functionality
235 * of the plugin.
236 *
237 * @since 1.0.0
238 * @access private
239 */
240 private function define_public_hooks() {
241
242 $quickwebp_display_webp = new Quickwebp_Display_Webp( $this->get_plugin_name(), $this->get_version() );
243 $this->loader->add_action( 'template_redirect', $quickwebp_display_webp, 'start_content_process', -1000 );
244 }
245
246 /**
247 * Run the loader to execute all of the hooks with WordPress.
248 *
249 * @since 1.0.0
250 */
251 public function run() {
252 $this->loader->run();
253 }
254
255 /**
256 * The name of the plugin used to uniquely identify it within the context of
257 * WordPress and to define internationalization functionality.
258 *
259 * @since 1.0.0
260 * @return string The name of the plugin.
261 */
262 public function get_plugin_name() {
263 return $this->plugin_name;
264 }
265
266 /**
267 * The reference to the class that orchestrates the hooks with the plugin.
268 *
269 * @since 1.0.0
270 * @return Quickwebp_Loader Orchestrates the hooks of the plugin.
271 */
272 public function get_loader() {
273 return $this->loader;
274 }
275
276 /**
277 * Retrieve the version number of the plugin.
278 *
279 * @since 1.0.0
280 * @return string The version number of the plugin.
281 */
282 public function get_version() {
283 return $this->version;
284 }
285
286 }
287