PluginProbe
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress / 3.0.0
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress v3.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 / admin / class-settings.php

class-settings.php in QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress 3.0.0, at admin/class-settings.php

192 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The admin-specific functionality of the plugin.
4 *
5 * @link http://webdeclic.com
6 * @since 1.0.0
7 *
8 * @package Quickwebp
9 * @subpackage Quickwebp/admin
10 */
11 class Quickwebp_Settings {
12
13 /**
14 * The ID of this plugin.
15 *
16 * @since 1.0.0
17 * @access private
18 * @var string $plugin_name The ID of this plugin.
19 */
20 private $plugin_name;
21
22 /**
23 * The version of this plugin.
24 *
25 * @since 1.0.0
26 * @access private
27 * @var string $version The current version of this plugin.
28 */
29 private $version;
30
31 /**
32 * Initialize the class and set its properties.
33 *
34 * @since 1.0.0
35 * @param string $plugin_name The name of this plugin.
36 * @param string $version The version of this plugin.
37 */
38 public function __construct( $plugin_name, $version ) {
39
40 $this->plugin_name = $plugin_name;
41 $this->version = $version;
42
43 }
44
45 /**
46 * Enqueue scripts and styles
47 *
48 */
49 public function enqueue_scripts_styles( $hook_suffix ) {
50 if ( $hook_suffix == 'toplevel_page_quickwebp-settings' || $hook_suffix == 'media_page_quickwebp-settings' ) {
51
52 $admin_main_settings_assets = include( QUICKWEBP_PLUGIN_PATH . 'public/assets/build/admin-main-settings.asset.php' );
53 wp_enqueue_style( 'quickwebpoi_admin_main_settings', QUICKWEBP_PLUGIN_URL . 'public/assets/build/admin-main-settings.css', array(), $admin_main_settings_assets['version'], 'all' );
54 wp_enqueue_script( 'quickwebpoi_admin_main_settings', QUICKWEBP_PLUGIN_URL . 'public/assets/build/admin-main-settings.js', $admin_main_settings_assets['dependencies'], $admin_main_settings_assets['version'], true );
55 wp_localize_script( 'quickwebpoi_admin_main_settings', 'QUICKWEBP_ADMIN_SETTINGS', array(
56 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
57 'nonce' => wp_create_nonce( 'image_optimize_nonce' ),
58 ));
59 }
60 }
61
62 /**
63 * add_settings_menu
64 *
65 * @return void
66 */
67 public function add_settings_menu() {
68 add_submenu_page(
69 'upload.php',
70 __('Quickwebp Settings', QUICKWEBP_TEXT_DOMAIN),
71 __('Quickwebp', QUICKWEBP_TEXT_DOMAIN),
72 'manage_options',
73 'quickwebp-settings',
74 array( $this, 'render_settings_page' )
75 );
76 }
77
78 /**
79 * render_settings_page
80 *
81 * @return void
82 */
83 public function render_settings_page() {
84 require_once QUICKWEBP_PLUGIN_PATH . 'admin/templates/page-settings.php';
85 }
86
87 /**
88 * render_component
89 *
90 * @param mixed $data
91 * @return void
92 */
93 public function render_component( $data = array() ) {
94 $data['type'] = $data['type'] ?? 'text';
95 $data['name'] = $data['name'] ?? '';
96 $file_name = $data['type'] == 'text' || $data['type'] == 'email' || $data['type'] == 'tel' || $data['type'] == 'number' ? 'text' : $data['type'];
97 $path_to_component = QUICKWEBP_PLUGIN_PATH . 'admin/components/' . $file_name . '.php';
98
99 if( file_exists( $path_to_component ) ) {
100 ?>
101 <tr>
102 <th>
103 <label for="<?php echo esc_attr( $data['name'] ?? '' ); ?>"><?php echo esc_html( $data['label'] ?? '' ); ?></label>
104 </th>
105 <td class="<?php echo esc_attr( $data['name'] ?? '' ); ?>-container">
106 <?php include $path_to_component; ?>
107 <?php if( isset( $data['description'] ) ) {
108 ?>
109 <p class="description"><?php echo esc_html( $data['description'] ); ?></p>
110 <?php
111 }
112 ?>
113 </td>
114 </tr>
115 <?php
116 }
117 }
118
119 /**
120 * Add the settings link
121 */
122 public function add_settings_link( $plugin_actions, $plugin_file ) {
123
124 $new_actions = array();
125
126 if ( 'quickwebp/quickwebp.php' === $plugin_file ) {
127
128 $new_actions['settings'] = sprintf( __( '<a href="%s">Settings</a>', QUICKWEBP_TEXT_DOMAIN ), esc_url( admin_url( 'upload.php?page=quickwebp-settings' ) ) );
129 }
130
131 return array_merge( $new_actions, $plugin_actions );
132 }
133
134 /**
135 * Show notice
136 */
137 public function show_notice_if_library_not_exist() {
138
139 $library_to_use = get_option( 'quickwebp_settings_library', quickwebp_settings_default('quickwebp_settings_library') );
140
141 switch ($library_to_use) {
142 case 'gd':
143
144 if ( ! extension_loaded('gd') ) {
145 add_action( 'admin_notices', function() {
146 ?>
147 <div class="notice notice-error">
148 <p><?php _e( 'Oops! QuickWebP needs the GD library to function properly, but it looks like the library is not installed on your server.', QUICKWEBP_TEXT_DOMAIN ); ?></p>
149 <p><?php _e( 'Please contact your hosting provider and ask them to install the GD library for PHP. They should be able to assist you with this process. Once the library is installed, QuickWebP should work as expected.', QUICKWEBP_TEXT_DOMAIN ); ?></p>
150 <p><?php _e( 'Thank you for using QuickWebP!', QUICKWEBP_TEXT_DOMAIN ); ?></p>
151 </div>
152 <?php
153 });
154 }
155
156 break;
157
158 case 'imagick':
159
160 if ( ! extension_loaded('imagick') ) {
161 add_action( 'admin_notices', function() {
162 ?>
163 <div class="notice notice-error">
164 <p><?php _e( 'Oops! QuickWebP needs the Imagick library to function properly, but it looks like the library is not installed on your server.', QUICKWEBP_TEXT_DOMAIN ); ?></p>
165 <p><?php _e( 'Please contact your hosting provider and ask them to install the Imagick library for PHP. They should be able to assist you with this process. Once the library is installed, QuickWebP should work as expected.', QUICKWEBP_TEXT_DOMAIN ); ?></p>
166 <p><?php _e( 'Thank you for using QuickWebP!', QUICKWEBP_TEXT_DOMAIN ); ?></p>
167 </div>
168 <?php
169 });
170 }
171
172 break;
173
174 default:
175
176 add_action( 'admin_notices', function() {
177 ?>
178 <div class="notice notice-error">
179 <p><?php _e( 'Oops! QuickWebP needs the Imagick or GD library to function properly, but it looks like the no Imagick nor GD is not installed on your server.', QUICKWEBP_TEXT_DOMAIN ); ?></p>
180 <p><?php _e( 'Please contact your hosting provider and ask them to install the Imagick or GD library for PHP. They should be able to assist you with this process. Once the library is installed, QuickWebP should work as expected.', QUICKWEBP_TEXT_DOMAIN ); ?></p>
181 <p><?php _e( 'Thank you for using QuickWebP!', QUICKWEBP_TEXT_DOMAIN ); ?></p>
182 </div>
183 <?php
184 });
185
186 break;
187 }
188
189
190 }
191
192 }