| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); |
| 3 |
|
| 4 |
/** |
| 5 |
* Class that contains the deprecated methods of Imagify_Auto_Optimization. |
| 6 |
* |
| 7 |
* @since 1.9.10 |
| 8 |
*/ |
| 9 |
abstract class Imagify_Auto_Optimization_Deprecated { |
| 10 |
|
| 11 |
/** |
| 12 |
* With WP 5.3+, prevent auto-optimization inside wp_generate_attachment_metadata() because it triggers a wp_update_attachment_metadata() for each thumbnail size. |
| 13 |
* |
| 14 |
* @since 1.9.8 |
| 15 |
* @since 1.9.10 Deprecated. |
| 16 |
* @see wp_generate_attachment_metadata() |
| 17 |
* @see wp_create_image_subsizes() |
| 18 |
* |
| 19 |
* @param int $threshold The threshold value in pixels. Default 2560. |
| 20 |
* @param array $imagesize Indexed array of the image width and height (in that order). |
| 21 |
* @param string $file Full path to the uploaded image file. |
| 22 |
* @param int $attachment_id Attachment post ID. |
| 23 |
* @return int The threshold value in pixels. |
| 24 |
*/ |
| 25 |
public function prevent_auto_optimization_when_generating_thumbnails( $threshold, $imagesize, $file, $attachment_id ) { |
| 26 |
_deprecated_function( get_class( $this ) . '::' . __FUNCTION__ . '()', '1.9.10' ); |
| 27 |
|
| 28 |
static::prevent_optimization_internally( $attachment_id ); |
| 29 |
return $threshold; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* With WP 5.3+, allow auto-optimization back after wp_generate_attachment_metadata(). |
| 34 |
* |
| 35 |
* @since 1.9.8 |
| 36 |
* @since 1.9.10 Deprecated. |
| 37 |
* @see $this->prevent_auto_optimization_when_generating_thumbnails() |
| 38 |
* |
| 39 |
* @param array $metadata An array of attachment meta data. |
| 40 |
* @param int $attachment_id Current attachment ID. |
| 41 |
* @param string $context Additional context. Can be 'create' when metadata was initially created for new attachment or 'update' when the metadata was updated. |
| 42 |
* @return array An array of attachment meta data. |
| 43 |
*/ |
| 44 |
public function allow_auto_optimization_when_generating_thumbnails( $metadata, $attachment_id, $context = null ) { |
| 45 |
_deprecated_function( get_class( $this ) . '::' . __FUNCTION__ . '()', '1.9.10' ); |
| 46 |
|
| 47 |
if ( ! empty( $context ) && 'create' !== $context ) { |
| 48 |
return $metadata; |
| 49 |
} |
| 50 |
|
| 51 |
// Fired from wp_generate_attachment_metadata(): $context is empty (WP < 5.3) or equal to 'create' (>P >= 5.3). |
| 52 |
static::allow_optimization_internally( $attachment_id ); |
| 53 |
return $metadata; |
| 54 |
} |
| 55 |
} |
| 56 |
|