__( 'Optimized','imagify' ), 'unoptimized' => __( 'Unoptimized','imagify' ), 'errors' => __( 'Errors','imagify' ), ); echo ''; echo ' '; } add_filter( 'request', '_imagify_sort_attachments_by_status' ); /** * Modify the query based on the imagify-status variable in $_GET. * * @since 1.0 * @author Jonathan Buttigieg * * @param array $vars The array of requested query variables. * @return array */ function _imagify_sort_attachments_by_status( $vars ) { if ( 'upload.php' !== $GLOBALS['pagenow'] || empty( $_GET['imagify-status'] ) ) { // WPCS: CSRF ok. return $vars; } $status = $_GET['imagify-status']; // WPCS: CSRF ok. $meta_key = '_imagify_status'; $meta_compare = '='; $relation = array(); switch ( $status ) { case 'unoptimized': $meta_key = '_imagify_data'; $meta_compare = 'NOT EXISTS'; break; case 'optimized': $status = 'success'; $relation = array( 'key' => $meta_key, 'value' => 'already_optimized', 'compare' => $meta_compare, ); break; case 'errors': $status = 'error'; break; default: return $vars; } $vars = array_merge( $vars, array( 'meta_query' => array( 'relation' => 'or', array( 'key' => $meta_key, 'value' => $status, 'compare' => $meta_compare, ), $relation, ), ) ); $vars['post_mime_type'] = imagify_get_mime_types(); return $vars; }