| 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 |
} |