25
25
public $l10n = array(
26
'add_to_widget' => '',
27
'replace_media' => '',
29
'media_library_state_multi' => '',
26
'add_to_widget' => '',
27
'replace_media' => '',
29
'media_library_state_multi' => '',
30
30
'media_library_state_single' => '',
31
'missing_attachment' => '',
32
'no_media_selected' => '',
31
'missing_attachment' => '',
32
'no_media_selected' => '',
54
54
* for information on accepted arguments. Default empty array.
56
56
public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
57
$widget_opts = wp_parse_args( $widget_options, array(
58
'description' => __( 'A media item.' ),
59
'customize_selective_refresh' => true,
57
$widget_opts = wp_parse_args(
60
'description' => __( 'A media item.' ),
61
'customize_selective_refresh' => true,
63
66
$control_opts = wp_parse_args( $control_options, array() );
65
68
$l10n_defaults = array(
66
'no_media_selected' => __( 'No media selected' ),
67
'add_media' => _x( 'Add Media', 'label for button in the media widget' ),
68
'replace_media' => _x( 'Replace Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
69
'edit_media' => _x( 'Edit Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
70
'add_to_widget' => __( 'Add to Widget' ),
71
'missing_attachment' => sprintf(
69
'no_media_selected' => __( 'No media selected' ),
70
'add_media' => _x( 'Add Media', 'label for button in the media widget' ),
71
'replace_media' => _x( 'Replace Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
72
'edit_media' => _x( 'Edit Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
73
'add_to_widget' => __( 'Add to Widget' ),
74
'missing_attachment' => sprintf(
72
75
/* translators: %s: URL to media library */
73
76
__( 'We can’t find that file. Check your <a href="%s">media library</a> and make sure it wasn’t deleted.' ),
74
77
esc_url( admin_url( 'upload.php' ) )
76
79
/* translators: %d: widget count */
77
'media_library_state_multi' => _n_noop( 'Media Widget (%d)', 'Media Widget (%d)' ),
80
'media_library_state_multi' => _n_noop( 'Media Widget (%d)', 'Media Widget (%d)' ),
78
81
'media_library_state_single' => __( 'Media Widget' ),
79
'unsupported_file_type' => __( 'Looks like this isn’t the correct kind of file. Please link to an appropriate file instead.' ),
82
'unsupported_file_type' => __( 'Looks like this isn’t the correct kind of file. Please link to an appropriate file instead.' ),
81
$this->l10n = array_merge( $l10n_defaults, array_filter( $this->l10n ) );
84
$this->l10n = array_merge( $l10n_defaults, array_filter( $this->l10n ) );
83
86
parent::__construct(
129
132
public function get_instance_schema() {
131
134
'attachment_id' => array(
135
138
'description' => __( 'Attachment post ID' ),
136
'media_prop' => 'id',
139
'media_prop' => 'id',
142
145
'description' => __( 'URL to the media file' ),
147
'sanitize_callback' => 'sanitize_text_field',
148
'description' => __( 'Title for the widget' ),
150
'sanitize_callback' => 'sanitize_text_field',
151
'description' => __( 'Title for the widget' ),
149
152
'should_preview_update' => false,
323
326
final public function form( $instance ) {
324
327
$instance_schema = $this->get_instance_schema();
325
$instance = wp_array_slice_assoc(
328
$instance = wp_array_slice_assoc(
326
329
wp_parse_args( (array) $instance, wp_list_pluck( $instance_schema, 'default' ) ),
327
330
array_keys( $instance_schema )