*
* Displays posts from Aside, Quote, Video, Audio, Image, Gallery, and Link formats.
*
- * @link http://codex.wordpress.org/Widgets_API#Developing_Widgets
+ * @link https://codex.wordpress.org/Widgets_API#Developing_Widgets
*
* @package WordPress
* @subpackage Twenty_Fourteen
*/
private $formats = array( 'aside', 'image', 'video', 'audio', 'quote', 'link', 'gallery' );
- /**
- * Pluralized post format strings.
- *
- * @access private
- * @since Twenty Fourteen 1.0
- *
- * @var array
- */
- private $format_strings;
-
/**
* Constructor.
*
public function __construct() {
parent::__construct( 'widget_twentyfourteen_ephemera', __( 'Twenty Fourteen Ephemera', 'twentyfourteen' ), array(
'classname' => 'widget_twentyfourteen_ephemera',
- 'description' => __( 'Use this widget to list your recent Aside, Quote, Video, Audio, Image, Gallery, and Link posts', 'twentyfourteen' ),
+ 'description' => __( 'Use this widget to list your recent Aside, Quote, Video, Audio, Image, Gallery, and Link posts.', 'twentyfourteen' ),
+ 'customize_selective_refresh' => true,
) );
- /*
- * @todo http://core.trac.wordpress.org/ticket/23257: Add plural versions of Post Format strings
- */
- $this->format_strings = array(
- 'aside' => __( 'Asides', 'twentyfourteen' ),
- 'image' => __( 'Images', 'twentyfourteen' ),
- 'video' => __( 'Videos', 'twentyfourteen' ),
- 'audio' => __( 'Audio', 'twentyfourteen' ),
- 'quote' => __( 'Quotes', 'twentyfourteen' ),
- 'link' => __( 'Links', 'twentyfourteen' ),
- 'gallery' => __( 'Galleries', 'twentyfourteen' ),
- );
+ if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) {
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
+ }
+ }
+
+ /**
+ * Enqueue scripts.
+ *
+ * @since Twenty Fourteen 1.7
+ */
+ public function enqueue_scripts() {
+ /** This filter is documented in wp-includes/media.php */
+ $audio_library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' );
+ /** This filter is documented in wp-includes/media.php */
+ $video_library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' );
+ if ( in_array( 'mediaelement', array( $video_library, $audio_library ), true ) ) {
+ wp_enqueue_style( 'wp-mediaelement' );
+ wp_enqueue_script( 'wp-mediaelement' );
+ }
}
/**
*
* @param array $args An array of standard parameters for widgets in this theme.
* @param array $instance An array of settings for this widget instance.
- * @return void Echoes its output.
*/
public function widget( $args, $instance ) {
- $format = $instance['format'];
+ $format = isset( $instance['format'] ) && in_array( $instance['format'], $this->formats ) ? $instance['format'] : 'aside';
+
+ switch ( $format ) {
+ case 'image':
+ $format_string = __( 'Images', 'twentyfourteen' );
+ $format_string_more = __( 'More images', 'twentyfourteen' );
+ break;
+ case 'video':
+ $format_string = __( 'Videos', 'twentyfourteen' );
+ $format_string_more = __( 'More videos', 'twentyfourteen' );
+ break;
+ case 'audio':
+ $format_string = __( 'Audio', 'twentyfourteen' );
+ $format_string_more = __( 'More audio', 'twentyfourteen' );
+ break;
+ case 'quote':
+ $format_string = __( 'Quotes', 'twentyfourteen' );
+ $format_string_more = __( 'More quotes', 'twentyfourteen' );
+ break;
+ case 'link':
+ $format_string = __( 'Links', 'twentyfourteen' );
+ $format_string_more = __( 'More links', 'twentyfourteen' );
+ break;
+ case 'gallery':
+ $format_string = __( 'Galleries', 'twentyfourteen' );
+ $format_string_more = __( 'More galleries', 'twentyfourteen' );
+ break;
+ case 'aside':
+ default:
+ $format_string = __( 'Asides', 'twentyfourteen' );
+ $format_string_more = __( 'More asides', 'twentyfourteen' );
+ break;
+ }
+
$number = empty( $instance['number'] ) ? 2 : absint( $instance['number'] );
- $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? $this->format_strings[ $format ] : $instance['title'], $instance, $this->id_base );
+ $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? $format_string : $instance['title'], $instance, $this->id_base );
$ephemera = new WP_Query( array(
'order' => 'DESC',
echo $args['before_widget'];
?>
<h1 class="widget-title <?php echo esc_attr( $format ); ?>">
- <a class="entry-format" href="<?php echo esc_url( get_post_format_link( $format ) ); ?>"><?php echo $title; ?></a>
+ <a class="entry-format" href="<?php echo esc_url( get_post_format_link( $format ) ); ?>"><?php echo esc_html( $title ); ?></a>
</h1>
<ol>
- <?php while ( $ephemera->have_posts() ) : $ephemera->the_post(); ?>
+ <?php
+ while ( $ephemera->have_posts() ) :
+ $ephemera->the_post();
+ $tmp_more = $GLOBALS['more'];
+ $GLOBALS['more'] = 0;
+ ?>
<li>
<article <?php post_class(); ?>>
<div class="entry-content">
if ( has_post_thumbnail() ) :
$post_thumbnail = get_the_post_thumbnail();
elseif ( $total_images > 0 ) :
- $image = array_shift( $images );
+ $image = reset( $images );
$post_thumbnail = wp_get_attachment_image( $image, 'post-thumbnail' );
endif;
<?php endwhile; ?>
</ol>
- <a class="post-format-archive-link" href="<?php echo esc_url( get_post_format_link( $format ) ); ?>"><?php printf( __( 'More %s <span class="meta-nav">→</span>', 'twentyfourteen' ), $this->format_strings[ $format ] ); ?></a>
+ <a class="post-format-archive-link" href="<?php echo esc_url( get_post_format_link( $format ) ); ?>">
+ <?php
+ /* translators: used with More archives link */
+ printf( __( '%s <span class="meta-nav">→</span>', 'twentyfourteen' ), $format_string_more );
+ ?>
+ </a>
<?php
echo $args['after_widget'];
// Reset the post globals as this query will have stomped on it.
wp_reset_postdata();
+ $GLOBALS['more'] = $tmp_more;
$GLOBALS['content_width'] = $tmp_content_width;
endif; // End check for ephemeral posts.
* @since Twenty Fourteen 1.0
*
* @param array $instance
- * @return void
*/
function form( $instance ) {
$title = empty( $instance['title'] ) ? '' : esc_attr( $instance['title'] );
<p><label for="<?php echo esc_attr( $this->get_field_id( 'format' ) ); ?>"><?php _e( 'Post format to show:', 'twentyfourteen' ); ?></label>
<select id="<?php echo esc_attr( $this->get_field_id( 'format' ) ); ?>" class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'format' ) ); ?>">
<?php foreach ( $this->formats as $slug ) : ?>
- <option value="<?php echo esc_attr( $slug ); ?>"<?php selected( $format, $slug ); ?>><?php echo get_post_format_string( $slug ); ?></option>
+ <option value="<?php echo esc_attr( $slug ); ?>"<?php selected( $format, $slug ); ?>><?php echo esc_html( get_post_format_string( $slug ) ); ?></option>
<?php endforeach; ?>
</select>
<?php