| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); | |
| 2 | +defined( 'ABSPATH' ) || exit; | |
| 3 | 3 | |
| 4 | 4 | add_filter( 'manage_media_columns', '_imagify_manage_media_columns' ); |
| 5 | 5 | /** |
| 6 | 6 | * Add "Imagify" column in upload.php. |
| @@ -35,43 +35,11 @@ | ||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $process = imagify_get_optimization_process( $attachment_id, 'wp' ); |
| 38 | 38 | |
| 39 | - echo get_imagify_media_column_content( $process ); | |
| 39 | + echo get_imagify_media_column_content( $process ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | -add_action( 'restrict_manage_posts', '_imagify_attachments_filter_dropdown' ); | |
| 43 | -/** | |
| 44 | - * Adds a dropdown that allows filtering on the attachments Imagify status. | |
| 45 | - * | |
| 46 | - * @since 1.0 | |
| 47 | - * @author Jonathan Buttigieg | |
| 48 | - */ | |
| 49 | -function _imagify_attachments_filter_dropdown() { | |
| 50 | - if ( ! Imagify_Views::get_instance()->is_wp_library_page() ) { | |
| 51 | - return; | |
| 52 | - } | |
| 53 | - | |
| 54 | - $optimized = imagify_count_optimized_attachments(); | |
| 55 | - $unoptimized = imagify_count_unoptimized_attachments(); | |
| 56 | - $errors = imagify_count_error_attachments(); | |
| 57 | - $status = isset( $_GET['imagify-status'] ) ? wp_unslash( $_GET['imagify-status'] ) : 0; // WPCS: CSRF ok. | |
| 58 | - $options = array( | |
| 59 | - 'optimized' => _x( 'Optimized', 'Media Files', 'imagify' ), | |
| 60 | - 'unoptimized' => _x( 'Unoptimized', 'Media Files', 'imagify' ), | |
| 61 | - 'errors' => _x( 'Errors', 'Media Files', 'imagify' ), | |
| 62 | - ); | |
| 63 | - | |
| 64 | - echo '<label class="screen-reader-text" for="filter-by-optimization-status">' . __( 'Filter by status', 'imagify' ) . '</label>'; | |
| 65 | - echo '<select id="filter-by-optimization-status" name="imagify-status">'; | |
| 66 | - echo '<option value="0" selected="selected">' . __( 'All Media Files', 'imagify' ) . '</option>'; | |
| 67 | - | |
| 68 | - foreach ( $options as $value => $label ) { | |
| 69 | - echo '<option value="' . $value . '" ' . selected( $status, $value, false ) . '>' . $label . ' (' . ${$value} . ')</option>'; | |
| 70 | - } | |
| 71 | - echo '</select> '; | |
| 72 | -} | |
| 73 | - | |
| 74 | 42 | add_filter( 'request', '_imagify_sort_attachments_by_status' ); |
| 75 | 43 | /** |
| 76 | 44 | * Modify the query based on the imagify-status variable in $_GET. |
| 77 | 45 | * |
| @@ -81,16 +49,16 @@ | ||
| 81 | 49 | * @param array $vars The array of requested query variables. |
| 82 | 50 | * @return array |
| 83 | 51 | */ |
| 84 | 52 | function _imagify_sort_attachments_by_status( $vars ) { |
| 85 | - if ( empty( $_GET['imagify-status'] ) || ! Imagify_Views::get_instance()->is_wp_library_page() ) { // WPCS: CSRF ok. | |
| 53 | + if ( empty( $_GET['imagify-status'] ) || ! Imagify_Views::get_instance()->is_wp_library_page() ) { | |
| 86 | 54 | return $vars; |
| 87 | 55 | } |
| 88 | 56 | |
| 89 | - $status = wp_unslash( $_GET['imagify-status'] ); // WPCS: CSRF ok. | |
| 57 | + $status = sanitize_text_field( wp_unslash( $_GET['imagify-status'] ) ); | |
| 90 | 58 | $meta_key = '_imagify_status'; |
| 91 | 59 | $meta_compare = '='; |
| 92 | - $relation = array(); | |
| 60 | + $relation = []; | |
| 93 | 61 | |
| 94 | 62 | switch ( $status ) { |
| 95 | 63 | case 'unoptimized': |
| 96 | 64 | $meta_key = '_imagify_data'; |
| @@ -97,13 +65,13 @@ | ||
| 97 | 65 | $meta_compare = 'NOT EXISTS'; |
| 98 | 66 | break; |
| 99 | 67 | case 'optimized': |
| 100 | 68 | $status = 'success'; |
| 101 | - $relation = array( | |
| 69 | + $relation = [ | |
| 102 | 70 | 'key' => $meta_key, |
| 103 | 71 | 'value' => 'already_optimized', |
| 104 | 72 | 'compare' => $meta_compare, |
| 105 | - ); | |
| 73 | + ]; | |
| 106 | 74 | break; |
| 107 | 75 | case 'errors': |
| 108 | 76 | $status = 'error'; |
| 109 | 77 | break; |
| @@ -110,20 +78,25 @@ | ||
| 110 | 78 | default: |
| 111 | 79 | return $vars; |
| 112 | 80 | } |
| 113 | 81 | |
| 114 | - $vars = array_merge( $vars, array( | |
| 115 | - 'meta_query' => array( | |
| 116 | - 'relation' => 'or', | |
| 117 | - array( | |
| 118 | - 'key' => $meta_key, | |
| 119 | - 'value' => $status, | |
| 120 | - 'compare' => $meta_compare, | |
| 121 | - ), | |
| 122 | - $relation, | |
| 123 | - ), | |
| 124 | - ) ); | |
| 82 | + $vars = array_merge( | |
| 83 | + $vars, | |
| 84 | + [ | |
| 85 | + 'meta_query' => [ | |
| 86 | + 'relation' => 'or', | |
| 87 | + [ | |
| 88 | + 'key' => $meta_key, | |
| 89 | + 'value' => $status, | |
| 90 | + 'compare' => $meta_compare, | |
| 91 | + ], | |
| 92 | + $relation, | |
| 93 | + ], | |
| 94 | + ] | |
| 95 | + ); | |
| 125 | 96 | |
| 126 | - $vars['post_mime_type'] = imagify_get_mime_types(); | |
| 97 | + if ( ! key_exists( 'post_mime_type', $vars ) ) { | |
| 98 | + $vars['post_mime_type'] = imagify_get_mime_types(); | |
| 99 | + } | |
| 127 | 100 | |
| 128 | 101 | return $vars; |
| 129 | 102 | } |