Last active
September 18, 2026 15:55
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: