Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Widget API: WP_Media_Widget class
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Widgets
|
|
|
|
* @since 4.8.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Core class that implements a media widget.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*
|
|
|
|
* @see WP_Widget
|
|
|
|
*/
|
|
|
|
abstract class WP_Widget_Media extends WP_Widget {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translation labels.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $l10n = array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'add_to_widget' => '',
|
|
|
|
'replace_media' => '',
|
|
|
|
'edit_media' => '',
|
|
|
|
'media_library_state_multi' => '',
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
'media_library_state_single' => '',
|
2017-12-01 00:11:00 +01:00
|
|
|
'missing_attachment' => '',
|
|
|
|
'no_media_selected' => '',
|
|
|
|
'add_media' => '',
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
);
|
|
|
|
|
2017-07-12 00:47:43 +02:00
|
|
|
/**
|
|
|
|
* Whether or not the widget has been registered yet.
|
|
|
|
*
|
|
|
|
* @since 4.8.1
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $registered = false;
|
|
|
|
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
/**
|
|
|
|
* 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() ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$widget_opts = wp_parse_args(
|
2018-08-17 03:51:36 +02:00
|
|
|
$widget_options,
|
|
|
|
array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'description' => __( 'A media item.' ),
|
|
|
|
'customize_selective_refresh' => true,
|
2021-05-25 10:27:57 +02:00
|
|
|
'show_instance_in_rest' => true,
|
2017-12-01 00:11:00 +01:00
|
|
|
'mime_type' => '',
|
|
|
|
)
|
|
|
|
);
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
|
|
|
$control_opts = wp_parse_args( $control_options, array() );
|
|
|
|
|
|
|
|
$l10n_defaults = array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'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(
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %s: URL to media library. */
|
Administration: Remove self-reference ("we") in WordPress Admin.
This changes updates many strings to remove self-references to an undefined "we" collective across the WordPress Administration.
The goal of this change is to better match the guidelines and recommendations set forth in the make/core handbook, specifically:
> the word "we" should be avoided (…) unless its made very clear which group is speaking.
Props johnbillion, shital-patel, audrasjb, marybaum, SergeyBiryukov, peterwilsoncc, johnjamesjacoby, kebbet, costdev, chaion07, davidbaumwald.
Fixes #46057.
Built from https://develop.svn.wordpress.org/trunk@53131
git-svn-id: http://core.svn.wordpress.org/trunk@52720 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-11 13:42:04 +02:00
|
|
|
__( 'That file can not be found. Check your <a href="%s">media library</a> and make sure it was not deleted.' ),
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
esc_url( admin_url( 'upload.php' ) )
|
|
|
|
),
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %d: Widget count. */
|
2017-12-01 00:11:00 +01:00
|
|
|
'media_library_state_multi' => _n_noop( 'Media Widget (%d)', 'Media Widget (%d)' ),
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
'media_library_state_single' => __( 'Media Widget' ),
|
Administration: Replace contracted verb forms for better consistency.
This changeset replaces contracted verb forms like `doesn't`, `can't`, or `isn't` with non-contracted forms like `does not`, `cannot`, or `is not`, for better consistency across the WordPress administration. It also updates some corresponding unit tests strings.
Props Presskopp, socalchristina, aandrewdixon, francina, SergeyBiryukov, JeffPaul, audrasjb, hellofromTonya.
Fixes #38913.
See #39176.
Built from https://develop.svn.wordpress.org/trunk@52978
git-svn-id: http://core.svn.wordpress.org/trunk@52567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-22 17:25:03 +01:00
|
|
|
'unsupported_file_type' => __( 'Looks like this is not the correct kind of file. Please link to an appropriate file instead.' ),
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
);
|
2018-08-17 03:51:36 +02:00
|
|
|
$this->l10n = array_merge( $l10n_defaults, array_filter( $this->l10n ) );
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
|
|
|
parent::__construct(
|
|
|
|
$id_base,
|
|
|
|
$name,
|
|
|
|
$widget_opts,
|
|
|
|
$control_opts
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add hooks while registering all widget instances of this widget class.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
2017-07-12 00:47:43 +02:00
|
|
|
*
|
2020-10-10 22:02:05 +02:00
|
|
|
* @param int $number Optional. The unique order number of this widget instance
|
|
|
|
* compared to other instances of the same class. Default -1.
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*/
|
2017-07-12 00:47:43 +02:00
|
|
|
public function _register_one( $number = -1 ) {
|
|
|
|
parent::_register_one( $number );
|
|
|
|
if ( $this->registered ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->registered = true;
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Note that the widgets component in the customizer will also do
|
|
|
|
// the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );
|
|
|
|
|
|
|
|
if ( $this->is_preview() ) {
|
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) );
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Note that the widgets component in the customizer will also do
|
|
|
|
// the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
add_action( 'admin_footer-widgets.php', array( $this, 'render_control_template_scripts' ) );
|
|
|
|
|
|
|
|
add_filter( 'display_media_states', array( $this, 'display_media_state' ), 10, 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get schema for properties of a widget instance (item).
|
|
|
|
*
|
2019-04-03 00:13:52 +02:00
|
|
|
* @since 4.8.0
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*
|
|
|
|
* @see WP_REST_Controller::get_item_schema()
|
|
|
|
* @see WP_REST_Controller::get_additional_fields()
|
|
|
|
* @link https://core.trac.wordpress.org/ticket/35574
|
2020-01-10 01:30:05 +01:00
|
|
|
*
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
* @return array Schema for properties.
|
|
|
|
*/
|
|
|
|
public function get_instance_schema() {
|
2017-10-20 01:44:48 +02:00
|
|
|
$schema = array(
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
'attachment_id' => array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'type' => 'integer',
|
|
|
|
'default' => 0,
|
|
|
|
'minimum' => 0,
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
'description' => __( 'Attachment post ID' ),
|
2017-12-01 00:11:00 +01:00
|
|
|
'media_prop' => 'id',
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
),
|
2017-12-01 00:11:00 +01:00
|
|
|
'url' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'default' => '',
|
|
|
|
'format' => 'uri',
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
'description' => __( 'URL to the media file' ),
|
|
|
|
),
|
2017-12-01 00:11:00 +01:00
|
|
|
'title' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'default' => '',
|
|
|
|
'sanitize_callback' => 'sanitize_text_field',
|
|
|
|
'description' => __( 'Title for the widget' ),
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
'should_preview_update' => false,
|
|
|
|
),
|
|
|
|
);
|
2017-10-20 01:44:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters the media widget instance schema to add additional properties.
|
|
|
|
*
|
|
|
|
* @since 4.9.0
|
|
|
|
*
|
|
|
|
* @param array $schema Instance schema.
|
2021-01-08 15:30:14 +01:00
|
|
|
* @param WP_Widget_Media $widget Widget object.
|
2017-10-20 01:44:48 +02:00
|
|
|
*/
|
|
|
|
$schema = apply_filters( "widget_{$this->id_base}_instance_schema", $schema, $this );
|
|
|
|
|
|
|
|
return $schema;
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if the supplied attachment is for a valid attachment post with the specified MIME type.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*
|
|
|
|
* @param int|WP_Post $attachment Attachment post ID or object.
|
|
|
|
* @param string $mime_type MIME type.
|
|
|
|
* @return bool Is matching MIME type.
|
|
|
|
*/
|
|
|
|
public function is_attachment_with_mime_type( $attachment, $mime_type ) {
|
|
|
|
if ( empty( $attachment ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$attachment = get_post( $attachment );
|
|
|
|
if ( ! $attachment ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( 'attachment' !== $attachment->post_type ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return wp_attachment_is( $mime_type, $attachment );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sanitize a token list string, such as used in HTML rel and class attributes.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*
|
|
|
|
* @link http://w3c.github.io/html/infrastructure.html#space-separated-tokens
|
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList
|
|
|
|
* @param string|array $tokens List of tokens separated by spaces, or an array of tokens.
|
|
|
|
* @return string Sanitized token string list.
|
|
|
|
*/
|
|
|
|
public function sanitize_token_list( $tokens ) {
|
|
|
|
if ( is_string( $tokens ) ) {
|
|
|
|
$tokens = preg_split( '/\s+/', trim( $tokens ) );
|
|
|
|
}
|
|
|
|
$tokens = array_map( 'sanitize_html_class', $tokens );
|
|
|
|
$tokens = array_filter( $tokens );
|
2020-10-18 19:27:06 +02:00
|
|
|
return implode( ' ', $tokens );
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the widget on the front-end.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*
|
|
|
|
* @see WP_Widget::widget()
|
|
|
|
*
|
|
|
|
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
|
|
|
|
* @param array $instance Saved setting from the database.
|
|
|
|
*/
|
|
|
|
public function widget( $args, $instance ) {
|
|
|
|
$instance = wp_parse_args( $instance, wp_list_pluck( $this->get_instance_schema(), 'default' ) );
|
|
|
|
|
|
|
|
// Short-circuit if no media is selected.
|
|
|
|
if ( ! $this->has_content( $instance ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $args['before_widget'];
|
|
|
|
|
2017-10-15 23:29:51 +02:00
|
|
|
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
|
|
|
|
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
2017-10-15 23:29:51 +02:00
|
|
|
if ( $title ) {
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
echo $args['before_title'] . $title . $args['after_title'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters the media widget instance prior to rendering the media.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*
|
|
|
|
* @param array $instance Instance data.
|
|
|
|
* @param array $args Widget args.
|
2021-01-08 15:30:14 +01:00
|
|
|
* @param WP_Widget_Media $widget Widget object.
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*/
|
|
|
|
$instance = apply_filters( "widget_{$this->id_base}_instance", $instance, $args, $this );
|
|
|
|
|
|
|
|
$this->render_media( $instance );
|
|
|
|
|
|
|
|
echo $args['after_widget'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sanitizes the widget form values as they are saved.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
Code Modernization: Fix parameter name mismatches for parent/child classes in `WP_Widget::update()`.
In each child class, renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Adds @since to clearly specify why the change happened.
Replaces the original with the variable name with within each method.
Why? The new name is more specific and descriptive, which improves readability.
Follow-up to [10782], [25090], [26556], [40640].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51789
git-svn-id: http://core.svn.wordpress.org/trunk@51396 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 22:13:57 +02:00
|
|
|
* @since 5.9.0 Renamed `$instance` to `$old_instance` to match parent class
|
|
|
|
* for PHP 8 named parameter support.
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*
|
|
|
|
* @see WP_Widget::update()
|
|
|
|
* @see WP_REST_Request::has_valid_params()
|
|
|
|
* @see WP_REST_Request::sanitize_params()
|
|
|
|
*
|
|
|
|
* @param array $new_instance Values just sent to be saved.
|
Code Modernization: Fix parameter name mismatches for parent/child classes in `WP_Widget::update()`.
In each child class, renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Adds @since to clearly specify why the change happened.
Replaces the original with the variable name with within each method.
Why? The new name is more specific and descriptive, which improves readability.
Follow-up to [10782], [25090], [26556], [40640].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51789
git-svn-id: http://core.svn.wordpress.org/trunk@51396 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 22:13:57 +02:00
|
|
|
* @param array $old_instance Previously saved values from database.
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
* @return array Updated safe values to be saved.
|
|
|
|
*/
|
Code Modernization: Fix parameter name mismatches for parent/child classes in `WP_Widget::update()`.
In each child class, renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Adds @since to clearly specify why the change happened.
Replaces the original with the variable name with within each method.
Why? The new name is more specific and descriptive, which improves readability.
Follow-up to [10782], [25090], [26556], [40640].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51789
git-svn-id: http://core.svn.wordpress.org/trunk@51396 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 22:13:57 +02:00
|
|
|
public function update( $new_instance, $old_instance ) {
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
|
|
|
$schema = $this->get_instance_schema();
|
|
|
|
foreach ( $schema as $field => $field_schema ) {
|
|
|
|
if ( ! array_key_exists( $field, $new_instance ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$value = $new_instance[ $field ];
|
2017-09-25 08:28:45 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
/*
|
|
|
|
* Workaround for rest_validate_value_from_schema() due to the fact that
|
|
|
|
* rest_is_boolean( '' ) === false, while rest_is_boolean( '1' ) is true.
|
|
|
|
*/
|
2017-09-25 08:28:45 +02:00
|
|
|
if ( 'boolean' === $field_schema['type'] && '' === $value ) {
|
|
|
|
$value = false;
|
|
|
|
}
|
|
|
|
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
if ( true !== rest_validate_value_from_schema( $value, $field_schema, $field ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$value = rest_sanitize_value_from_schema( $value, $field_schema );
|
|
|
|
|
|
|
|
// @codeCoverageIgnoreStart
|
|
|
|
if ( is_wp_error( $value ) ) {
|
|
|
|
continue; // Handle case when rest_sanitize_value_from_schema() ever returns WP_Error as its phpdoc @return tag indicates.
|
|
|
|
}
|
|
|
|
|
|
|
|
// @codeCoverageIgnoreEnd
|
|
|
|
if ( isset( $field_schema['sanitize_callback'] ) ) {
|
|
|
|
$value = call_user_func( $field_schema['sanitize_callback'], $value );
|
|
|
|
}
|
|
|
|
if ( is_wp_error( $value ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
Code Modernization: Fix parameter name mismatches for parent/child classes in `WP_Widget::update()`.
In each child class, renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Adds @since to clearly specify why the change happened.
Replaces the original with the variable name with within each method.
Why? The new name is more specific and descriptive, which improves readability.
Follow-up to [10782], [25090], [26556], [40640].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51789
git-svn-id: http://core.svn.wordpress.org/trunk@51396 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 22:13:57 +02:00
|
|
|
$old_instance[ $field ] = $value;
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
}
|
|
|
|
|
Code Modernization: Fix parameter name mismatches for parent/child classes in `WP_Widget::update()`.
In each child class, renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Adds @since to clearly specify why the change happened.
Replaces the original with the variable name with within each method.
Why? The new name is more specific and descriptive, which improves readability.
Follow-up to [10782], [25090], [26556], [40640].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51789
git-svn-id: http://core.svn.wordpress.org/trunk@51396 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 22:13:57 +02:00
|
|
|
return $old_instance;
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the media on the frontend.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*
|
|
|
|
* @param array $instance Widget instance props.
|
|
|
|
*/
|
|
|
|
abstract public function render_media( $instance );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Outputs the settings update form.
|
|
|
|
*
|
|
|
|
* Note that the widget UI itself is rendered with JavaScript via `MediaWidgetControl#render()`.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*
|
|
|
|
* @see \WP_Widget_Media::render_control_template_scripts() Where the JS template is located.
|
2020-01-10 01:30:05 +01:00
|
|
|
*
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
* @param array $instance Current settings.
|
|
|
|
*/
|
|
|
|
final public function form( $instance ) {
|
|
|
|
$instance_schema = $this->get_instance_schema();
|
2017-12-01 00:11:00 +01:00
|
|
|
$instance = wp_array_slice_assoc(
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
wp_parse_args( (array) $instance, wp_list_pluck( $instance_schema, 'default' ) ),
|
|
|
|
array_keys( $instance_schema )
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ( $instance as $name => $value ) : ?>
|
|
|
|
<input
|
|
|
|
type="hidden"
|
|
|
|
data-property="<?php echo esc_attr( $name ); ?>"
|
|
|
|
class="media-widget-instance-property"
|
|
|
|
name="<?php echo esc_attr( $this->get_field_name( $name ) ); ?>"
|
|
|
|
id="<?php echo esc_attr( $this->get_field_id( $name ) ); // Needed specifically by wpWidgets.appendTitle(). ?>"
|
2020-10-18 19:27:06 +02:00
|
|
|
value="<?php echo esc_attr( is_array( $value ) ? implode( ',', $value ) : (string) $value ); ?>"
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
/>
|
2018-08-17 03:51:36 +02:00
|
|
|
<?php
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
endforeach;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters the default media display states for items in the Media list table.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*
|
|
|
|
* @param array $states An array of media states.
|
|
|
|
* @param WP_Post $post The current attachment object.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function display_media_state( $states, $post = null ) {
|
|
|
|
if ( ! $post ) {
|
|
|
|
$post = get_post();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count how many times this attachment is used in widgets.
|
|
|
|
$use_count = 0;
|
|
|
|
foreach ( $this->get_settings() as $instance ) {
|
|
|
|
if ( isset( $instance['attachment_id'] ) && $instance['attachment_id'] === $post->ID ) {
|
|
|
|
$use_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 1 === $use_count ) {
|
|
|
|
$states[] = $this->l10n['media_library_state_single'];
|
|
|
|
} elseif ( $use_count > 0 ) {
|
|
|
|
$states[] = sprintf( translate_nooped_plural( $this->l10n['media_library_state_multi'], $use_count ), number_format_i18n( $use_count ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $states;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueue preview scripts.
|
|
|
|
*
|
|
|
|
* These scripts normally are enqueued just-in-time when a widget is rendered.
|
|
|
|
* In the customizer, however, widgets can be dynamically added and rendered via
|
|
|
|
* selective refresh, and so it is important to unconditionally enqueue them in
|
|
|
|
* case a widget does get added.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*/
|
|
|
|
public function enqueue_preview_scripts() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the required scripts and styles for the widget control.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*/
|
|
|
|
public function enqueue_admin_scripts() {
|
|
|
|
wp_enqueue_media();
|
|
|
|
wp_enqueue_script( 'media-widgets' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render form template scripts.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*/
|
|
|
|
public function render_control_template_scripts() {
|
|
|
|
?>
|
|
|
|
<script type="text/html" id="tmpl-widget-media-<?php echo esc_attr( $this->id_base ); ?>-control">
|
|
|
|
<# var elementIdPrefix = 'el' + String( Math.random() ) + '_' #>
|
|
|
|
<p>
|
|
|
|
<label for="{{ elementIdPrefix }}title"><?php esc_html_e( 'Title:' ); ?></label>
|
|
|
|
<input id="{{ elementIdPrefix }}title" type="text" class="widefat title">
|
|
|
|
</p>
|
2017-09-25 08:28:45 +02:00
|
|
|
<div class="media-widget-preview <?php echo esc_attr( $this->id_base ); ?>">
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
<div class="attachment-media-view">
|
2019-03-05 18:49:52 +01:00
|
|
|
<button type="button" class="select-media button-add-media not-selected">
|
|
|
|
<?php echo esc_html( $this->l10n['add_media'] ); ?>
|
|
|
|
</button>
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<p class="media-widget-buttons">
|
|
|
|
<button type="button" class="button edit-media selected">
|
|
|
|
<?php echo esc_html( $this->l10n['edit_media'] ); ?>
|
|
|
|
</button>
|
2017-10-05 05:13:49 +02:00
|
|
|
<?php if ( ! empty( $this->l10n['replace_media'] ) ) : ?>
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
<button type="button" class="button change-media select-media selected">
|
|
|
|
<?php echo esc_html( $this->l10n['replace_media'] ); ?>
|
|
|
|
</button>
|
2017-10-05 05:13:49 +02:00
|
|
|
<?php endif; ?>
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
</p>
|
2017-08-14 19:56:42 +02:00
|
|
|
<div class="media-widget-fields">
|
|
|
|
</div>
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
</script>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the widget has content to show.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*
|
|
|
|
* @param array $instance Widget instance props.
|
|
|
|
* @return bool Whether widget has content.
|
|
|
|
*/
|
|
|
|
protected function has_content( $instance ) {
|
|
|
|
return ( $instance['attachment_id'] && 'attachment' === get_post_type( $instance['attachment_id'] ) ) || $instance['url'];
|
|
|
|
}
|
|
|
|
}
|