PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.5
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.5
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 / admin / options.php

options.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.5, at inc/admin/options.php

160 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
3
4 /**
5 * Fix the capability for our capacity filter hook
6 *
7 * @author Jonathan
8 * @since 1.0
9 */
10 add_filter( 'option_page_capability_imagify', '_imagify_correct_capability_for_options_page' );
11 function _imagify_correct_capability_for_options_page( $capability ) {
12 $cap = ( imagify_is_active_for_network() ) ? 'manage_network_options' : 'manage_options';
13 return apply_filters( 'imagify_capacity', $cap );
14 }
15
16 /**
17 * Tell to WordPress to be confident with our setting, we are clean!
18 *
19 * @author Jonathan
20 * @since 1.0
21 */
22 add_action( 'admin_init', '_imagify_register_setting' );
23 function _imagify_register_setting() {
24 register_setting( 'imagify', 'imagify_settings' );
25 }
26
27 /**
28 * Filter specific options before its value is (maybe) serialized and updated.
29 *
30 * @author Jonathan
31 * @since 1.0
32 */
33 add_filter( 'pre_update_option_' . IMAGIFY_SETTINGS_SLUG, '_imagify_pre_update_option', 10, 2 );
34 function _imagify_pre_update_option( $value, $old_value ) {
35 // Store all sizes even if one of them isn't checked
36 $value['disallowed-sizes'] = array();
37
38 if ( isset( $value['sizes'] ) ) {
39 foreach( $value['sizes'] as $size_key => $size_value ) {
40 if ( strpos( $size_key , '-hidden' ) ) {
41 $key = str_replace( '-hidden', '', $size_key );
42 if ( ! isset( $value['sizes'][ $key ] ) ) {
43 $value['disallowed-sizes'][ $key ] = '1';
44 }
45 }
46 }
47 }
48
49 // The max width for the "Resize larger images" option can't be 0
50 if ( (bool) ! $value['resize_larger_w'] ) {
51 $value['resize_larger_w'] = '';
52 $value['resize_larger'] = 0;
53 }
54
55 // The max width for the "Resize larger images" option can't be less than the largest thumbnail width
56 $max_sizes = get_imagify_max_intermediate_image_size();
57 if ( (bool) $value['resize_larger_w'] && $value['resize_larger_w'] < $max_sizes['width'] ) {
58 $value['resize_larger_w'] = $max_sizes['width'];
59 }
60
61 unset( $value['sizes'] );
62 return $value;
63 }
64
65 /**
66 * Used to launch some actions after saving the options
67 *
68 * @author Jonathan
69 * @since 1.0
70 * @since 1.5 Used to redirect user to Bulk Optimizer (if requested)
71 */
72 add_action( 'update_option_' . IMAGIFY_SETTINGS_SLUG, '_imagify_after_save_options', 10, 2 );
73 add_action( 'update_site_option_' . IMAGIFY_SETTINGS_SLUG, '_imagify_after_save_options', 10, 2 );
74 function _imagify_after_save_options( $oldvalue, $value ) {
75
76 if ( ! ( (bool) $oldvalue && (bool) $value ) ) {
77 return;
78 }
79
80 if ( ! isset( $oldvalue['api_key'] ) || $oldvalue['api_key'] != $value['api_key'] ) {
81 $api = new Imagify();
82
83 if ( is_wp_error( $api->getUser() ) ) {
84 imagify_renew_notice( 'wrong-api-key' );
85 delete_site_transient( 'imagify_check_licence_1' );
86 } else {
87 imagify_dismiss_notice( 'wrong-api-key' );
88 }
89 }
90
91 /**
92 * @author Geoffrey
93 * @since 1.5
94 */
95 if ( isset( $_POST['submit-goto-bulk'] ) ) {
96 wp_safe_redirect( get_admin_url( get_current_blog_id(), 'upload.php?page=imagify-bulk-optimization' ) );
97 exit;
98 }
99 }
100
101
102 if ( imagify_is_active_for_network() ) :
103
104 /**
105 * !options.php do not handle site options. Let's use admin-post.php for multisite installations.
106 *
107 * @since 1.0
108 */
109 add_action( 'admin_post_update', '_imagify_update_site_option_on_network' );
110 function _imagify_update_site_option_on_network() {
111 $option_group = IMAGIFY_SLUG;
112
113 if ( ! isset( $_POST['option_page'] ) || $_POST['option_page'] !== $option_group ) {
114 return;
115 }
116
117 $capability = apply_filters( "option_page_capability_{$option_group}", 'manage_network_options' );
118
119 if ( ! current_user_can( $capability ) ) {
120 wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
121 }
122
123 check_admin_referer( $option_group . '-options' );
124
125 $whitelist_options = apply_filters( 'whitelist_options', array() );
126
127 if ( ! isset( $whitelist_options[ $option_group ] ) ) {
128 wp_die( __( '<strong>ERROR</strong>: options page not found.' ) );
129 }
130
131 $options = $whitelist_options[ $option_group ];
132
133 if ( $options ) {
134
135 foreach ( $options as $option ) {
136 $option = trim( $option );
137 $value = null;
138
139 if ( isset( $_POST[ $option ] ) ) {
140 $value = $_POST[ $option ];
141 if ( ! is_array( $value ) ) {
142 $value = trim( $value );
143 }
144 $value = wp_unslash( $value );
145 }
146
147 update_site_option( $option, $value );
148 }
149
150 }
151
152 /**
153 * Redirect back to the settings page that was submitted
154 */
155 $goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
156 wp_redirect( $goback );
157 exit;
158 }
159
160 endif;