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

188 lines 5.9 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 }
56 }
57
58 /**
59 * add_settings_menu
60 *
61 * @return void
62 */
63 public function add_settings_menu() {
64 add_submenu_page(
65 'upload.php',
66 __('Quickwebp Settings', QUICKWEBP_TEXT_DOMAIN),
67 __('Quickwebp', QUICKWEBP_TEXT_DOMAIN),
68 'manage_options',
69 'quickwebp-settings',
70 array( $this, 'render_settings_page' )
71 );
72 }
73
74 /**
75 * render_settings_page
76 *
77 * @return void
78 */
79 public function render_settings_page() {
80 require_once QUICKWEBP_PLUGIN_PATH . 'admin/templates/page-settings.php';
81 }
82
83 /**
84 * render_component
85 *
86 * @param mixed $data
87 * @return void
88 */
89 public function render_component( $data = array() ) {
90 $data['type'] = $data['type'] ?? 'text';
91 $data['name'] = $data['name'] ?? '';
92 $file_name = $data['type'] == 'text' || $data['type'] == 'email' || $data['type'] == 'tel' || $data['type'] == 'number' ? 'text' : $data['type'];
93 $path_to_component = QUICKWEBP_PLUGIN_PATH . 'admin/components/' . $file_name . '.php';
94
95 if( file_exists( $path_to_component ) ) {
96 ?>
97 <tr>
98 <th>
99 <label for="<?php echo esc_attr( $data['name'] ?? '' ); ?>"><?php echo esc_html( $data['label'] ?? '' ); ?></label>
100 </th>
101 <td class="<?php echo esc_attr( $data['name'] ?? '' ); ?>-container">
102 <?php include $path_to_component; ?>
103 <?php if( isset( $data['description'] ) ) {
104 ?>
105 <p class="description"><?php echo esc_html( $data['description'] ); ?></p>
106 <?php
107 }
108 ?>
109 </td>
110 </tr>
111 <?php
112 }
113 }
114
115 /**
116 * Add the settings link
117 */
118 public function add_settings_link( $plugin_actions, $plugin_file ) {
119
120 $new_actions = array();
121
122 if ( 'quickwebp/quickwebp.php' === $plugin_file ) {
123
124 $new_actions['settings'] = sprintf( __( '<a href="%s">Settings</a>', QUICKWEBP_TEXT_DOMAIN ), esc_url( admin_url( 'upload.php?page=quickwebp-settings' ) ) );
125 }
126
127 return array_merge( $new_actions, $plugin_actions );
128 }
129
130 /**
131 * Show notice
132 */
133 public function show_notice_if_library_not_exist() {
134
135 $library_to_use = get_option( 'quickwebp_settings_library', quickwebp_settings_default('quickwebp_settings_library') );
136
137 switch ($library_to_use) {
138 case 'gd':
139
140 if ( ! extension_loaded('gd') ) {
141 add_action( 'admin_notices', function() {
142 ?>
143 <div class="notice notice-error">
144 <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>
145 <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>
146 <p><?php _e( 'Thank you for using QuickWebP!', QUICKWEBP_TEXT_DOMAIN ); ?></p>
147 </div>
148 <?php
149 });
150 }
151
152 break;
153
154 case 'imagick':
155
156 if ( ! extension_loaded('imagick') ) {
157 add_action( 'admin_notices', function() {
158 ?>
159 <div class="notice notice-error">
160 <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>
161 <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>
162 <p><?php _e( 'Thank you for using QuickWebP!', QUICKWEBP_TEXT_DOMAIN ); ?></p>
163 </div>
164 <?php
165 });
166 }
167
168 break;
169
170 default:
171
172 add_action( 'admin_notices', function() {
173 ?>
174 <div class="notice notice-error">
175 <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>
176 <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>
177 <p><?php _e( 'Thank you for using QuickWebP!', QUICKWEBP_TEXT_DOMAIN ); ?></p>
178 </div>
179 <?php
180 });
181
182 break;
183 }
184
185
186 }
187
188 }