~canonical-sysadmins/wordpress/5.1

« back to all changes in this revision

Viewing changes to wp-includes/widgets/class-wp-widget-media.php

  • Committer: Barry Price
  • Date: 2019-02-22 03:51:26 UTC
  • mfrom: (1.2.12 upstream)
  • Revision ID: barry.price@canonical.com-20190222035126-o28k38qs8jfyjsxt
Merge WP5.1 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
         * @var array
24
24
         */
25
25
        public $l10n = array(
26
 
                'add_to_widget' => '',
27
 
                'replace_media' => '',
28
 
                'edit_media' => '',
29
 
                'media_library_state_multi' => '',
 
26
                'add_to_widget'              => '',
 
27
                'replace_media'              => '',
 
28
                'edit_media'                 => '',
 
29
                'media_library_state_multi'  => '',
30
30
                'media_library_state_single' => '',
31
 
                'missing_attachment' => '',
32
 
                'no_media_selected' => '',
33
 
                'add_media' => '',
 
31
                'missing_attachment'         => '',
 
32
                'no_media_selected'          => '',
 
33
                'add_media'                  => '',
34
34
        );
35
35
 
36
36
        /**
54
54
         *                                for information on accepted arguments. Default empty array.
55
55
         */
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,
60
 
                        'mime_type' => '',
61
 
                ) );
 
57
                $widget_opts = wp_parse_args(
 
58
                        $widget_options,
 
59
                        array(
 
60
                                'description'                 => __( 'A media item.' ),
 
61
                                'customize_selective_refresh' => true,
 
62
                                'mime_type'                   => '',
 
63
                        )
 
64
                );
62
65
 
63
66
                $control_opts = wp_parse_args( $control_options, array() );
64
67
 
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&#8217;t find that file. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
74
77
                                esc_url( admin_url( 'upload.php' ) )
75
78
                        ),
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&#8217;t the correct kind of file. Please link to an appropriate file instead.' ),
 
82
                        'unsupported_file_type'      => __( 'Looks like this isn&#8217;t the correct kind of file. Please link to an appropriate file instead.' ),
80
83
                );
81
 
                $this->l10n = array_merge( $l10n_defaults, array_filter( $this->l10n ) );
 
84
                $this->l10n    = array_merge( $l10n_defaults, array_filter( $this->l10n ) );
82
85
 
83
86
                parent::__construct(
84
87
                        $id_base,
129
132
        public function get_instance_schema() {
130
133
                $schema = array(
131
134
                        'attachment_id' => array(
132
 
                                'type' => 'integer',
133
 
                                'default' => 0,
134
 
                                'minimum' => 0,
 
135
                                'type'        => 'integer',
 
136
                                'default'     => 0,
 
137
                                'minimum'     => 0,
135
138
                                'description' => __( 'Attachment post ID' ),
136
 
                                'media_prop' => 'id',
 
139
                                'media_prop'  => 'id',
137
140
                        ),
138
 
                        'url' => array(
139
 
                                'type' => 'string',
140
 
                                'default' => '',
141
 
                                'format' => 'uri',
 
141
                        'url'           => array(
 
142
                                'type'        => 'string',
 
143
                                'default'     => '',
 
144
                                'format'      => 'uri',
142
145
                                'description' => __( 'URL to the media file' ),
143
146
                        ),
144
 
                        'title' => array(
145
 
                                'type' => 'string',
146
 
                                'default' => '',
147
 
                                'sanitize_callback' => 'sanitize_text_field',
148
 
                                'description' => __( 'Title for the widget' ),
 
147
                        'title'         => array(
 
148
                                'type'                  => 'string',
 
149
                                'default'               => '',
 
150
                                'sanitize_callback'     => 'sanitize_text_field',
 
151
                                'description'           => __( 'Title for the widget' ),
149
152
                                'should_preview_update' => false,
150
153
                        ),
151
154
                );
322
325
         */
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 )
328
331
                );
336
339
                                id="<?php echo esc_attr( $this->get_field_id( $name ) ); // Needed specifically by wpWidgets.appendTitle(). ?>"
337
340
                                value="<?php echo esc_attr( is_array( $value ) ? join( ',', $value ) : strval( $value ) ); ?>"
338
341
                        />
339
 
                <?php
 
342
                        <?php
340
343
                endforeach;
341
344
        }
342
345