| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) || die( 'Cheatin\' uh?' ); |
| 3 |
|
| 4 |
add_action( 'attachment_submitbox_misc_actions', '_imagify_attachment_submitbox_misc_actions', IMAGIFY_INT_MAX ); |
| 5 |
/** |
| 6 |
* Add a "Optimize It" button or the Imagify optimization data in the attachment submit area. |
| 7 |
* |
| 8 |
* @since 1.0 |
| 9 |
*/ |
| 10 |
function _imagify_attachment_submitbox_misc_actions() { |
| 11 |
global $post; |
| 12 |
|
| 13 |
if ( ! imagify_current_user_can( 'manual-optimize', $post->ID ) ) { |
| 14 |
return; |
| 15 |
} |
| 16 |
|
| 17 |
$attachment = get_imagify_attachment( 'wp', $post->ID, 'attachment_submitbox_misc_actions' ); |
| 18 |
|
| 19 |
if ( ! $attachment->is_extension_supported() ) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
if ( ! $attachment->has_required_metadata() ) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
if ( ! imagify_valid_key() && ! $attachment->is_optimized() ) { |
| 28 |
|
| 29 |
echo '<div class="misc-pub-section misc-pub-imagify"><h4>' . __( 'Imagify', 'imagify' ) . '</h4></div>'; |
| 30 |
echo '<div class="misc-pub-section misc-pub-imagify">'; |
| 31 |
echo __( 'Invalid API key', 'imagify' ); |
| 32 |
echo '<br/>'; |
| 33 |
echo '<a href="' . esc_url( get_imagify_admin_url() ) . '">' . __( 'Check your Settings', 'imagify' ) . '</a>'; |
| 34 |
echo '</div>'; |
| 35 |
|
| 36 |
} elseif ( $attachment->is_optimized() || $attachment->has_error() ) { |
| 37 |
|
| 38 |
echo '<div class="misc-pub-section misc-pub-imagify"><h4>' . __( 'Imagify', 'imagify' ) . '</h4></div>'; |
| 39 |
echo get_imagify_attachment_optimization_text( $attachment ); |
| 40 |
|
| 41 |
} elseif ( false !== get_transient( 'imagify-async-in-progress-' . $post->ID ) ) { |
| 42 |
|
| 43 |
echo '<div class="misc-pub-section misc-pub-imagify">'; |
| 44 |
echo '<div class="button">'; |
| 45 |
echo '<span class="imagify-spinner"></span>'; |
| 46 |
_e( 'Optimizing...', 'imagify' ); |
| 47 |
echo '</div>'; |
| 48 |
echo '</div>'; |
| 49 |
|
| 50 |
} else { |
| 51 |
|
| 52 |
$url = get_imagify_admin_url( 'manual-upload', array( 'attachment_id' => $post->ID ) ); |
| 53 |
printf( '<div class="misc-pub-section misc-pub-imagify"><a class="button-primary" href="%s">%s</a></div>', esc_url( $url ), __( 'Optimize', 'imagify' ) ); |
| 54 |
} |
| 55 |
|
| 56 |
if ( $attachment->is_optimized() ) { |
| 57 |
echo '<input id="imagify-full-original" type="hidden" value="' . esc_url( $attachment->get_backup_url() ) . '">'; |
| 58 |
echo '<input id="imagify-full-original-size" type="hidden" value="' . esc_attr( $attachment->get_original_size( true, 0 ) ) . '">'; |
| 59 |
} |
| 60 |
} |
| 61 |
|