Skip to content

Commit 28637a8

Browse files
andrewserongramonjdadamsilverstein
authored
Client-side media processing: Disable in Gutenberg just for now (#75756)
* Client-side media processing: Disable in Gutenberg just for now * Try to fix failing test * Update docblock Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
1 parent 9f40e3c commit 28637a8

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

lib/compat/plugin/media.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Disables client-side media processing by default in the Gutenberg plugin.
4+
*
5+
* Client-side media processing is being polished during the 7.0 cycle.
6+
* It is disabled by default in the plugin until known issues are resolved,
7+
* but can still be enabled via the filter.
8+
*
9+
* Remove this file when the linked issues are resolved and the plugin
10+
* is ready to match Core's default.
11+
*
12+
* @see https://github.com/WordPress/gutenberg/issues/75302
13+
* @see https://github.com/WordPress/gutenberg/issues/75605
14+
*
15+
* @package gutenberg
16+
*/
17+
18+
// @core-merge: Do not merge this into WordPress core.
19+
add_filter( 'wp_client_side_media_processing_enabled', '__return_false' );

lib/load.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ function gutenberg_is_experiment_enabled( $name ) {
110110
require __DIR__ . '/compat/wordpress-7.0/kses.php';
111111
require __DIR__ . '/compat/wordpress-7.0/media.php';
112112

113+
// Gutenberg plugin compat: disable client-side media processing by default.
114+
require __DIR__ . '/compat/plugin/media.php';
115+
113116
// Experimental features.
114117
require __DIR__ . '/experimental/block-editor-settings-mobile.php';
115118
require __DIR__ . '/experimental/blocks.php';

phpunit/bootstrap.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ function fail_if_died( $message ) {
9696
// Enable the widget block editor.
9797
tests_add_filter( 'gutenberg_use_widgets_block_editor', '__return_true' );
9898

99+
// Enable client-side media processing for tests.
100+
// The Gutenberg plugin disables this by default (lib/compat/plugin/media.php),
101+
// but tests need the media functions to be loaded.
102+
tests_add_filter( 'wp_client_side_media_processing_enabled', '__return_true', 20 );
103+
99104
// Start up the WP testing environment.
100105
require $_tests_dir . '/includes/bootstrap.php';
101106

phpunit/media/media-processing-test.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,25 +202,31 @@ public function test_gutenberg_override_media_templates(): void {
202202
}
203203

204204
/**
205-
* Tests that client-side media processing is enabled by default.
205+
* Tests that client-side media processing is disabled by default in the Gutenberg plugin.
206+
*
207+
* The core compat layer defaults to true, but the Gutenberg plugin
208+
* adds a filter to disable it by default (lib/compat/plugin/media.php)
209+
* until known issues are resolved.
206210
*
207211
* @covers ::gutenberg_is_client_side_media_processing_enabled
208212
*/
209-
public function test_client_side_media_processing_enabled_by_default() {
210-
$this->assertTrue( gutenberg_is_client_side_media_processing_enabled() );
213+
public function test_client_side_media_processing_disabled_by_default_in_plugin() {
214+
// Remove the test bootstrap override to check the plugin's actual default.
215+
remove_filter( 'wp_client_side_media_processing_enabled', '__return_true', 20 );
216+
$enabled = gutenberg_is_client_side_media_processing_enabled();
217+
// Restore the test bootstrap override.
218+
add_filter( 'wp_client_side_media_processing_enabled', '__return_true', 20 );
219+
220+
$this->assertFalse( $enabled );
211221
}
212222

213223
/**
214-
* Tests that client-side media processing can be disabled via filter.
224+
* Tests that client-side media processing can be enabled via filter.
215225
*
216226
* @covers ::gutenberg_is_client_side_media_processing_enabled
217227
*/
218-
public function test_client_side_media_processing_can_be_disabled() {
219-
add_filter( 'wp_client_side_media_processing_enabled', '__return_false' );
220-
$enabled = gutenberg_is_client_side_media_processing_enabled();
221-
remove_filter( 'wp_client_side_media_processing_enabled', '__return_false' );
222-
223-
$this->assertFalse( $enabled );
228+
public function test_client_side_media_processing_can_be_enabled() {
229+
$this->assertTrue( gutenberg_is_client_side_media_processing_enabled() );
224230
}
225231

226232
/**
@@ -229,11 +235,14 @@ public function test_client_side_media_processing_can_be_disabled() {
229235
* @covers ::gutenberg_override_attachments_rest_controller
230236
*/
231237
public function test_compat_rest_controller_used_when_filter_disabled() {
238+
// Remove the test bootstrap override so the disable filter takes effect.
239+
remove_filter( 'wp_client_side_media_processing_enabled', '__return_true', 20 );
232240
add_filter( 'wp_client_side_media_processing_enabled', '__return_false' );
233241

234242
$result = gutenberg_override_attachments_rest_controller( array(), 'attachment' );
235243

236244
remove_filter( 'wp_client_side_media_processing_enabled', '__return_false' );
245+
add_filter( 'wp_client_side_media_processing_enabled', '__return_true', 20 );
237246

238247
$this->assertSame(
239248
array( 'rest_controller_class' => 'Gutenberg_REST_Attachments_Controller_6_9' ),
@@ -242,11 +251,12 @@ public function test_compat_rest_controller_used_when_filter_disabled() {
242251
}
243252

244253
/**
245-
* Tests that the 6.9 compat REST controller is not used when filter is enabled (default).
254+
* Tests that the 6.9 compat REST controller is not used when filter is enabled.
246255
*
247256
* @covers ::gutenberg_override_attachments_rest_controller
248257
*/
249258
public function test_compat_rest_controller_not_used_when_filter_enabled() {
259+
// Feature is enabled via test bootstrap filter at priority 20.
250260
$result = gutenberg_override_attachments_rest_controller( array(), 'attachment' );
251261

252262
$this->assertSame( array(), $result );

0 commit comments

Comments
 (0)