PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.4.6
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.4.6
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.4.6, at inc/functions/admin.php

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