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

64 lines 2.0 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 */
9 add_filter( 'attachment_fields_to_edit', '_imagify_attachment_fields_to_edit', PHP_INT_MAX, 2 );
10 function _imagify_attachment_fields_to_edit( $form_fields, $post ) {
11 global $pagenow;
12 if ( 'post.php' == $pagenow ) {
13 return $form_fields;
14 }
15
16 $form_fields['imagify'] = array(
17 'label' => 'Imagify',
18 'input' => 'html',
19 'html' => get_imagify_media_column_content( $post->ID ),
20 'show_in_edit' => true,
21 'show_in_modal' => true,
22 );
23
24 return $form_fields;
25 }
26
27 /**
28 * Add "Compare Original VS Optimized" link to the media row action
29 *
30 * @since 1.4.3
31 * @author Geoffrey Crofte
32 */
33 add_filter( 'media_row_actions', '_imagify_add_actions_to_media_list_row', PHP_INT_MAX, 2 );
34 function _imagify_add_actions_to_media_list_row( $actions, $post ) {
35
36 // if this attachment is not an image, do nothing
37 if ( ! wp_attachment_is_image( $post->ID ) ) {
38 return $actions;
39 }
40
41 $attachment = new Imagify_Attachment();
42
43 // if Imagify license not valid, or image is not optimized, do nothing
44 if ( ! imagify_valid_key() || ! $attachment->is_optimized() ) {
45 return $actions;
46 }
47
48 // if was not activated for that image, do nothing
49 if ( '' === $attachment->get_backup_url() ) {
50 return $actions;
51 }
52
53 $image = wp_get_attachment_image_src( $post->ID, 'full' );
54
55 // if full image is too small
56 if ( (int) $image[1] < 360 ) {
57 return $actions;
58 }
59
60 // else, add action link for comparison (JS triggered)
61 $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>';
62
63 return $actions;
64 }