wp/wp-includes/widgets/class-wp-widget-media-video.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 19 3d72ae0968f4
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    10 /**
    10 /**
    11  * Core class that implements a video widget.
    11  * Core class that implements a video widget.
    12  *
    12  *
    13  * @since 4.8.0
    13  * @since 4.8.0
    14  *
    14  *
       
    15  * @see WP_Widget_Media
    15  * @see WP_Widget
    16  * @see WP_Widget
    16  */
    17  */
    17 class WP_Widget_Media_Video extends WP_Widget_Media {
    18 class WP_Widget_Media_Video extends WP_Widget_Media {
    18 
    19 
    19 	/**
    20 	/**
    37 				'no_media_selected'          => __( 'No video selected' ),
    38 				'no_media_selected'          => __( 'No video selected' ),
    38 				'add_media'                  => _x( 'Add Video', 'label for button in the video widget' ),
    39 				'add_media'                  => _x( 'Add Video', 'label for button in the video widget' ),
    39 				'replace_media'              => _x( 'Replace Video', 'label for button in the video widget; should preferably not be longer than ~13 characters long' ),
    40 				'replace_media'              => _x( 'Replace Video', 'label for button in the video widget; should preferably not be longer than ~13 characters long' ),
    40 				'edit_media'                 => _x( 'Edit Video', 'label for button in the video widget; should preferably not be longer than ~13 characters long' ),
    41 				'edit_media'                 => _x( 'Edit Video', 'label for button in the video widget; should preferably not be longer than ~13 characters long' ),
    41 				'missing_attachment'         => sprintf(
    42 				'missing_attachment'         => sprintf(
    42 					/* translators: %s: URL to media library */
    43 					/* translators: %s: URL to media library. */
    43 					__( 'We can&#8217;t find that video. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
    44 					__( 'We can&#8217;t find that video. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
    44 					esc_url( admin_url( 'upload.php' ) )
    45 					esc_url( admin_url( 'upload.php' ) )
    45 				),
    46 				),
    46 				/* translators: %d: widget count */
    47 				/* translators: %d: Widget count. */
    47 				'media_library_state_multi'  => _n_noop( 'Video Widget (%d)', 'Video Widget (%d)' ),
    48 				'media_library_state_multi'  => _n_noop( 'Video Widget (%d)', 'Video Widget (%d)' ),
    48 				'media_library_state_single' => __( 'Video Widget' ),
    49 				'media_library_state_single' => __( 'Video Widget' ),
    49 				/* translators: %s: a list of valid video file extensions */
    50 				/* translators: %s: A list of valid video file extensions. */
    50 				'unsupported_file_type'      => sprintf( __( 'Sorry, we can&#8217;t load the video at the supplied URL. Please check that the URL is for a supported video file (%s) or stream (e.g. YouTube and Vimeo).' ), '<code>.' . implode( '</code>, <code>.', wp_get_video_extensions() ) . '</code>' ),
    51 				'unsupported_file_type'      => sprintf( __( 'Sorry, we can&#8217;t load the video at the supplied URL. Please check that the URL is for a supported video file (%s) or stream (e.g. YouTube and Vimeo).' ), '<code>.' . implode( '</code>, <code>.', wp_get_video_extensions() ) . '</code>' ),
    51 			)
    52 			)
    52 		);
    53 		);
    53 	}
    54 	}
    54 
    55 
    58 	 * @since 4.8.0
    59 	 * @since 4.8.0
    59 	 *
    60 	 *
    60 	 * @see WP_REST_Controller::get_item_schema()
    61 	 * @see WP_REST_Controller::get_item_schema()
    61 	 * @see WP_REST_Controller::get_additional_fields()
    62 	 * @see WP_REST_Controller::get_additional_fields()
    62 	 * @link https://core.trac.wordpress.org/ticket/35574
    63 	 * @link https://core.trac.wordpress.org/ticket/35574
       
    64 	 *
    63 	 * @return array Schema for properties.
    65 	 * @return array Schema for properties.
    64 	 */
    66 	 */
    65 	public function get_instance_schema() {
    67 	public function get_instance_schema() {
    66 
    68 
    67 		$schema = array(
    69 		$schema = array(
    90 		foreach ( wp_get_video_extensions() as $video_extension ) {
    92 		foreach ( wp_get_video_extensions() as $video_extension ) {
    91 			$schema[ $video_extension ] = array(
    93 			$schema[ $video_extension ] = array(
    92 				'type'        => 'string',
    94 				'type'        => 'string',
    93 				'default'     => '',
    95 				'default'     => '',
    94 				'format'      => 'uri',
    96 				'format'      => 'uri',
    95 				/* translators: %s: video extension */
    97 				/* translators: %s: Video extension. */
    96 				'description' => sprintf( __( 'URL to the %s video source file' ), $video_extension ),
    98 				'description' => sprintf( __( 'URL to the %s video source file' ), $video_extension ),
    97 			);
    99 			);
    98 		}
   100 		}
    99 
   101 
   100 		return array_merge( $schema, parent::get_instance_schema() );
   102 		return array_merge( $schema, parent::get_instance_schema() );
   104 	 * Render the media on the frontend.
   106 	 * Render the media on the frontend.
   105 	 *
   107 	 *
   106 	 * @since 4.8.0
   108 	 * @since 4.8.0
   107 	 *
   109 	 *
   108 	 * @param array $instance Widget instance props.
   110 	 * @param array $instance Widget instance props.
   109 	 *
       
   110 	 * @return void
       
   111 	 */
   111 	 */
   112 	public function render_media( $instance ) {
   112 	public function render_media( $instance ) {
   113 		$instance   = array_merge( wp_list_pluck( $this->get_instance_schema(), 'default' ), $instance );
   113 		$instance   = array_merge( wp_list_pluck( $this->get_instance_schema(), 'default' ), $instance );
   114 		$attachment = null;
   114 		$attachment = null;
   115 
   115