Skip to content

Instantly share code, notes, and snippets.

@adamsilverstein
Last active September 18, 2026 15:55
Show Gist options
  • Select an option

  • Save adamsilverstein/16c35549d26024dd7266630fbd801442 to your computer and use it in GitHub Desktop.

Select an option

Save adamsilverstein/16c35549d26024dd7266630fbd801442 to your computer and use it in GitHub Desktop.
Test plugin for Gutenberg PR #80385: toggles the wp_generate_animated_image_subsizes filter from Settings > Media
<?php
/**
* Toggle animated sub-size generation for animated images.
*
* @wordpress-plugin
* Plugin Name: Animated Sub-sizes Toggle
* Description: Adds a Settings > Media checkbox that turns the wp_generate_animated_image_subsizes filter on or off, for testing Gutenberg PR #80385.
* Plugin URI: https://github.com/WordPress/gutenberg/pull/80385
* Version: 1.0.0
* Author: Adam Silverstein
* License: Apache License 2.0
* License URI: https://www.apache.org/licenses/LICENSE-2.0
*/
defined( 'ABSPATH' ) || exit;
const AGST_OPTION = 'agst_generate_animated_image_subsizes';
/**
* Returns the filter to the value stored by the Settings > Media checkbox.
*
* @param bool $enabled Whether animated sub-sizes should be generated.
* @return bool Filtered value.
*/
function agst_filter_animated_subsizes( $enabled ) {
return (bool) get_option( AGST_OPTION, false );
}
add_filter( 'wp_generate_animated_image_subsizes', 'agst_filter_animated_subsizes' );
/**
* Registers the setting and its field on Settings > Media.
*/
function agst_register_setting() {
register_setting(
'media',
AGST_OPTION,
array(
'type' => 'boolean',
'sanitize_callback' => 'rest_sanitize_boolean',
'default' => false,
'show_in_rest' => false,
)
);
add_settings_field(
AGST_OPTION,
'Animated sub-sizes',
'agst_render_field',
'media',
'default'
);
}
add_action( 'admin_init', 'agst_register_setting' );
/**
* Renders the checkbox.
*/
function agst_render_field() {
$enabled = (bool) get_option( AGST_OPTION, false );
?>
<label for="<?php echo esc_attr( AGST_OPTION ); ?>">
<input
type="checkbox"
name="<?php echo esc_attr( AGST_OPTION ); ?>"
id="<?php echo esc_attr( AGST_OPTION ); ?>"
value="1"
<?php checked( $enabled ); ?>
/>
Keep animation in uncropped sub-sizes of animated images
</label>
<p class="description">
Sets the <code>wp_generate_animated_image_subsizes</code> filter. Cropped sizes such as the thumbnail are always taken from the first frame. Reload the editor after changing this.
</p>
<?php
}
/**
* Shows the current state in the admin bar, so the editor page itself says which mode is live.
*
* @param WP_Admin_Bar $admin_bar Admin bar instance.
*/
function agst_admin_bar_indicator( $admin_bar ) {
if ( ! current_user_can( 'upload_files' ) ) {
return;
}
$enabled = (bool) apply_filters( 'wp_generate_animated_image_subsizes', false );
$admin_bar->add_node(
array(
'id' => 'agst-indicator',
'title' => $enabled ? 'Animated sub-sizes: ON' : 'Animated sub-sizes: OFF',
'href' => admin_url( 'options-media.php' ),
'meta' => array( 'title' => 'Toggle on Settings > Media' ),
)
);
}
add_action( 'admin_bar_menu', 'agst_admin_bar_indicator', 100 );
@adamsilverstein

Copy link
Copy Markdown
Author

Sharing the toggle plugin I used while testing WordPress/gutenberg#80385, in case it helps anyone else who wants to try that PR.

Claude wrote the plugin and these notes, forwarding them along:

The PR makes animated sub-sizes opt-in behind a new wp_generate_animated_image_subsizes filter. Rather than editing a file to flip that filter, this plugin puts a checkbox at Settings > Media, so one site can be tested both ways without a redeploy. The admin bar shows Animated sub-sizes: ON or OFF, so the editor page itself says which mode is live.

To install it, use the Download ZIP button above and upload the zip at Plugins > Add New > Upload Plugin. The plugin folder winds up named after the gist id, which is harmless.

Testing steps:

  1. Leave the toggle off, which is the default, and upload an animated GIF. The sub-sizes should all be static.
  2. Tick the box on Settings > Media, reload the editor, then upload again. Uncropped sub-sizes should now animate.

Worth using a source wider than 1024px so medium, medium_large, and large are all generated - a smaller GIF only yields one uncropped size, which makes for a thin test. The thumbnail stays static either way, since cropped sizes are always taken from the first frame.

Note that this only applies to uploads that go through client-side media processing. Uploads taking the server-side path still produce static sub-sizes, since core has no animated resize support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment