| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' ); |
| 3 |
|
| 4 |
/** |
| 5 |
* Add a "Optimize It" button or the Imagify optimization data in the attachment submit area |
| 6 |
* |
| 7 |
* @since 1.0 |
| 8 |
*/ |
| 9 |
add_action( 'attachment_submitbox_misc_actions', '_imagify_attachment_submitbox_misc_actions', PHP_INT_MAX ); |
| 10 |
function _imagify_attachment_submitbox_misc_actions() { |
| 11 |
/** This filter is documented in inc/admin/options.php */ |
| 12 |
if ( current_user_can( apply_filters( 'imagify_capacity', 'manage_options' ) ) ) { |
| 13 |
global $post; |
| 14 |
$attachment = new Imagify_Attachment(); |
| 15 |
|
| 16 |
if ( ! imagify_valid_key() && ! $attachment->is_optimized() ) { |
| 17 |
echo '<div class="misc-pub-section misc-pub-imagify"><h4>' . __( 'Imagify', 'imagify' ) . '</h4></div>'; |
| 18 |
echo '<div class="misc-pub-section misc-pub-imagify">'; |
| 19 |
echo __( 'Invalid API key', 'imagify' ); |
| 20 |
echo '<br/>'; |
| 21 |
echo '<a href="' . get_imagify_admin_url( 'options-general' ) . '">' . __( 'Check your Settings', 'imagify' ) . '</a>'; |
| 22 |
echo '</div>'; |
| 23 |
} elseif ( $attachment->is_optimized() || $attachment->has_error() ) { |
| 24 |
echo '<div class="misc-pub-section misc-pub-imagify"><h4>' . __( 'Imagify', 'imagify' ) . '</h4></div>'; |
| 25 |
echo get_imagify_attachment_optimization_text( $post->ID ); |
| 26 |
} elseif ( false !== get_transient( 'imagify-async-in-progress-' . $post->ID ) ) { |
| 27 |
echo '<div class="misc-pub-section misc-pub-imagify">'; |
| 28 |
echo '<div class="button"><span class="imagify-spinner"></span>'; |
| 29 |
_e( 'Optimizing...', 'imagify' ); |
| 30 |
echo '</div>'; |
| 31 |
echo '</div>'; |
| 32 |
} else { |
| 33 |
$url = get_imagify_admin_url( 'manual-upload', $post->ID ); |
| 34 |
printf( '<div class="misc-pub-section misc-pub-imagify"><a class="button-primary" href="%s">%s</a></div>', $url, __( 'Optimize', 'imagify' ) ); |
| 35 |
} |
| 36 |
|
| 37 |
if ( $attachment->is_optimized() ) { |
| 38 |
echo '<input id="imagify-full-original" type="hidden" value="' . $attachment->get_backup_url() . '">'; |
| 39 |
echo '<input id="imagify-full-original-size" type="hidden" value="' . $attachment->get_original_size() . '">'; |
| 40 |
} |
| 41 |
} |
| 42 |
} |