PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.5
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.5
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
imagify / inc / admin / media.php

media.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.5, at inc/admin/media.php

66 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
3
4 /*
5 * Add "Imagify" column in the Media Uploader
6 *
7 * @since 1.2
8 * @author Jonathan Buttigieg
9 */
10 add_filter( 'attachment_fields_to_edit', '_imagify_attachment_fields_to_edit', PHP_INT_MAX, 2 );
11 function _imagify_attachment_fields_to_edit( $form_fields, $post ) {
12 global $pagenow;
13 if ( 'post.php' == $pagenow ) {
14 return $form_fields;
15 }
16
17 $attachment = new Imagify_Attachment( $post->ID );
18
19 $form_fields['imagify'] = array(
20 'label' => 'Imagify',
21 'input' => 'html',
22 'html' => get_imagify_media_column_content( $attachment ),
23 'show_in_edit' => true,
24 'show_in_modal' => true,
25 );
26
27 return $form_fields;
28 }
29
30 /**
31 * Add "Compare Original VS Optimized" link to the media row action
32 *
33 * @since 1.4.3
34 * @author Geoffrey Crofte
35 */
36 add_filter( 'media_row_actions', '_imagify_add_actions_to_media_list_row', PHP_INT_MAX, 2 );
37 function _imagify_add_actions_to_media_list_row( $actions, $post ) {
38 // if this attachment is not an image, do nothing
39 if ( ! wp_attachment_is_image( $post->ID ) ) {
40 return $actions;
41 }
42
43 $attachment = new Imagify_Attachment();
44
45 // if Imagify license not valid, or image is not optimized, do nothing
46 if ( ! imagify_valid_key() || ! $attachment->is_optimized() ) {
47 return $actions;
48 }
49
50 // if was not activated for that image, do nothing
51 if ( '' === $attachment->get_backup_url() ) {
52 return $actions;
53 }
54
55 $image = wp_get_attachment_image_src( $post->ID, 'full' );
56
57 // if full image is too small
58 if ( (int) $image[1] < 360 ) {
59 return $actions;
60 }
61
62 // else, add action link for comparison (JS triggered)
63 $actions['imagify-compare'] = '<a href="' . get_edit_post_link( $post->ID ) . '#imagify-compare" data-id="' . $post->ID . '" data-backup-src="' . $attachment->get_backup_url() . '" data-full-src="' . $image[0] . '" data-full-width="' . $image[1] . '" data-full-height="' . $image[2] . '" data-target="#imagify-comparison-' . $post->ID . '" class="imagify-compare-images imagify-modal-trigger">' . esc_html__('Compare Original VS Optimized', 'imagify') . '</a>';
64
65 return $actions;
66 }