diff --git src/wp-includes/class-wp-image-editor.php src/wp-includes/class-wp-image-editor.php
index 2db73f0..f6e1c12 100644
|
|
abstract class WP_Image_Editor { |
233 | 233 | /** |
234 | 234 | * Filter the default image compression quality setting. |
235 | 235 | * |
| 236 | * Applies only during initial editor instantiation, or when set_quality() is run |
| 237 | * manually without an argument after editor instantiation. |
| 238 | * |
| 239 | * set_quality() has priority over the filter. |
| 240 | * |
236 | 241 | * @since 3.5.0 |
237 | 242 | * |
238 | 243 | * @param int $quality Quality level between 1 (low) and 100 (high). |
… |
… |
abstract class WP_Image_Editor { |
244 | 249 | /** |
245 | 250 | * Filter the JPEG compression quality for backward-compatibility. |
246 | 251 | * |
| 252 | * Applies only during initial editor instantiation, or when set_quality() is run |
| 253 | * manually without an argument after instantiation. |
| 254 | * |
| 255 | * set_quality() has priority over the filter. |
| 256 | * |
247 | 257 | * The filter is evaluated under two contexts: 'image_resize', and 'edit_image', |
248 | 258 | * (when a JPEG image is saved to file). |
249 | 259 | * |
diff --git tests/phpunit/includes/mock-image-editor.php tests/phpunit/includes/mock-image-editor.php
index 808b32d..a799bd0 100644
|
|
if (class_exists( 'WP_Image_Editor' ) ) : |
8 | 8 | public static $test_return = true; |
9 | 9 | public static $save_return = array(); |
10 | 10 | |
| 11 | // Allow testing of jpeg_quality filter. |
| 12 | public function set_mime_type( $mime_type = null ) { |
| 13 | $this->mime_type = $mime_type; |
| 14 | } |
| 15 | |
11 | 16 | public function load() { |
12 | 17 | return self::$load_return; |
13 | 18 | } |
diff --git tests/phpunit/tests/image/editor.php tests/phpunit/tests/image/editor.php
index 2844a08..14261e7 100644
|
|
class Tests_Image_Editor extends WP_Image_UnitTestCase { |
51 | 51 | |
52 | 52 | // Get an editor |
53 | 53 | $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); |
| 54 | $editor->set_mime_type( "image/jpeg" ); // Ensure mime-specific filters act properly. |
54 | 55 | |
55 | 56 | // Check default value |
56 | 57 | $this->assertEquals( 90, $editor->get_quality() ); |
57 | 58 | |
58 | | // Ensure set_quality works |
| 59 | // Ensure the quality filters do not have precedence if created after editor instantiation. |
| 60 | $func_100_percent = create_function( '', "return 100;" ); |
| 61 | add_filter( 'wp_editor_set_quality', $func_100_percent ); |
| 62 | $this->assertEquals( 90, $editor->get_quality() ); |
| 63 | |
| 64 | $func_95_percent = create_function( '', "return 95;" ); |
| 65 | add_filter( 'jpeg_quality', $func_95_percent ); |
| 66 | $this->assertEquals( 90, $editor->get_quality() ); |
| 67 | |
| 68 | // Ensure set_quality() works and overrides the filters |
59 | 69 | $this->assertTrue( $editor->set_quality( 75 ) ); |
60 | 70 | $this->assertEquals( 75, $editor->get_quality() ); |
61 | 71 | |
62 | | // Ensure the quality filter works |
63 | | $func = create_function( '', "return 100;"); |
64 | | add_filter( 'wp_editor_set_quality', $func ); |
65 | | $this->assertTrue( $editor->set_quality( 70 ) ); |
66 | | $this->assertEquals( 70, $editor->get_quality() ); |
| 72 | // Get a new editor to clear default quality state |
| 73 | unset( $editor ); |
| 74 | $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); |
| 75 | $editor->set_mime_type( "image/jpeg" ); // Ensure mime-specific filters act properly. |
| 76 | |
| 77 | // Ensure jpeg_quality filter applies if it exists before editor instantiation. |
| 78 | $this->assertEquals( 95, $editor->get_quality() ); |
| 79 | |
| 80 | // Get a new editor to clear jpeg_quality state |
| 81 | remove_filter( 'jpeg_quality', $func_95_percent ); |
| 82 | unset( $editor ); |
| 83 | $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); |
| 84 | |
| 85 | // Ensure wp_editor_set_quality filter applies if it exists before editor instantiation. |
| 86 | $this->assertEquals( 100, $editor->get_quality() ); |
67 | 87 | |
68 | 88 | // Clean up |
69 | | remove_filter( 'wp_editor_set_quality', $func ); |
| 89 | remove_filter( 'wp_editor_set_quality', $func_100_percent ); |
70 | 90 | } |
71 | 91 | |
72 | 92 | /** |