PluginProbe
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress / 1.0.0
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress v1.0.0
4.1.2 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 1.0.0, at includes/class-quickwebp.php

234 lines 6.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 * This file is loaded only on local environement for test or debug.
115 */
116 if( $_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1' ){
117 require_once QUICKWEBP_PLUGIN_PATH. 'includes/dev-toolkits.php';
118 }
119
120 /**
121 * The global functions for this plugin
122 */
123 require_once QUICKWEBP_PLUGIN_PATH . 'includes/global-functions.php';
124
125 /**
126 * The class responsible for defining internationalization functionality
127 * of the plugin.
128 */
129 require_once QUICKWEBP_PLUGIN_PATH . 'includes/class-quickwebp-i18n.php';
130
131 /**
132 * The class responsible of settings.
133 */
134 require_once QUICKWEBP_PLUGIN_PATH . 'admin/class-settings.php';
135
136 /**
137 * The core functionality for image optimizing
138 */
139 require_once QUICKWEBP_PLUGIN_PATH . 'admin/class-image-optimizer.php';
140
141
142 $this->loader = new Quickwebp_Loader();
143
144 }
145
146 /**
147 * Define the locale for this plugin for internationalization.
148 *
149 * Uses the Quickwebp_i18n class in order to set the domain and to register the hook
150 * with WordPress.
151 *
152 * @since 1.0.0
153 * @access private
154 */
155 private function set_locale() {
156
157 $plugin_i18n = new Quickwebp_i18n();
158
159 $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
160
161 }
162
163 /**
164 * Register all of the hooks related to the admin area functionality
165 * of the plugin.
166 *
167 * @since 1.0.0
168 * @access private
169 */
170 private function define_admin_hooks() {
171
172 $quickwebp_settings = new Quickwebp_Settings( $this->get_plugin_name(), $this->get_version() );
173 $this->loader->add_action( 'admin_enqueue_scripts', $quickwebp_settings, 'enqueue_scripts_styles' );
174 $this->loader->add_action( 'admin_menu', $quickwebp_settings, 'add_settings_menu' );
175
176 $quickwebp_image_optimizer = new Quickwebp_Image_Optimizer( $this->get_plugin_name(), $this->get_version() );
177 $this->loader->add_filter( 'wp_handle_upload_prefilter', $quickwebp_image_optimizer, 'image_optimizition' );
178 $this->loader->add_filter( 'wp_generate_attachment_metadata', $quickwebp_image_optimizer, 'add_data_to_attachment', 10, 3 );
179
180 }
181
182 /**
183 * Register all of the hooks related to the public-facing functionality
184 * of the plugin.
185 *
186 * @since 1.0.0
187 * @access private
188 */
189 private function define_public_hooks() {
190
191 }
192
193 /**
194 * Run the loader to execute all of the hooks with WordPress.
195 *
196 * @since 1.0.0
197 */
198 public function run() {
199 $this->loader->run();
200 }
201
202 /**
203 * The name of the plugin used to uniquely identify it within the context of
204 * WordPress and to define internationalization functionality.
205 *
206 * @since 1.0.0
207 * @return string The name of the plugin.
208 */
209 public function get_plugin_name() {
210 return $this->plugin_name;
211 }
212
213 /**
214 * The reference to the class that orchestrates the hooks with the plugin.
215 *
216 * @since 1.0.0
217 * @return Quickwebp_Loader Orchestrates the hooks of the plugin.
218 */
219 public function get_loader() {
220 return $this->loader;
221 }
222
223 /**
224 * Retrieve the version number of the plugin.
225 *
226 * @since 1.0.0
227 * @return string The version number of the plugin.
228 */
229 public function get_version() {
230 return $this->version;
231 }
232
233 }
234