Skip to content
Closed
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
1 change: 1 addition & 0 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@
// Widgets.
add_action( 'after_setup_theme', 'wp_setup_widgets_block_editor', 1 );
add_action( 'init', 'wp_widgets_init', 1 );
add_action( 'change_locale', array( 'WP_Widget_Media', 'reset_default_labels' ) );

// Admin Bar.
// Don't remove. Wrong way to disable.
Expand Down
94 changes: 76 additions & 18 deletions src/wp-includes/widgets/class-wp-widget-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ abstract class WP_Widget_Media extends WP_Widget {
*/
protected $registered = false;

/**
* The default widget description.
*
* @since 6.0.0
* @var string
*/
protected static $default_description = '';

/**
* The default localized strings used by the widget.
*
* @since 6.0.0
* @var string[]
*/
protected static $l10n_defaults = array();

/**
* Constructor.
*
Expand All @@ -57,7 +73,7 @@ public function __construct( $id_base, $name, $widget_options = array(), $contro
$widget_opts = wp_parse_args(
$widget_options,
array(
'description' => __( 'A media item.' ),
'description' => self::get_default_description(),
'customize_selective_refresh' => true,
'show_instance_in_rest' => true,
'mime_type' => '',
Expand All @@ -66,23 +82,7 @@ public function __construct( $id_base, $name, $widget_options = array(), $contro

$control_opts = wp_parse_args( $control_options, array() );

$l10n_defaults = array(
'no_media_selected' => __( 'No media selected' ),
'add_media' => _x( 'Add Media', 'label for button in the media widget' ),
'replace_media' => _x( 'Replace Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
'edit_media' => _x( 'Edit Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
'add_to_widget' => __( 'Add to Widget' ),
'missing_attachment' => sprintf(
/* translators: %s: URL to media library. */
__( 'That file cannot be found. Check your <a href="%s">media library</a> and make sure it was not deleted.' ),
esc_url( admin_url( 'upload.php' ) )
),
/* translators: %d: Widget count. */
'media_library_state_multi' => _n_noop( 'Media Widget (%d)', 'Media Widget (%d)' ),
'media_library_state_single' => __( 'Media Widget' ),
'unsupported_file_type' => __( 'Looks like this is not the correct kind of file. Please link to an appropriate file instead.' ),
);
$this->l10n = array_merge( $l10n_defaults, array_filter( $this->l10n ) );
$this->l10n = array_merge( self::get_l10n_defaults(), array_filter( $this->l10n ) );

parent::__construct(
$id_base,
Expand Down Expand Up @@ -440,6 +440,16 @@ public function render_control_template_scripts() {
<?php
}

/**
* Resets the cache for the default labels.
*
* @since 6.0.0
*/
public static function reset_default_labels() {
self::$default_description = '';
self::$l10n_defaults = array();
}

/**
* Whether the widget has content to show.
*
Expand All @@ -451,4 +461,52 @@ public function render_control_template_scripts() {
protected function has_content( $instance ) {
return ( $instance['attachment_id'] && 'attachment' === get_post_type( $instance['attachment_id'] ) ) || $instance['url'];
}

/**
* Returns the default description of the widget.
*
* @since 6.0.0
*
* @var string
*/
protected static function get_default_description() {
if ( self::$default_description ) {
return self::$default_description;
}

self::$default_description = __( 'A media item.' );
return self::$default_description;
}

/**
* Returns the default localized strings used by the widget.
*
* @since 6.0.0
*
* @return string[]
*/
protected static function get_l10n_defaults() {
if ( ! empty( self::$l10n_defaults ) ) {
return self::$l10n_defaults;
}

self::$l10n_defaults = array(
'no_media_selected' => __( 'No media selected' ),
'add_media' => _x( 'Add Media', 'label for button in the media widget' ),
'replace_media' => _x( 'Replace Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
'edit_media' => _x( 'Edit Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
'add_to_widget' => __( 'Add to Widget' ),
'missing_attachment' => sprintf(
/* translators: %s: URL to media library. */
__( 'That file cannot be found. Check your <a href="%s">media library</a> and make sure it was not deleted.' ),
esc_url( admin_url( 'upload.php' ) )
),
/* translators: %d: Widget count. */
'media_library_state_multi' => _n_noop( 'Media Widget (%d)', 'Media Widget (%d)' ),
'media_library_state_single' => __( 'Media Widget' ),
'unsupported_file_type' => __( 'Looks like this is not the correct kind of file. Please link to an appropriate file instead.' ),
);

return self::$l10n_defaults;
}
}