| 1 |
<?php |
| 2 |
declare(strict_types=1); |
| 3 |
|
| 4 |
namespace Imagify\Media\Upload; |
| 5 |
|
| 6 |
/** |
| 7 |
* Upload Media Class. |
| 8 |
*/ |
| 9 |
class Upload { |
| 10 |
/** |
| 11 |
* Adds a dropdown that allows filtering on the attachments Imagify status. |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
public function add_imagify_filter_to_attachments_dropdown() { |
| 16 |
$data = []; |
| 17 |
|
| 18 |
/** |
| 19 |
* Tell if imagify stats query should run. |
| 20 |
* |
| 21 |
* @param bool $boolean True if the query should be run. False otherwise. |
| 22 |
*/ |
| 23 |
if ( wpm_apply_filters_typed( 'boolean', 'imagify_display_library_stats', false ) ) { |
| 24 |
$data['optimized'] = imagify_count_optimized_attachments(); |
| 25 |
$data['unoptimized'] = imagify_count_unoptimized_attachments(); |
| 26 |
$data['errors'] = imagify_count_error_attachments(); |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
$status = isset( $_GET['imagify-status'] ) ? sanitize_text_field( wp_unslash( $_GET['imagify-status'] ) ) : 0; |
| 31 |
$options = [ |
| 32 |
'optimized' => _x( 'Optimized', 'Media Files', 'imagify' ), |
| 33 |
'unoptimized' => _x( 'Unoptimized', 'Media Files', 'imagify' ), |
| 34 |
'errors' => _x( 'Errors', 'Media Files', 'imagify' ), |
| 35 |
]; |
| 36 |
|
| 37 |
echo '<label class="screen-reader-text" for="filter-by-optimization-status">' . esc_html__( 'Filter by status', 'imagify' ) . '</label>'; |
| 38 |
echo '<select id="filter-by-optimization-status" name="imagify-status">'; |
| 39 |
echo '<option value="0" selected="selected">' . esc_html__( 'All Media Files', 'imagify' ) . '</option>'; |
| 40 |
|
| 41 |
foreach ( $options as $value => $label ) { |
| 42 |
$filter_value = isset( $data[ $value ] ) ? ' (' . $data[ $value ] . ')' : ''; |
| 43 |
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $status, $value, false ) . '>' . esc_html( $label ) . esc_html( $filter_value ) . '</option>'; |
| 44 |
} |
| 45 |
echo '</select> '; |
| 46 |
} |
| 47 |
} |
| 48 |
|