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 / functions / admin.php

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

164 lines 4.6 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 * Check if Imagify is activated on the network.
6 *
7 * @since 1.0
8 *
9 * return bool True if Imagify is activated on the network
10 */
11 function imagify_is_active_for_network() {
12 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
13 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
14 }
15 return is_plugin_active_for_network( 'imagify/imagify.php' );
16 }
17
18 /*
19 * Get the URL related to specific admin page or action.
20 *
21 * @since 1.0
22 *
23 * @return string The URL of the specific admin page or action
24 */
25 function get_imagify_admin_url( $action = 'options-general', $arg = array() ) {
26 $url = '';
27 $id = ( isset( $arg['attachment_id'] ) ) ? $arg['attachment_id'] : 0;
28 $context = ( isset( $arg['context'] ) ) ? $arg['context'] : 'wp';
29
30 switch( $action ) {
31 case 'manual-override-upload':
32 $level = ( isset( $arg['optimization_level'] ) ) ? $arg['optimization_level'] : 0;
33 $url = wp_nonce_url( admin_url( 'admin-post.php?action=imagify_manual_override_upload&attachment_id=' . $id . '&optimization_level=' . $level . '&context=' . $context ), 'imagify-manual-override-upload' );
34 break;
35
36 case 'manual-upload':
37 $url = wp_nonce_url( admin_url( 'admin-post.php?action=imagify_manual_upload&attachment_id=' . $id . '&context=' . $context ), 'imagify-manual-upload' );
38 break;
39
40 case 'restore-upload' :
41 $url = wp_nonce_url( admin_url( 'admin-post.php?action=imagify_restore_upload&attachment_id=' . $id . '&context=' . $context ), 'imagify-restore-upload' );
42 break;
43
44 case 'dismiss-notice':
45 $url = wp_nonce_url( admin_url( 'admin-post.php?action=imagify_dismiss_notice&notice=' . $arg ), 'imagify-dismiss-notice' );
46 break;
47
48 case 'bulk-optimization':
49 $url = admin_url( 'upload.php?page=' . IMAGIFY_SLUG . '-bulk-optimization' );
50 break;
51
52 case 'options-general':
53 default :
54 $page = imagify_is_active_for_network() ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' );
55 $url = $page . '?page=' . IMAGIFY_SLUG;
56 break;
57 }
58
59 return $url;
60 }
61
62 /*
63 * Get maximal width and height from all thumbnails.
64 *
65 * @since 1.1
66 *
67 * @return array An array containing the max with and height.
68 */
69 function get_imagify_max_intermediate_image_size() {
70 global $_wp_additional_image_sizes;
71
72 $width = 0;
73 $height = 0;
74 $limit = 9999;
75 $get_intermediate_image_sizes = get_intermediate_image_sizes();
76
77 // Create the full array with sizes and crop info
78 foreach( $get_intermediate_image_sizes as $_size ) {
79 if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ) ) ) {
80 $_size_width = get_option( $_size . '_size_w' );
81 $_size_height = get_option( $_size . '_size_h' );
82 } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
83 $_size_width = $_wp_additional_image_sizes[ $_size ]['width'];
84 $_size_height = $_wp_additional_image_sizes[ $_size ]['height'];
85 }
86
87 if ( ! isset( $_size_width, $_size_height ) ) {
88 continue;
89 }
90
91 if ( $_size_width < $limit ) {
92 $width = max( $width, $_size_width );
93 }
94
95 if ( $_size_height < $limit ) {
96 $height = max( $height, $_size_height );
97 }
98 }
99 return array(
100 'width' => $width,
101 'height' => $height
102 );
103 }
104
105 /**
106 * Renew a dismissed Imagify notice.
107 *
108 * @since 1.0
109 *
110 * @return void
111 */
112 function imagify_renew_notice( $notice, $user_id = 0 ) {
113 global $current_user;
114 $user_id = ( 0 === $user_id ) ? $current_user->ID : $user_id;
115 $notices = get_user_meta( $user_id, '_imagify_ignore_notices', true );
116
117 if( $notices && false !== array_search( $notice, $notices ) ) {
118 unset( $notices[array_search( $notice, $notices )] );
119 update_user_meta( $user_id, '_imagify_ignore_notices', $notices );
120 }
121 }
122
123 /**
124 * Dismissed an Imagify notice.
125 *
126 * @since 1.0
127 *
128 * @return void
129 */
130 function imagify_dismiss_notice( $notice, $user_id = 0 ) {
131 global $current_user;
132 $user_id = ( 0 === $user_id ) ? $current_user->ID : $user_id;
133 $notices = get_user_meta( $user_id, '_imagify_ignore_notices', true );
134 $notices[] = $notice;
135 $notices = array_filter( $notices );
136 $notices = array_unique( $notices );
137
138 update_user_meta( $user_id, '_imagify_ignore_notices', $notices );
139 }
140
141 /**
142 * Combine two arrays with some specific keys.
143 * We use this function to combine the result of 2 SQL queries.
144 *
145 * @since 1.4.5
146 *
147 * @return array $result The combined array
148 */
149 function imagify_query_results_combine( $keys, $values ) {
150 if ( ! $values ) {
151 return array();
152 }
153
154 $result = array();
155 $keys = array_flip( $keys );
156
157 foreach ( $values as $v ) {
158 if ( isset( $keys[ $v['id'] ] ) ) {
159 $result[ $v['id'] ] = $v['value'];
160 }
161 }
162
163 return $result;
164 }