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

93 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) || die( 'Cheatin\' uh?' );
3
4 add_filter( 'attachment_fields_to_edit', '_imagify_attachment_fields_to_edit', IMAGIFY_INT_MAX, 2 );
5 /**
6 * Add "Imagify" column in the Media Uploader
7 *
8 * @since 1.2
9 * @author Jonathan Buttigieg
10 *
11 * @param array $form_fields An array of attachment form fields.
12 * @param object $post The WP_Post attachment object.
13 * @return array
14 */
15 function _imagify_attachment_fields_to_edit( $form_fields, $post ) {
16 global $pagenow;
17
18 if ( 'post.php' === $pagenow ) {
19 return $form_fields;
20 }
21
22 if ( ! imagify_current_user_can( 'manual-optimize', $post->ID ) ) {
23 return $form_fields;
24 }
25
26 $attachment = get_imagify_attachment( 'wp', $post->ID, 'attachment_fields_to_edit' );
27
28 $form_fields['imagify'] = array(
29 'label' => 'Imagify',
30 'input' => 'html',
31 'html' => get_imagify_media_column_content( $attachment ),
32 'show_in_edit' => true,
33 'show_in_modal' => true,
34 );
35
36 return $form_fields;
37 }
38
39 add_filter( 'media_row_actions', '_imagify_add_actions_to_media_list_row', IMAGIFY_INT_MAX, 2 );
40 /**
41 * Add "Compare Original VS Optimized" link to the media row action
42 *
43 * @since 1.4.3
44 * @author Geoffrey Crofte
45 * @param array $actions An array of action links for each attachment.
46 * Default 'Edit', 'Delete Permanently', 'View'.
47 * @param object $post WP_Post object for the current attachment.
48 * @return array
49 */
50 function _imagify_add_actions_to_media_list_row( $actions, $post ) {
51 if ( ! imagify_current_user_can( 'manual-optimize', $post->ID ) ) {
52 return $actions;
53 }
54
55 $attachment = get_imagify_attachment( 'wp', $post->ID, 'media_row_actions' );
56
57 // If this attachment is not an image, do nothing.
58 if ( ! $attachment->is_extension_supported() ) {
59 return $actions;
60 }
61
62 // If Imagify license not valid, or image is not optimized, do nothing.
63 if ( ! imagify_valid_key() || ! $attachment->is_optimized() ) {
64 return $actions;
65 }
66
67 // If was not activated for that image, do nothing.
68 if ( ! $attachment->get_backup_url() ) {
69 return $actions;
70 }
71
72 $image = wp_get_attachment_image_src( $post->ID, 'full' );
73
74 // If full image is too small. See get_imagify_localize_script_translations().
75 if ( ! $image || (int) $image[1] < 360 ) {
76 return $actions;
77 }
78
79 // Else, add action link for comparison (JS triggered).
80 $actions['imagify-compare'] = sprintf(
81 '<a href="%1$s#imagify-compare" data-id="%2$d" data-backup-src="%3$s" data-full-src="%4$s" data-full-width="%5$d" data-full-height="%6$d" data-target="#imagify-comparison-%2$d" class="imagify-compare-images imagify-modal-trigger">%7$s</a>',
82 esc_url( get_edit_post_link( $post->ID ) ),
83 $post->ID,
84 esc_url( $attachment->get_backup_url() ),
85 esc_url( $image[0] ),
86 $image[1],
87 $image[2],
88 esc_html__( 'Compare Original VS Optimized', 'imagify' )
89 );
90
91 return $actions;
92 }
93