PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
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
← All changes | inc/admin/upload.php +59 -67 1.4 → trunk View file →
@@ -1,110 +1,102 @@
1 1 <?php
2 -defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
2 +defined( 'ABSPATH' ) || exit;
3 3
4 -/*
5 - * Add "Imagify" column in upload.php
4 +add_filter( 'manage_media_columns', '_imagify_manage_media_columns' );
5 +/**
6 + * Add "Imagify" column in upload.php.
6 7 *
7 - * @since 1.0
8 + * @since 1.0
9 + * @author Jonathan Buttigieg
10 + *
11 + * @param array $columns An array of columns displayed in the Media list table.
12 + * @return array
8 13 */
9 -add_filter( 'manage_media_columns', '_imagify_manage_media_columns' );
10 14 function _imagify_manage_media_columns( $columns ) {
11 - $columns['imagify_optimized_file'] = __( 'Imagify', 'imagify' );
15 + if ( imagify_get_context( 'wp' )->current_user_can( 'optimize' ) ) {
16 + $columns['imagify_optimized_file'] = __( 'Imagify', 'imagify' );
17 + }
18 +
12 19 return $columns;
13 20 }
14 21
15 -add_filter( 'manage_media_custom_column', '_imagify_manage_media_custom_column', 10, 2 );
16 -function _imagify_manage_media_custom_column( $column_name, $attachment_id ) {
17 - if ( 'imagify_optimized_file' == $column_name ) {
18 - echo get_imagify_media_column_content( $attachment_id );
19 - }
20 -}
21 -
22 -/*
23 - * Adds a dropdown that allows filtering on the attachments Imagify status.
22 +add_action( 'manage_media_custom_column', '_imagify_manage_media_custom_column', 10, 2 );
23 +/**
24 + * Add content to the "Imagify" columns in upload.php.
24 25 *
25 - * @since 1.0
26 + * @since 1.0
27 + * @author Jonathan Buttigieg
28 + *
29 + * @param string $column_name Name of the custom column.
30 + * @param int $attachment_id Attachment ID.
26 31 */
27 -add_action( 'restrict_manage_posts', '_imagify_attachments_filter_dropdown' );
28 -function _imagify_attachments_filter_dropdown() {
29 - if ( 'upload.php' !== $GLOBALS['pagenow'] ) {
32 +function _imagify_manage_media_custom_column( $column_name, $attachment_id ) {
33 + if ( 'imagify_optimized_file' !== $column_name ) {
30 34 return;
31 35 }
32 36
33 - $optimized = imagify_count_optimized_attachments();
34 - $unoptimized = imagify_count_unoptimized_attachments();
35 - $errors = imagify_count_error_attachments();
36 - $status = ( isset( $_GET['imagify-status'] ) ) ? $_GET['imagify-status'] : 0;
37 - $options = array(
38 - 'optimized' => __( 'Optimized','imagify' ),
39 - 'unoptimized' => __( 'Unoptimized','imagify' ),
40 - 'errors' => __( 'Errors','imagify' ),
41 - );
37 + $process = imagify_get_optimization_process( $attachment_id, 'wp' );
42 38
43 - $output = '<label class="screen-reader-text" for="filter-by-optimization-status">' . __( 'Filter by status','imagify' ) . '</label>';
44 -
45 - $output .= '<select id="filter-by-optimization-status" name="imagify-status">';
46 - $output .= '<option value="0" selected="selected">' . __( 'All images','imagify' ) . '</option>';
47 -
48 - foreach( $options as $value => $label ) {
49 - $output .= '<option value="' . $value . '" ' . selected( $status, $value, false ) . '>' . $label . ' (' . ${$value} . ')</option>';
50 - }
51 -
52 - $output .= '</select>&nbsp;';
53 -
54 - echo $output;
39 + echo get_imagify_media_column_content( $process ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
55 40 }
56 41
42 +add_filter( 'request', '_imagify_sort_attachments_by_status' );
57 43 /**
58 - * Modify the query based on the imagify-status variable in $_GET
44 + * Modify the query based on the imagify-status variable in $_GET.
59 45 *
60 - * @since 1.0
46 + * @since 1.0
47 + * @author Jonathan Buttigieg
48 + *
49 + * @param array $vars The array of requested query variables.
50 + * @return array
61 51 */
62 -add_filter( 'request', '_imagify_sort_attachments_by_status' );
63 52 function _imagify_sort_attachments_by_status( $vars ) {
64 - if ( 'upload.php' !== $GLOBALS['pagenow'] || empty( $_GET['imagify-status'] ) ) {
53 + if ( empty( $_GET['imagify-status'] ) || ! Imagify_Views::get_instance()->is_wp_library_page() ) {
65 54 return $vars;
66 55 }
67 -
68 - $status = $_GET['imagify-status'];
56 +
57 + $status = sanitize_text_field( wp_unslash( $_GET['imagify-status'] ) );
69 58 $meta_key = '_imagify_status';
70 59 $meta_compare = '=';
71 - $relation = array();
72 -
73 - switch( $status ) {
60 + $relation = [];
61 +
62 + switch ( $status ) {
74 63 case 'unoptimized':
75 64 $meta_key = '_imagify_data';
76 65 $meta_compare = 'NOT EXISTS';
77 - break;
78 -
66 + break;
79 67 case 'optimized':
80 68 $status = 'success';
81 - $relation = array(
69 + $relation = [
82 70 'key' => $meta_key,
83 71 'value' => 'already_optimized',
84 72 'compare' => $meta_compare,
85 - );
86 - break;
87 -
73 + ];
74 + break;
88 75 case 'errors':
89 76 $status = 'error';
90 - break;
77 + break;
78 + default:
79 + return $vars;
91 80 }
92 -
93 - $vars['post_mime_type'] = get_imagify_mime_type();
81 +
94 82 $vars = array_merge(
95 83 $vars,
96 - array(
97 - 'meta_query' => array(
84 + [
85 + 'meta_query' => [
98 86 'relation' => 'or',
99 - array(
87 + [
100 88 'key' => $meta_key,
101 89 'value' => $status,
102 90 'compare' => $meta_compare,
103 - ),
104 - $relation
105 - ),
106 - )
91 + ],
92 + $relation,
93 + ],
94 + ]
107 95 );
108 -
96 +
97 + if ( ! key_exists( 'post_mime_type', $vars ) ) {
98 + $vars['post_mime_type'] = imagify_get_mime_types();
99 + }
100 +
109 101 return $vars;
110 -}
102 +}