Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/compat/plugin/media.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Disables client-side media processing by default in the Gutenberg plugin.
*
* Client-side media processing is being polished during the 7.0 cycle.
* It is disabled by default in the plugin until known issues are resolved,
* but can still be enabled via the filter.
*
* Remove this file when the linked issues are resolved and the plugin
* is ready to match Core's default.
*
* @see https://github.com/WordPress/gutenberg/issues/75302
* @see https://github.com/WordPress/gutenberg/issues/75605
*
* @package gutenberg
*/

// @core-merge: Do not merge this into WordPress core.
add_filter( 'wp_client_side_media_processing_enabled', '__return_false' );
3 changes: 3 additions & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-7.0/kses.php';
require __DIR__ . '/compat/wordpress-7.0/media.php';

// Gutenberg plugin compat: disable client-side media processing by default.
require __DIR__ . '/compat/plugin/media.php';

// Experimental features.
require __DIR__ . '/experimental/block-editor-settings-mobile.php';
require __DIR__ . '/experimental/blocks.php';
Expand Down
5 changes: 5 additions & 0 deletions phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ function fail_if_died( $message ) {
// Enable the widget block editor.
tests_add_filter( 'gutenberg_use_widgets_block_editor', '__return_true' );

// Enable client-side media processing for tests.
// The Gutenberg plugin disables this by default (lib/compat/plugin/media.php),
// but tests need the media functions to be loaded.
tests_add_filter( 'wp_client_side_media_processing_enabled', '__return_true', 20 );

// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';

Expand Down
32 changes: 21 additions & 11 deletions phpunit/media/media-processing-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,31 @@ public function test_gutenberg_override_media_templates(): void {
}

/**
* Tests that client-side media processing is enabled by default.
* Tests that client-side media processing is disabled by default in the Gutenberg plugin.
*
* The core compat layer defaults to true, but the Gutenberg plugin
* adds a filter to disable it by default (lib/compat/plugin/media.php)
* until known issues are resolved.
*
* @covers ::gutenberg_is_client_side_media_processing_enabled
*/
public function test_client_side_media_processing_enabled_by_default() {
$this->assertTrue( gutenberg_is_client_side_media_processing_enabled() );
public function test_client_side_media_processing_disabled_by_default_in_plugin() {
// Remove the test bootstrap override to check the plugin's actual default.
remove_filter( 'wp_client_side_media_processing_enabled', '__return_true', 20 );
$enabled = gutenberg_is_client_side_media_processing_enabled();
// Restore the test bootstrap override.
add_filter( 'wp_client_side_media_processing_enabled', '__return_true', 20 );

$this->assertFalse( $enabled );
}

/**
* Tests that client-side media processing can be disabled via filter.
* Tests that client-side media processing can be enabled via filter.
*
* @covers ::gutenberg_is_client_side_media_processing_enabled
*/
public function test_client_side_media_processing_can_be_disabled() {
add_filter( 'wp_client_side_media_processing_enabled', '__return_false' );
$enabled = gutenberg_is_client_side_media_processing_enabled();
remove_filter( 'wp_client_side_media_processing_enabled', '__return_false' );

$this->assertFalse( $enabled );
public function test_client_side_media_processing_can_be_enabled() {
$this->assertTrue( gutenberg_is_client_side_media_processing_enabled() );
}

/**
Expand All @@ -229,11 +235,14 @@ public function test_client_side_media_processing_can_be_disabled() {
* @covers ::gutenberg_override_attachments_rest_controller
*/
public function test_compat_rest_controller_used_when_filter_disabled() {
// Remove the test bootstrap override so the disable filter takes effect.
remove_filter( 'wp_client_side_media_processing_enabled', '__return_true', 20 );
add_filter( 'wp_client_side_media_processing_enabled', '__return_false' );

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

remove_filter( 'wp_client_side_media_processing_enabled', '__return_false' );
add_filter( 'wp_client_side_media_processing_enabled', '__return_true', 20 );

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

/**
* Tests that the 6.9 compat REST controller is not used when filter is enabled (default).
* Tests that the 6.9 compat REST controller is not used when filter is enabled.
*
* @covers ::gutenberg_override_attachments_rest_controller
*/
public function test_compat_rest_controller_not_used_when_filter_enabled() {
// Feature is enabled via test bootstrap filter at priority 20.
$result = gutenberg_override_attachments_rest_controller( array(), 'attachment' );

$this->assertSame( array(), $result );
Expand Down
Loading