1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
<?php defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
add_filter( 'attachment_fields_to_edit', '_imagify_attachment_fields_to_edit', IMAGIFY_INT_MAX, 2 ); /** * Add "Imagify" column in the Media Uploader * * @since 1.2 * @author Jonathan Buttigieg * * @param array $form_fields An array of attachment form fields. * @param object $post The WP_Post attachment object. * @return array */ function _imagify_attachment_fields_to_edit( $form_fields, $post ) { global $pagenow;
if ( 'post.php' === $pagenow ) { return $form_fields; }
if ( ! imagify_get_context( 'wp' )->current_user_can( 'manual-optimize', $post->ID ) ) { return $form_fields; }
$process = imagify_get_optimization_process( $post->ID, 'wp' );
$form_fields['imagify'] = array( 'label' => 'Imagify', 'input' => 'html', 'html' => get_imagify_media_column_content( $process ), 'show_in_edit' => true, 'show_in_modal' => true, );
return $form_fields; }
add_filter( 'media_row_actions', '_imagify_add_actions_to_media_list_row', IMAGIFY_INT_MAX, 2 ); /** * Add "Compare Original VS Optimized" link to the media row action * * @since 1.4.3 * @author Geoffrey Crofte * @param array $actions An array of action links for each attachment. * Default 'Edit', 'Delete Permanently', 'View'. * @param object $post WP_Post object for the current attachment. * @return array */ function _imagify_add_actions_to_media_list_row( $actions, $post ) { if ( ! imagify_get_context( 'wp' )->current_user_can( 'manual-optimize', $post->ID ) ) { return $actions; }
$process = imagify_get_optimization_process( $post->ID, 'wp' );
if ( ! $process->is_valid() ) { return $actions; }
$media = $process->get_media();
// If this media is not an image, do nothing. if ( ! $media->is_supported() || ! $media->is_image() ) { return $actions; }
$data = $process->get_data();
// If Imagify license not valid, or image is not optimized, do nothing. if ( ! Imagify_Requirements::is_api_key_valid() || ! $data->is_optimized() ) { return $actions; }
// If no backup, do nothing. if ( ! $media->has_backup() ) { return $actions; }
$dimensions = $media->get_dimensions();
// If full image is too small. See get_imagify_localize_script_translations(). if ( $dimensions['width'] < 360 ) { return $actions; }
// Else, add action link for comparison (JS triggered). $actions['imagify-compare'] = Imagify_Views::get_instance()->get_template( 'button/compare-images', [ 'url' => get_edit_post_link( $media->get_id() ) . '#imagify-compare', 'backup_url' => $media->get_backup_url(), 'original_url' => $media->get_fullsize_url(), 'media_id' => $media->get_id(), 'width' => $dimensions['width'], 'height' => $dimensions['height'], ] );
return $actions; }
|