237 } |
237 } |
238 if ( 0 === $instance['height'] ) { |
238 if ( 0 === $instance['height'] ) { |
239 $instance['height'] = ''; |
239 $instance['height'] = ''; |
240 } |
240 } |
241 |
241 |
242 $image = sprintf( |
242 $attr = array( |
243 '<img class="%1$s" src="%2$s" alt="%3$s" width="%4$s" height="%5$s" />', |
243 'class' => $classes, |
244 esc_attr( $classes ), |
244 'src' => $instance['url'], |
245 esc_url( $instance['url'] ), |
245 'alt' => $instance['alt'], |
246 esc_attr( $instance['alt'] ), |
246 'width' => $instance['width'], |
247 esc_attr( $instance['width'] ), |
247 'height' => $instance['height'], |
248 esc_attr( $instance['height'] ) |
|
249 ); |
248 ); |
|
249 |
|
250 $loading_optimization_attr = wp_get_loading_optimization_attributes( |
|
251 'img', |
|
252 $attr, |
|
253 'widget_media_image' |
|
254 ); |
|
255 |
|
256 $attr = array_merge( $attr, $loading_optimization_attr ); |
|
257 |
|
258 $attr = array_map( 'esc_attr', $attr ); |
|
259 $image = '<img'; |
|
260 |
|
261 foreach ( $attr as $name => $value ) { |
|
262 $image .= ' ' . $name . '="' . $value . '"'; |
|
263 } |
|
264 |
|
265 $image .= ' />'; |
250 } // End if(). |
266 } // End if(). |
251 |
267 |
252 $url = ''; |
268 $url = ''; |
253 if ( 'file' === $instance['link_type'] ) { |
269 if ( 'file' === $instance['link_type'] ) { |
254 $url = $attachment ? wp_get_attachment_url( $attachment->ID ) : $instance['url']; |
270 $url = $attachment ? wp_get_attachment_url( $attachment->ID ) : $instance['url']; |
344 </p> |
360 </p> |
345 <# } #> |
361 <# } #> |
346 </script> |
362 </script> |
347 <script type="text/html" id="tmpl-wp-media-widget-image-preview"> |
363 <script type="text/html" id="tmpl-wp-media-widget-image-preview"> |
348 <# if ( data.error && 'missing_attachment' === data.error ) { #> |
364 <# if ( data.error && 'missing_attachment' === data.error ) { #> |
349 <div class="notice notice-error notice-alt notice-missing-attachment"> |
365 <?php |
350 <p><?php echo $this->l10n['missing_attachment']; ?></p> |
366 wp_admin_notice( |
351 </div> |
367 $this->l10n['missing_attachment'], |
|
368 array( |
|
369 'type' => 'error', |
|
370 'additional_classes' => array( 'notice-alt', 'notice-missing-attachment' ), |
|
371 ) |
|
372 ); |
|
373 ?> |
352 <# } else if ( data.error ) { #> |
374 <# } else if ( data.error ) { #> |
353 <div class="notice notice-error notice-alt"> |
375 <?php |
354 <p><?php _e( 'Unable to preview media due to an unknown error.' ); ?></p> |
376 wp_admin_notice( |
355 </div> |
377 __( 'Unable to preview media due to an unknown error.' ), |
|
378 array( |
|
379 'type' => 'error', |
|
380 'additional_classes' => array( 'notice-alt' ), |
|
381 ) |
|
382 ); |
|
383 ?> |
356 <# } else if ( data.url ) { #> |
384 <# } else if ( data.url ) { #> |
357 <img class="attachment-thumb" src="{{ data.url }}" draggable="false" alt="{{ data.alt }}" |
385 <img class="attachment-thumb" src="{{ data.url }}" draggable="false" alt="{{ data.alt }}" |
358 <# if ( ! data.alt && data.currentFilename ) { #> |
386 <# if ( ! data.alt && data.currentFilename ) { #> |
359 aria-label=" |
387 aria-label=" |
360 <?php |
388 <?php |