WP_Widget_Media
- Since
- 4.8.0
- Source
wp-includes/widgets/class-wp-widget-media.php:17
Core class that implements a media widget.
Compatibility
- WordPress
- since 4.8.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 3
Every hook that fires from inside WP_Widget_Media, in the order it appears in the class, grouped by the method that fires it.
WP_Widget_Media::get_instance_schema()
- apply_filters( widget_{$this->id_base}_instance_schema )filter line 172
WP_Widget_Media::widget()
- apply_filters( widget_title )filter line 240
- apply_filters( widget_{$this->id_base}_instance )filter line 255
Properties · 4
$l10narraypublic- Translation labels.
$registeredboolprotected- Whether or not the widget has been registered yet.
$default_descriptionstringprotected static- The default widget description.
$l10n_defaultsstring[]protected static- The default localized strings used by the widget.
Methods · 17
- __construct()Constructor.
- _register_one()Add hooks while registering all widget instances of this widget class.
- get_instance_schema()Get schema for properties of a widget instance (item).
- is_attachment_with_mime_type()Determine if the supplied attachment is for a valid attachment post with the specified MIME type.
- sanitize_token_list()Sanitize a token list string, such as used in HTML rel and class attributes.
- widget()Displays the widget on the front-end.
- update()Sanitizes the widget form values as they are saved.
- render_media()Render the media on the frontend.
- form()Outputs the settings update form.
- display_media_state()Filters the default media display states for items in the Media list table.
- enqueue_preview_scripts()Enqueue preview scripts.
- enqueue_admin_scripts()Loads the required scripts and styles for the widget control.
- render_control_template_scripts()Render form template scripts.
- reset_default_labels()Resets the cache for the default labels.
- has_content()Whether the widget has content to show.
- get_default_description()Returns the default description of the widget.
- get_l10n_defaults()Returns the default localized strings used by the widget.
Source code
abstract class WP_Widget_Media extends WP_Widget { /** * Translation labels. * * @since 4.8.0 * @var array */ public $l10n = array( 'add_to_widget' => '', 'replace_media' => '', 'edit_media' => '', 'media_library_state_multi' => '', 'media_library_state_single' => '', 'missing_attachment' => '', 'no_media_selected' => '', 'add_media' => '', ); /** * Whether or not the widget has been registered yet. * * @since 4.8.1 * @var bool */ 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. * * @since 4.8.0 * * @param string $id_base Base ID for the widget, lowercase and unique. * @param string $name Name for the widget displayed on the configuration page. * @param array $widget_options Optional. Widget options. See wp_register_sidebar_widget() for * information on accepted arguments. Default empty array. * @param array $control_options Optional. Widget control options. See wp_register_widget_control() * for information on accepted arguments. Default empty array. */ public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) { $widget_opts = wp_parse_args( $widget_options, array( 'description' => self::get_default_description(), 'customize_selective_refresh' => true, 'show_instance_in_rest' => true, 'mime_type' => '', ) ); $control_opts = wp_parse_args( $control_options, array() ); $this->l10n = array_merge( self::get_l10n_defaults(), array_filter( $this->l10n ) ); parent::__construct( $id_base, $name, $widget_opts, $control_opts ); } /** * Add hooks while registering all widget instances of this widget class.Changelog
Introduced in 4.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/widgets/class-wp-widget-media.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.