Make WordPress Core

Ticket #54561: 54561.2.patch

File 54561.2.patch, 5.4 KB (added by Chouby, 3 years ago)

Refresh patch and reset default labels on change_locale

  • src/wp-includes/default-filters.php

    diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
    index 124b1c2440..267d16c3b1 100644
    add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 ); 
    630630// Widgets.
    631631add_action( 'after_setup_theme', 'wp_setup_widgets_block_editor', 1 );
    632632add_action( 'init', 'wp_widgets_init', 1 );
     633add_action( 'change_locale', array( 'WP_Widget_Media', 'reset_default_labels' ) );
    633634
    634635// Admin Bar.
    635636// Don't remove. Wrong way to disable.
  • src/wp-includes/widgets/class-wp-widget-media.php

    diff --git src/wp-includes/widgets/class-wp-widget-media.php src/wp-includes/widgets/class-wp-widget-media.php
    index e1bd5de9b3..3ec9184397 100644
    abstract class WP_Widget_Media extends WP_Widget { 
    4141         */
    4242        protected $registered = false;
    4343
     44        /**
     45         * The default widget description.
     46         *
     47         * @since 6.0.0
     48         * @var string
     49         */
     50        protected static $default_description = '';
     51
     52        /**
     53         * The default localized strings used by the widget.
     54         *
     55         * @since 6.0.0
     56         * @var string[]
     57         */
     58        protected static $l10n_defaults = array();
     59
    4460        /**
    4561         * Constructor.
    4662         *
    abstract class WP_Widget_Media extends WP_Widget { 
    5773                $widget_opts = wp_parse_args(
    5874                        $widget_options,
    5975                        array(
    60                                 'description'                 => __( 'A media item.' ),
     76                                'description'                 => self::get_default_description(),
    6177                                'customize_selective_refresh' => true,
    6278                                'show_instance_in_rest'       => true,
    6379                                'mime_type'                   => '',
    abstract class WP_Widget_Media extends WP_Widget { 
    6581                );
    6682
    6783                $control_opts = wp_parse_args( $control_options, array() );
    68 
    69                 $l10n_defaults = array(
    70                         'no_media_selected'          => __( 'No media selected' ),
    71                         'add_media'                  => _x( 'Add Media', 'label for button in the media widget' ),
    72                         'replace_media'              => _x( 'Replace Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
    73                         'edit_media'                 => _x( 'Edit Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
    74                         'add_to_widget'              => __( 'Add to Widget' ),
    75                         'missing_attachment'         => sprintf(
    76                                 /* translators: %s: URL to media library. */
    77                                 __( 'That file cannot be found. Check your <a href="%s">media library</a> and make sure it was not deleted.' ),
    78                                 esc_url( admin_url( 'upload.php' ) )
    79                         ),
    80                         /* translators: %d: Widget count. */
    81                         'media_library_state_multi'  => _n_noop( 'Media Widget (%d)', 'Media Widget (%d)' ),
    82                         'media_library_state_single' => __( 'Media Widget' ),
    83                         'unsupported_file_type'      => __( 'Looks like this is not the correct kind of file. Please link to an appropriate file instead.' ),
    84                 );
    85                 $this->l10n    = array_merge( $l10n_defaults, array_filter( $this->l10n ) );
     84                $this->l10n   = array_merge( self::get_l10n_defaults(), array_filter( $this->l10n ) );
    8685
    8786                parent::__construct(
    8887                        $id_base,
    abstract class WP_Widget_Media extends WP_Widget { 
    440439                <?php
    441440        }
    442441
     442        /**
     443         * Resets the cache for the default labels.
     444         *
     445         * @since 6.0.0
     446         */
     447        public static function reset_default_labels() {
     448                self::$default_description = '';
     449                self::$l10n_defaults       = array();
     450        }
     451
    443452        /**
    444453         * Whether the widget has content to show.
    445454         *
    abstract class WP_Widget_Media extends WP_Widget { 
    451460        protected function has_content( $instance ) {
    452461                return ( $instance['attachment_id'] && 'attachment' === get_post_type( $instance['attachment_id'] ) ) || $instance['url'];
    453462        }
     463
     464        /**
     465         * Returns the default description of the widget.
     466         *
     467         * @since 6.0.O
     468         *
     469         * @var string
     470         */
     471        protected static function get_default_description() {
     472                if ( ! empty( self::$default_description ) ) {
     473                        return self::$default_description;
     474                }
     475
     476                self::$default_description = __( 'A media item.' );
     477                return self::$default_description;
     478        }
     479
     480        /**
     481         * Returns the default localized strings used by the widget.
     482         *
     483         * @since 6.0.0
     484         *
     485         * @return string[]
     486         */
     487        protected static function get_l10n_defaults() {
     488                if ( ! empty( self::$l10n_defaults ) ) {
     489                        return self::$l10n_defaults;
     490                }
     491
     492                self::$l10n_defaults = array(
     493                        'no_media_selected'          => __( 'No media selected' ),
     494                        'add_media'                  => _x( 'Add Media', 'label for button in the media widget' ),
     495                        'replace_media'              => _x( 'Replace Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
     496                        'edit_media'                 => _x( 'Edit Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
     497                        'add_to_widget'              => __( 'Add to Widget' ),
     498                        'missing_attachment'         => sprintf(
     499                                /* translators: %s: URL to media library. */
     500                                __( 'That file cannot be found. Check your <a href="%s">media library</a> and make sure it was not deleted.' ),
     501                                esc_url( admin_url( 'upload.php' ) )
     502                        ),
     503                        /* translators: %d: Widget count. */
     504                        'media_library_state_multi'  => _n_noop( 'Media Widget (%d)', 'Media Widget (%d)' ),
     505                        'media_library_state_single' => __( 'Media Widget' ),
     506                        'unsupported_file_type'      => __( 'Looks like this is not the correct kind of file. Please link to an appropriate file instead.' ),
     507                );
     508
     509                return self::$l10n_defaults;
     510        }
    454511}