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 / upload.php

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

114 lines 3.0 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 * Add "Imagify" column in upload.php
6 *
7 * @since 1.0
8 * @author Jonathan Buttigieg
9 */
10 add_filter( 'manage_media_columns', '_imagify_manage_media_columns' );
11 function _imagify_manage_media_columns( $columns ) {
12 $columns['imagify_optimized_file'] = __( 'Imagify', 'imagify' );
13 return $columns;
14 }
15
16 add_filter( 'manage_media_custom_column', '_imagify_manage_media_custom_column', 10, 2 );
17 function _imagify_manage_media_custom_column( $column_name, $attachment_id ) {
18 if ( 'imagify_optimized_file' == $column_name ) {
19 $attachment = new Imagify_Attachment( $attachment_id );
20 echo get_imagify_media_column_content( $attachment );
21 }
22 }
23
24 /*
25 * Adds a dropdown that allows filtering on the attachments Imagify status.
26 *
27 * @since 1.0
28 * @author Jonathan Buttigieg
29 */
30 add_action( 'restrict_manage_posts', '_imagify_attachments_filter_dropdown' );
31 function _imagify_attachments_filter_dropdown() {
32 if ( 'upload.php' !== $GLOBALS['pagenow'] ) {
33 return;
34 }
35
36 $optimized = imagify_count_optimized_attachments();
37 $unoptimized = imagify_count_unoptimized_attachments();
38 $errors = imagify_count_error_attachments();
39 $status = ( isset( $_GET['imagify-status'] ) ) ? $_GET['imagify-status'] : 0;
40 $options = array(
41 'optimized' => __( 'Optimized','imagify' ),
42 'unoptimized' => __( 'Unoptimized','imagify' ),
43 'errors' => __( 'Errors','imagify' ),
44 );
45
46 $output = '<label class="screen-reader-text" for="filter-by-optimization-status">' . __( 'Filter by status','imagify' ) . '</label>';
47
48 $output .= '<select id="filter-by-optimization-status" name="imagify-status">';
49 $output .= '<option value="0" selected="selected">' . __( 'All images','imagify' ) . '</option>';
50
51 foreach( $options as $value => $label ) {
52 $output .= '<option value="' . $value . '" ' . selected( $status, $value, false ) . '>' . $label . ' (' . ${$value} . ')</option>';
53 }
54
55 $output .= '</select>&nbsp;';
56
57 echo $output;
58 }
59
60 /**
61 * Modify the query based on the imagify-status variable in $_GET
62 *
63 * @since 1.0
64 * @author Jonathan Buttigieg
65 */
66 add_filter( 'request', '_imagify_sort_attachments_by_status' );
67 function _imagify_sort_attachments_by_status( $vars ) {
68 if ( 'upload.php' !== $GLOBALS['pagenow'] || empty( $_GET['imagify-status'] ) ) {
69 return $vars;
70 }
71
72 $status = $_GET['imagify-status'];
73 $meta_key = '_imagify_status';
74 $meta_compare = '=';
75 $relation = array();
76
77 switch( $status ) {
78 case 'unoptimized':
79 $meta_key = '_imagify_data';
80 $meta_compare = 'NOT EXISTS';
81 break;
82
83 case 'optimized':
84 $status = 'success';
85 $relation = array(
86 'key' => $meta_key,
87 'value' => 'already_optimized',
88 'compare' => $meta_compare,
89 );
90 break;
91
92 case 'errors':
93 $status = 'error';
94 break;
95 }
96
97 $vars['post_mime_type'] = get_imagify_mime_type();
98 $vars = array_merge(
99 $vars,
100 array(
101 'meta_query' => array(
102 'relation' => 'or',
103 array(
104 'key' => $meta_key,
105 'value' => $status,
106 'compare' => $meta_compare,
107 ),
108 $relation
109 ),
110 )
111 );
112
113 return $vars;
114 }