Move the logic from WP_Image_Editor::get_quality() to WP_Image_Editor::set_quality(), so that 'wp_editor_set_quality' and 'jpeg_quality' filters run when setting the default value.

props markoheijnen.
fixes #29856.

git-svn-id: https://develop.svn.wordpress.org/trunk@30788 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2014-12-08 16:18:42 +00:00
parent 28f8566630
commit 99224928bf

View File

@ -213,6 +213,23 @@ abstract class WP_Image_Editor {
*/
public function get_quality() {
if ( ! $this->quality ) {
$this->set_quality();
}
return $this->quality;
}
/**
* Sets Image Compression quality on a 1-100% scale.
*
* @since 3.5.0
* @access public
*
* @param int $quality Compression Quality. Range: [1,100]
* @return boolean|WP_Error True if set successfully; WP_Error on failure.
*/
public function set_quality( $quality = null ) {
if ( null === $quality ) {
/**
* Filter the default image compression quality setting.
*
@ -238,28 +255,11 @@ abstract class WP_Image_Editor {
$quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' );
}
if ( ! $this->set_quality( $quality ) ) {
$this->quality = $this->default_quality;
if ( $quality < 0 || $quality > 100 ) {
$quality = $this->default_quality;
}
}
return $this->quality;
}
/**
* Sets Image Compression quality on a 1-100% scale.
*
* @since 3.5.0
* @access public
*
* @param int $quality Compression Quality. Range: [1,100]
* @return boolean|WP_Error True if set successfully; WP_Error on failure.
*/
public function set_quality( $quality = null ) {
if ( null === $quality ) {
$quality = $this->default_quality;
}
// Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility.
if ( 0 === $quality ) {
$quality = 1;