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_Widget_Media_Image class
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Widgets
|
|
|
|
* @since 4.8.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Core class that implements an image widget.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*
|
2019-05-14 22:23:06 +02:00
|
|
|
* @see WP_Widget_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
|
|
|
* @see WP_Widget
|
|
|
|
*/
|
|
|
|
class WP_Widget_Media_Image extends WP_Widget_Media {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
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
|
|
|
*/
|
|
|
|
public function __construct() {
|
2017-12-01 00:11:00 +01:00
|
|
|
parent::__construct(
|
2018-08-17 03:51:36 +02:00
|
|
|
'media_image',
|
|
|
|
__( 'Image' ),
|
|
|
|
array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'description' => __( 'Displays an image.' ),
|
|
|
|
'mime_type' => 'image',
|
|
|
|
)
|
|
|
|
);
|
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
|
|
|
$this->l10n = array_merge(
|
2018-08-17 03:51:36 +02:00
|
|
|
$this->l10n,
|
|
|
|
array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'no_media_selected' => __( 'No image selected' ),
|
|
|
|
'add_media' => _x( 'Add Image', 'label for button in the image widget' ),
|
|
|
|
'replace_media' => _x( 'Replace Image', 'label for button in the image widget; should preferably not be longer than ~13 characters long' ),
|
|
|
|
'edit_media' => _x( 'Edit Image', 'label for button in the image widget; should preferably not be longer than ~13 characters long' ),
|
|
|
|
'missing_attachment' => sprintf(
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %s: URL to media library. */
|
2022-04-11 14:08:09 +02:00
|
|
|
__( 'That image cannot be found. Check your <a href="%s">media library</a> and make sure it was not deleted.' ),
|
2017-12-01 00:11:00 +01: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( 'Image Widget (%d)', 'Image Widget (%d)' ),
|
|
|
|
'media_library_state_single' => __( 'Image 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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
|
|
|
return array_merge(
|
|
|
|
array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'size' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'enum' => array_merge( get_intermediate_image_sizes(), array( 'full', 'custom' ) ),
|
|
|
|
'default' => 'medium',
|
2017-05-25 04:59:44 +02:00
|
|
|
'description' => __( 'Size' ),
|
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
|
|
|
'width' => array( // Via 'customWidth', only when size=custom; otherwise via 'width'.
|
|
|
|
'type' => 'integer',
|
|
|
|
'minimum' => 0,
|
|
|
|
'default' => 0,
|
2017-05-25 04:59:44 +02:00
|
|
|
'description' => __( 'Width' ),
|
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
|
|
|
'height' => array( // Via 'customHeight', only when size=custom; otherwise via 'height'.
|
|
|
|
'type' => 'integer',
|
|
|
|
'minimum' => 0,
|
|
|
|
'default' => 0,
|
2017-05-25 04:59:44 +02:00
|
|
|
'description' => __( 'Height' ),
|
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
|
|
|
'caption' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'default' => '',
|
|
|
|
'sanitize_callback' => 'wp_kses_post',
|
|
|
|
'description' => __( 'Caption' ),
|
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-12-01 00:11:00 +01:00
|
|
|
'alt' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'default' => '',
|
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
|
|
|
'sanitize_callback' => 'sanitize_text_field',
|
2017-12-01 00:11:00 +01:00
|
|
|
'description' => __( 'Alternative Text' ),
|
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
|
|
|
'link_type' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'enum' => array( 'none', 'file', 'post', 'custom' ),
|
|
|
|
'default' => 'custom',
|
|
|
|
'media_prop' => 'link',
|
|
|
|
'description' => __( 'Link To' ),
|
2017-08-14 19:56:42 +02:00
|
|
|
'should_preview_update' => 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
|
|
|
),
|
2017-12-01 00:11:00 +01:00
|
|
|
'link_url' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'default' => '',
|
|
|
|
'format' => 'uri',
|
|
|
|
'media_prop' => 'linkUrl',
|
|
|
|
'description' => __( 'URL' ),
|
2017-08-14 19:56:42 +02:00
|
|
|
'should_preview_update' => 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
|
|
|
),
|
2017-12-01 00:11:00 +01:00
|
|
|
'image_classes' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'default' => '',
|
|
|
|
'sanitize_callback' => array( $this, 'sanitize_token_list' ),
|
|
|
|
'media_prop' => 'extraClasses',
|
|
|
|
'description' => __( 'Image CSS Class' ),
|
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-12-01 00:11:00 +01:00
|
|
|
'link_classes' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'default' => '',
|
|
|
|
'sanitize_callback' => array( $this, 'sanitize_token_list' ),
|
|
|
|
'media_prop' => 'linkClassName',
|
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-12-01 00:11:00 +01:00
|
|
|
'description' => __( 'Link CSS Class' ),
|
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
|
|
|
'link_rel' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'default' => '',
|
|
|
|
'sanitize_callback' => array( $this, 'sanitize_token_list' ),
|
|
|
|
'media_prop' => 'linkRel',
|
|
|
|
'description' => __( 'Link Rel' ),
|
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-05-25 04:59:44 +02:00
|
|
|
'link_target_blank' => array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'type' => 'boolean',
|
|
|
|
'default' => false,
|
|
|
|
'media_prop' => 'linkTargetBlank',
|
|
|
|
'description' => __( 'Open link in a new tab' ),
|
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-12-01 00:11:00 +01:00
|
|
|
'image_title' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'default' => '',
|
|
|
|
'sanitize_callback' => 'sanitize_text_field',
|
|
|
|
'media_prop' => 'title',
|
|
|
|
'description' => __( 'Image Title Attribute' ),
|
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,
|
|
|
|
),
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There are two additional properties exposed by the PostImage modal
|
|
|
|
* that don't seem to be relevant, as they may only be derived read-only
|
|
|
|
* values:
|
|
|
|
* - originalUrl
|
|
|
|
* - aspectRatio
|
|
|
|
* - height (redundant when size is not custom)
|
|
|
|
* - width (redundant when size is not custom)
|
|
|
|
*/
|
2019-04-03 00:13:52 +02:00
|
|
|
),
|
|
|
|
parent::get_instance_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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the media on the frontend.
|
|
|
|
*
|
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
|
|
|
*
|
|
|
|
* @param array $instance Widget instance props.
|
|
|
|
*/
|
|
|
|
public function render_media( $instance ) {
|
|
|
|
$instance = array_merge( wp_list_pluck( $this->get_instance_schema(), 'default' ), $instance );
|
2017-12-01 00:11:00 +01:00
|
|
|
$instance = wp_parse_args(
|
2018-08-17 03:51:36 +02:00
|
|
|
$instance,
|
|
|
|
array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'size' => 'thumbnail',
|
|
|
|
)
|
|
|
|
);
|
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 = null;
|
2020-07-22 01:14:06 +02: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
|
|
|
if ( $this->is_attachment_with_mime_type( $instance['attachment_id'], $this->widget_options['mime_type'] ) ) {
|
|
|
|
$attachment = get_post( $instance['attachment_id'] );
|
|
|
|
}
|
2020-07-22 01:14:06 +02: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
|
|
|
if ( $attachment ) {
|
2017-10-27 07:05:51 +02:00
|
|
|
$caption = '';
|
|
|
|
if ( ! isset( $instance['caption'] ) ) {
|
|
|
|
$caption = $attachment->post_excerpt;
|
|
|
|
} elseif ( trim( $instance['caption'] ) ) {
|
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
|
|
|
$caption = $instance['caption'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$image_attributes = array(
|
|
|
|
'class' => sprintf( 'image wp-image-%d %s', $attachment->ID, $instance['image_classes'] ),
|
|
|
|
'style' => 'max-width: 100%; height: auto;',
|
|
|
|
);
|
|
|
|
if ( ! empty( $instance['image_title'] ) ) {
|
|
|
|
$image_attributes['title'] = $instance['image_title'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $instance['alt'] ) {
|
|
|
|
$image_attributes['alt'] = $instance['alt'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$size = $instance['size'];
|
2020-07-22 01:14:06 +02: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
|
|
|
if ( 'custom' === $size || ! in_array( $size, array_merge( get_intermediate_image_sizes(), array( 'full' ) ), true ) ) {
|
2020-07-22 01:14:06 +02:00
|
|
|
$size = array( $instance['width'], $instance['height'] );
|
|
|
|
$width = $instance['width'];
|
|
|
|
} else {
|
|
|
|
$caption_size = _wp_get_image_size_from_meta( $instance['size'], wp_get_attachment_metadata( $attachment->ID ) );
|
|
|
|
$width = empty( $caption_size[0] ) ? 0 : $caption_size[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
|
|
|
}
|
2020-07-22 01:14:06 +02:00
|
|
|
|
2020-10-18 19:27:06 +02:00
|
|
|
$image_attributes['class'] .= sprintf( ' attachment-%1$s size-%1$s', is_array( $size ) ? implode( 'x', $size ) : $size );
|
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
|
|
|
|
|
|
|
$image = wp_get_attachment_image( $attachment->ID, $size, false, $image_attributes );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if ( empty( $instance['url'] ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$instance['size'] = 'custom';
|
2017-12-01 00:11:00 +01:00
|
|
|
$caption = $instance['caption'];
|
|
|
|
$width = $instance['width'];
|
|
|
|
$classes = 'image ' . $instance['image_classes'];
|
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 ( 0 === $instance['width'] ) {
|
|
|
|
$instance['width'] = '';
|
|
|
|
}
|
|
|
|
if ( 0 === $instance['height'] ) {
|
|
|
|
$instance['height'] = '';
|
|
|
|
}
|
|
|
|
|
2023-07-06 18:33:27 +02:00
|
|
|
$attr = array(
|
Media: Rely on `wp_get_loading_optimization_attributes()` to add `decoding="async"` to images.
The `wp_get_loading_optimization_attributes()` function was introduced in 6.3, as a single centralized place to control loading optimization attributes for various tags, most importantly images.
This changeset consolidates the `decoding="async"` optimization, which was added in 6.1, to occur solely as part of `wp_get_loading_optimization_attributes()`, removing duplicate code and allowing centralized filtering based on [56651].
As part of the change, the `wp_img_tag_add_decoding_attr()` function has been deprecated. The filter of the same name continues to be maintained for backward compatibility, as before covering only images that are part of a content blob such as post content (`the_content`).
Props pereirinha, mukesh27, joemcgill, flixos90.
Fixes #58892.
See #53232.
Built from https://develop.svn.wordpress.org/trunk@56690
git-svn-id: http://core.svn.wordpress.org/trunk@56202 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-09-26 00:38:17 +02:00
|
|
|
'class' => $classes,
|
|
|
|
'src' => $instance['url'],
|
|
|
|
'alt' => $instance['alt'],
|
|
|
|
'width' => $instance['width'],
|
|
|
|
'height' => $instance['height'],
|
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
|
|
|
);
|
2023-07-06 18:33:27 +02:00
|
|
|
|
|
|
|
$loading_optimization_attr = wp_get_loading_optimization_attributes(
|
|
|
|
'img',
|
|
|
|
$attr,
|
|
|
|
'widget_media_image'
|
|
|
|
);
|
|
|
|
|
|
|
|
$attr = array_merge( $attr, $loading_optimization_attr );
|
|
|
|
|
|
|
|
$attr = array_map( 'esc_attr', $attr );
|
|
|
|
$image = '<img';
|
|
|
|
|
|
|
|
foreach ( $attr as $name => $value ) {
|
|
|
|
$image .= ' ' . $name . '="' . $value . '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
$image .= ' />';
|
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
|
|
|
} // End if().
|
|
|
|
|
|
|
|
$url = '';
|
|
|
|
if ( 'file' === $instance['link_type'] ) {
|
|
|
|
$url = $attachment ? wp_get_attachment_url( $attachment->ID ) : $instance['url'];
|
|
|
|
} elseif ( $attachment && 'post' === $instance['link_type'] ) {
|
|
|
|
$url = get_attachment_link( $attachment->ID );
|
|
|
|
} elseif ( 'custom' === $instance['link_type'] && ! empty( $instance['link_url'] ) ) {
|
|
|
|
$url = $instance['link_url'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $url ) {
|
2017-09-20 21:45:46 +02:00
|
|
|
$link = sprintf( '<a href="%s"', esc_url( $url ) );
|
|
|
|
if ( ! empty( $instance['link_classes'] ) ) {
|
|
|
|
$link .= sprintf( ' class="%s"', esc_attr( $instance['link_classes'] ) );
|
|
|
|
}
|
|
|
|
if ( ! empty( $instance['link_rel'] ) ) {
|
|
|
|
$link .= sprintf( ' rel="%s"', esc_attr( $instance['link_rel'] ) );
|
|
|
|
}
|
|
|
|
if ( ! empty( $instance['link_target_blank'] ) ) {
|
|
|
|
$link .= ' target="_blank"';
|
|
|
|
}
|
|
|
|
$link .= '>';
|
|
|
|
$link .= $image;
|
|
|
|
$link .= '</a>';
|
General: Remove `noopener` from links opening in a new tab.
Removes the automatic addition of `rel="noopener noreferrer"` from links targeting a new tab or window, `target='_blank'`. Since this was introduced, supported browsers have changed their security policies and no longer allow the opened link to have JavaScript access to the previous tab.
Deprecates:
* `wp_targeted_link_rel()`
* `wp_targeted_link_rel_callback()`
* `wp_init_targeted_link_rel_filters()`: converted to a noop function
* `wp_remove_targeted_link_rel_filters()`: converted to a noop function
The deprecated functions are retained in `formatting.php` as in `SHORTINIT` mode the file is included while `deprecated.php` is not.
This also removes the `noopener` from links hard coded within the WordPress dashboard linking to documentation and other resources.
Props audrasjb, azaozz, dhruval04, dorzki, neo2k23, presskopp, sabernhardt, swissspidy, tobiasbg.
Fixes #53843.
Built from https://develop.svn.wordpress.org/trunk@59120
git-svn-id: http://core.svn.wordpress.org/trunk@58516 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-09-30 07:19:16 +02:00
|
|
|
$image = $link;
|
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 ( $caption ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$image = img_caption_shortcode(
|
|
|
|
array(
|
|
|
|
'width' => $width,
|
|
|
|
'caption' => $caption,
|
2018-08-17 03:51:36 +02:00
|
|
|
),
|
|
|
|
$image
|
2017-12-01 00:11:00 +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
|
|
|
}
|
|
|
|
|
|
|
|
echo $image;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the required media files for the media manager and scripts for media widgets.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*/
|
|
|
|
public function enqueue_admin_scripts() {
|
|
|
|
parent::enqueue_admin_scripts();
|
|
|
|
|
|
|
|
$handle = 'media-image-widget';
|
|
|
|
wp_enqueue_script( $handle );
|
|
|
|
|
|
|
|
$exported_schema = array();
|
|
|
|
foreach ( $this->get_instance_schema() as $field => $field_schema ) {
|
|
|
|
$exported_schema[ $field ] = wp_array_slice_assoc( $field_schema, array( 'type', 'default', 'enum', 'minimum', 'format', 'media_prop', 'should_preview_update' ) );
|
|
|
|
}
|
|
|
|
wp_add_inline_script(
|
|
|
|
$handle,
|
|
|
|
sprintf(
|
|
|
|
'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
|
|
|
|
wp_json_encode( $this->id_base ),
|
|
|
|
wp_json_encode( $exported_schema )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_add_inline_script(
|
|
|
|
$handle,
|
|
|
|
sprintf(
|
|
|
|
'
|
|
|
|
wp.mediaWidgets.controlConstructors[ %1$s ].prototype.mime_type = %2$s;
|
|
|
|
wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n = _.extend( {}, wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n, %3$s );
|
|
|
|
',
|
|
|
|
wp_json_encode( $this->id_base ),
|
|
|
|
wp_json_encode( $this->widget_options['mime_type'] ),
|
|
|
|
wp_json_encode( $this->l10n )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render form template scripts.
|
|
|
|
*
|
|
|
|
* @since 4.8.0
|
|
|
|
*/
|
|
|
|
public function render_control_template_scripts() {
|
|
|
|
parent::render_control_template_scripts();
|
|
|
|
|
|
|
|
?>
|
2017-08-14 19:56:42 +02:00
|
|
|
<script type="text/html" id="tmpl-wp-media-widget-image-fields">
|
|
|
|
<# var elementIdPrefix = 'el' + String( Math.random() ) + '_'; #>
|
|
|
|
<# if ( data.url ) { #>
|
|
|
|
<p class="media-widget-image-link">
|
|
|
|
<label for="{{ elementIdPrefix }}linkUrl"><?php esc_html_e( 'Link to:' ); ?></label>
|
2019-08-09 19:06:55 +02:00
|
|
|
<input id="{{ elementIdPrefix }}linkUrl" type="text" class="widefat link" value="{{ data.link_url }}" placeholder="https://" pattern="((\w+:)?\/\/\w.*|\w+:(?!\/\/$)|\/|\?|#).*">
|
2017-08-14 19:56:42 +02:00
|
|
|
</p>
|
|
|
|
<# } #>
|
|
|
|
</script>
|
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 type="text/html" id="tmpl-wp-media-widget-image-preview">
|
|
|
|
<# if ( data.error && 'missing_attachment' === data.error ) { #>
|
Administration: Increase `wp_admin_notice()` usage in `/wp-includes/`.
Adds further usages of `wp_admin_notice()` in the root level of `/wp-includes/` on `.error` and `.notice-info`.
Ongoing task to implement new function across core.
Follow-up to [56408], [56409], [56410], [56518], [56570], [56571], [56572], [56573], [56576], [56589], [56590].
Props joedolson, costdev.
See #57791.
Built from https://develop.svn.wordpress.org/trunk@56597
git-svn-id: http://core.svn.wordpress.org/trunk@56109 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-09-16 23:49:27 +02:00
|
|
|
<?php
|
|
|
|
wp_admin_notice(
|
|
|
|
$this->l10n['missing_attachment'],
|
|
|
|
array(
|
|
|
|
'type' => 'error',
|
|
|
|
'additional_classes' => array( 'notice-alt', 'notice-missing-attachment' ),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
?>
|
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
|
|
|
<# } else if ( data.error ) { #>
|
Administration: Increase `wp_admin_notice()` usage in `/wp-includes/`.
Adds further usages of `wp_admin_notice()` in the root level of `/wp-includes/` on `.error` and `.notice-info`.
Ongoing task to implement new function across core.
Follow-up to [56408], [56409], [56410], [56518], [56570], [56571], [56572], [56573], [56576], [56589], [56590].
Props joedolson, costdev.
See #57791.
Built from https://develop.svn.wordpress.org/trunk@56597
git-svn-id: http://core.svn.wordpress.org/trunk@56109 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-09-16 23:49:27 +02:00
|
|
|
<?php
|
|
|
|
wp_admin_notice(
|
|
|
|
__( 'Unable to preview media due to an unknown error.' ),
|
|
|
|
array(
|
|
|
|
'type' => 'error',
|
|
|
|
'additional_classes' => array( 'notice-alt' ),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
?>
|
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
|
|
|
<# } else if ( data.url ) { #>
|
2019-02-23 19:32:53 +01:00
|
|
|
<img class="attachment-thumb" src="{{ data.url }}" draggable="false" alt="{{ data.alt }}"
|
|
|
|
<# if ( ! data.alt && data.currentFilename ) { #>
|
|
|
|
aria-label="
|
|
|
|
<?php
|
|
|
|
echo esc_attr(
|
|
|
|
sprintf(
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %s: The image file name. */
|
2019-02-23 19:32:53 +01:00
|
|
|
__( 'The current image has no alternative text. The file name is: %s' ),
|
|
|
|
'{{ data.currentFilename }}'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
?>
|
|
|
|
"
|
|
|
|
<# } #>
|
|
|
|
/>
|
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
|
|
|
|
}
|
|
|
|
}
|