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/meta-boxes.php +79 -20 1.3.6.1 → trunk View file →
@@ -1,31 +1,90 @@
1 1 <?php
2 -defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
2 +defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
3 3
4 +add_action( 'attachment_submitbox_misc_actions', '_imagify_attachment_submitbox_misc_actions', IMAGIFY_INT_MAX );
4 5 /**
5 - * Add a "Optimize It" button or the Imagify optimization data in the attachment submit area
6 + * Add a "Optimize It" button or the Imagify optimization data in the attachment submit area.
6 7 *
7 8 * @since 1.0
8 9 */
9 -add_action( 'attachment_submitbox_misc_actions', '_imagify_attachment_submitbox_misc_actions', PHP_INT_MAX );
10 10 function _imagify_attachment_submitbox_misc_actions() {
11 - /** This filter is documented in inc/admin/options.php */
12 - if ( current_user_can( apply_filters( 'imagify_capacity', 'manage_options' ) ) ) {
13 - global $post;
14 - $attachment = new Imagify_Attachment();
11 + global $post;
15 12
16 - if ( ! imagify_valid_key() && ! $attachment->is_optimized() ) {
17 - echo '<div class="misc-pub-section misc-pub-imagify"><h4>' . __( 'Imagify', 'imagify' ) . '</h4></div>';
18 - echo '<div class="misc-pub-section misc-pub-imagify">';
19 - echo __( 'Invalid API key', 'imagify' );
20 - echo '<br/>';
21 - echo '<a href="' . get_imagify_admin_url( 'options-general' ) . '">' . __( 'Check your Settings', 'imagify' ) . '</a>';
22 - echo '</div>';
23 - } elseif ( $attachment->is_optimized() || $attachment->has_error() ) {
24 - echo '<div class="misc-pub-section misc-pub-imagify"><h4>' . __( 'Imagify', 'imagify' ) . '</h4></div>';
25 - echo get_imagify_attachment_optimization_text( $post->ID );
13 + if ( ! imagify_get_context( 'wp' )->current_user_can( 'manual-optimize', $post->ID ) ) {
14 + return;
15 + }
16 +
17 + $process = imagify_get_optimization_process( $post->ID, 'wp' );
18 +
19 + if ( ! $process->is_valid() ) {
20 + return;
21 + }
22 +
23 + $media = $process->get_media();
24 +
25 + if ( ! $media->is_supported() ) {
26 + return;
27 + }
28 +
29 + if ( ! $media->has_required_media_data() ) {
30 + return;
31 + }
32 +
33 + $data = $process->get_data();
34 + $views = Imagify_Views::get_instance();
35 +
36 + if ( ! Imagify_Requirements::is_api_key_valid() && ! $data->is_optimized() ) {
37 + ?>
38 + <div class="misc-pub-section misc-pub-imagify"><h4><?php esc_html_e( 'Imagify', 'imagify' ); ?></h4></div>
39 + <div class="misc-pub-section misc-pub-imagify">
40 + <?php esc_html_e( 'Invalid API key', 'imagify' ); ?>
41 + <br/>
42 + <a href="<?php echo esc_url( get_imagify_admin_url() ); ?>">
43 + <?php esc_html_e( 'Check your Settings', 'imagify' ); ?>
44 + </a>
45 + </div>
46 + <?php
47 + } else {
48 + $is_locked = $process->is_locked();
49 +
50 + if ( $is_locked ) {
51 + switch ( $is_locked ) {
52 + case 'optimizing':
53 + $lock_label = __( 'Optimizing...', 'imagify' );
54 + break;
55 + case 'restoring':
56 + $lock_label = __( 'Restoring...', 'imagify' );
57 + break;
58 + default:
59 + $lock_label = __( 'Processing...', 'imagify' );
60 + }
61 + ?>
62 + <div class="misc-pub-section misc-pub-imagify">
63 + <?php $views->print_template( 'button/processing', [ 'label' => $lock_label ] ); ?>
64 + </div>
65 + <?php
66 + } elseif ( $data->is_optimized() || $data->is_already_optimized() || $data->is_error() ) {
67 + ?>
68 + <div class="misc-pub-section misc-pub-imagify"><h4><?php esc_html_e( 'Imagify', 'imagify' ); ?></h4></div>
69 + <div class="misc-pub-section misc-pub-imagify imagify-data-item">
70 + <?php echo get_imagify_attachment_optimization_text( $process ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
71 + </div>
72 + <?php
26 73 } else {
27 - $url = get_imagify_admin_url( 'manual-upload', $post->ID );
28 - printf( '<div class="misc-pub-section misc-pub-imagify"><a class="button-primary" href="%s">%s</a></div>', $url, __( 'Optimize', 'imagify' ) );
74 + $url = get_imagify_admin_url( 'optimize', [ 'attachment_id' => $post->ID ] );
75 + ?>
76 + <div class="misc-pub-section misc-pub-imagify">
77 + <a class="button-primary" href="<?php echo esc_url( $url ); ?>"><?php esc_html_e( 'Optimize', 'imagify' ); ?></a>
78 + </div>
79 + <?php
29 80 }
30 81 }
31 -}
82 +
83 + if ( $media->has_backup() && $data->is_optimized() ) {
84 + ?>
85 + <input id="imagify-full-original" type="hidden" value="<?php echo esc_url( $media->get_backup_url() ); ?>">
86 + <input id="imagify-full-original-size" type="hidden" value="<?php echo esc_attr( $data->get_original_size() ); ?>">
87 + <input id="imagify-full-optimized-size" type="hidden" value="<?php echo esc_attr( $data->get_optimized_size() ); ?>">
88 + <?php
89 + }
90 +}