2011-04-20 17:46:33 -04:00
|
|
|
<?php
|
|
|
|
/**
|
2013-09-25 12:50:11 -04:00
|
|
|
* Widget For displaying post format posts
|
2011-05-02 17:04:44 -04:00
|
|
|
*
|
2013-09-25 12:50:11 -04:00
|
|
|
* Handles displaying Aside, Link, Status, and Quote Posts available with Twenty Eleven.
|
|
|
|
*
|
2019-07-25 18:46:55 -04:00
|
|
|
* @link https://developer.wordpress.org/themes/functionality/widgets/#developing-widgets
|
2011-05-02 17:04:44 -04:00
|
|
|
*
|
|
|
|
* @package WordPress
|
2011-05-18 15:06:09 -04:00
|
|
|
* @subpackage Twenty_Eleven
|
2011-05-02 17:04:44 -04:00
|
|
|
* @since Twenty Eleven 1.0
|
2011-04-20 17:46:33 -04:00
|
|
|
*/
|
|
|
|
class Twenty_Eleven_Ephemera_Widget extends WP_Widget {
|
2011-04-26 14:34:52 -04:00
|
|
|
|
2011-04-20 17:46:33 -04:00
|
|
|
/**
|
2015-07-04 16:29:23 -04:00
|
|
|
* PHP5 constructor.
|
2011-04-20 17:46:33 -04:00
|
|
|
*
|
2015-07-04 16:29:23 -04:00
|
|
|
* @since Twenty Eleven 2.2
|
|
|
|
*/
|
|
|
|
function __construct() {
|
2017-11-30 18:11:00 -05:00
|
|
|
parent::__construct(
|
2018-08-16 21:51:36 -04:00
|
|
|
'widget_twentyeleven_ephemera',
|
|
|
|
__( 'Twenty Eleven Ephemera', 'twentyeleven' ),
|
|
|
|
array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'classname' => 'widget_twentyeleven_ephemera',
|
|
|
|
'description' => __( 'Use this widget to list your recent Aside, Status, Quote, and Link posts', 'twentyeleven' ),
|
|
|
|
'customize_selective_refresh' => true,
|
|
|
|
)
|
|
|
|
);
|
2011-04-20 17:46:33 -04:00
|
|
|
$this->alt_option_name = 'widget_twentyeleven_ephemera';
|
2011-04-26 14:34:52 -04:00
|
|
|
|
2015-01-21 19:42:23 -05:00
|
|
|
add_action( 'save_post', array( &$this, 'flush_widget_cache' ) );
|
|
|
|
add_action( 'deleted_post', array( &$this, 'flush_widget_cache' ) );
|
|
|
|
add_action( 'switch_theme', array( &$this, 'flush_widget_cache' ) );
|
2011-04-20 17:46:33 -04:00
|
|
|
}
|
|
|
|
|
2015-07-04 16:29:23 -04:00
|
|
|
/**
|
|
|
|
* PHP4 constructor.
|
|
|
|
*
|
|
|
|
* @since Twenty Eleven 1.0
|
|
|
|
*/
|
|
|
|
function Twenty_Eleven_Ephemera_Widget() {
|
|
|
|
self::__construct();
|
|
|
|
}
|
|
|
|
|
2011-04-20 17:46:33 -04:00
|
|
|
/**
|
|
|
|
* Outputs the HTML for this widget.
|
|
|
|
*
|
2013-09-25 12:50:11 -04:00
|
|
|
* @since Twenty Eleven 1.0
|
|
|
|
*
|
|
|
|
* @param array $args An array of standard parameters for widgets in this theme.
|
|
|
|
* @param array $instance An array of settings for this widget instance.
|
2017-11-30 18:11:00 -05:00
|
|
|
*/
|
2011-04-20 17:46:33 -04:00
|
|
|
function widget( $args, $instance ) {
|
|
|
|
$cache = wp_cache_get( 'widget_twentyeleven_ephemera', 'widget' );
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! is_array( $cache ) ) {
|
2011-04-20 17:46:33 -04:00
|
|
|
$cache = array();
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2011-04-20 17:46:33 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! isset( $args['widget_id'] ) ) {
|
2011-04-20 17:46:33 -04:00
|
|
|
$args['widget_id'] = null;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2011-04-20 17:46:33 -04:00
|
|
|
|
2016-05-29 12:06:30 -04:00
|
|
|
if ( ! is_customize_preview() && isset( $cache[ $args['widget_id'] ] ) ) {
|
2015-01-21 19:42:23 -05:00
|
|
|
echo $cache[ $args['widget_id'] ];
|
2011-04-20 17:46:33 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-26 14:34:52 -04:00
|
|
|
ob_start();
|
|
|
|
|
2013-10-24 18:59:20 -04:00
|
|
|
/** This filter is documented in wp-includes/default-widgets.php */
|
2015-01-21 19:42:23 -05:00
|
|
|
$args['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Ephemera', 'twentyeleven' ) : $instance['title'], $instance, $this->id_base );
|
2011-04-26 14:34:52 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! isset( $instance['number'] ) ) {
|
2011-04-20 17:46:33 -04:00
|
|
|
$instance['number'] = '10';
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2011-04-26 14:34:52 -04:00
|
|
|
|
2019-07-01 04:23:57 -04:00
|
|
|
$args['number'] = absint( $instance['number'] );
|
|
|
|
if ( ! $args['number'] ) {
|
2015-01-21 19:42:23 -05:00
|
|
|
$args['number'] = 10;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2011-04-20 17:46:33 -04:00
|
|
|
|
|
|
|
$ephemera_args = array(
|
2015-01-21 19:42:23 -05:00
|
|
|
'order' => 'DESC',
|
|
|
|
'posts_per_page' => $args['number'],
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'post__not_in' => get_option( 'sticky_posts' ),
|
|
|
|
'tax_query' => array(
|
2011-04-20 17:46:33 -04:00
|
|
|
array(
|
|
|
|
'taxonomy' => 'post_format',
|
2015-01-21 19:42:23 -05:00
|
|
|
'terms' => array( 'post-format-aside', 'post-format-link', 'post-format-status', 'post-format-quote' ),
|
|
|
|
'field' => 'slug',
|
2011-04-20 17:46:33 -04:00
|
|
|
'operator' => 'IN',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2017-11-30 18:11:00 -05:00
|
|
|
$ephemera = new WP_Query( $ephemera_args );
|
2011-04-20 17:46:33 -04:00
|
|
|
|
|
|
|
if ( $ephemera->have_posts() ) :
|
2015-01-21 19:42:23 -05:00
|
|
|
echo $args['before_widget'];
|
|
|
|
echo $args['before_title'];
|
|
|
|
echo $args['title'];
|
|
|
|
echo $args['after_title'];
|
2011-11-15 19:08:29 -05:00
|
|
|
?>
|
|
|
|
<ol>
|
2017-11-30 18:11:00 -05:00
|
|
|
<?php
|
|
|
|
while ( $ephemera->have_posts() ) :
|
|
|
|
$ephemera->the_post();
|
2018-08-16 21:51:36 -04:00
|
|
|
?>
|
2011-11-15 19:08:29 -05:00
|
|
|
|
|
|
|
<?php if ( 'link' != get_post_format() ) : ?>
|
|
|
|
|
|
|
|
<li class="widget-entry-title">
|
2013-04-29 12:57:30 -04:00
|
|
|
<a href="<?php echo esc_url( get_permalink() ); ?>" rel="bookmark"><?php the_title(); ?></a>
|
2011-11-15 19:08:29 -05:00
|
|
|
<span class="comments-link">
|
|
|
|
<?php comments_popup_link( __( '0 <span class="reply">comments →</span>', 'twentyeleven' ), __( '1 <span class="reply">comment →</span>', 'twentyeleven' ), __( '% <span class="reply">comments →</span>', 'twentyeleven' ) ); ?>
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<?php else : ?>
|
|
|
|
|
|
|
|
<li class="widget-entry-title">
|
2013-04-29 12:57:30 -04:00
|
|
|
<a href="<?php echo esc_url( twentyeleven_get_first_url() ); ?>" rel="bookmark"><?php the_title(); ?> <span>→</span></a>
|
2011-11-15 19:08:29 -05:00
|
|
|
<span class="comments-link">
|
|
|
|
<?php comments_popup_link( __( '0 <span class="reply">comments →</span>', 'twentyeleven' ), __( '1 <span class="reply">comment →</span>', 'twentyeleven' ), __( '% <span class="reply">comments →</span>', 'twentyeleven' ) ); ?>
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
<?php endwhile; ?>
|
|
|
|
</ol>
|
|
|
|
<?php
|
|
|
|
|
2015-01-21 19:42:23 -05:00
|
|
|
echo $args['after_widget'];
|
2011-11-15 19:08:29 -05:00
|
|
|
|
|
|
|
// Reset the post globals as this query will have stomped on it
|
|
|
|
wp_reset_postdata();
|
2011-04-20 17:46:33 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
// end check for ephemeral posts
|
2011-04-20 17:46:33 -04:00
|
|
|
endif;
|
|
|
|
|
2015-01-21 19:42:23 -05:00
|
|
|
$cache[ $args['widget_id'] ] = ob_get_flush();
|
2016-05-29 12:06:30 -04:00
|
|
|
if ( ! is_customize_preview() ) {
|
|
|
|
wp_cache_set( 'widget_twentyeleven_ephemera', $cache, 'widget' );
|
|
|
|
}
|
|
|
|
|
2011-04-20 17:46:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-25 12:50:11 -04:00
|
|
|
* Update widget settings.
|
|
|
|
*
|
2011-04-20 17:46:33 -04:00
|
|
|
* Deals with the settings when they are saved by the admin. Here is
|
|
|
|
* where any validation should be dealt with.
|
2013-09-25 12:50:11 -04:00
|
|
|
*
|
|
|
|
* @since Twenty Eleven 1.0
|
2017-11-30 18:11:00 -05:00
|
|
|
*/
|
2011-04-20 17:46:33 -04:00
|
|
|
function update( $new_instance, $old_instance ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$instance = $old_instance;
|
|
|
|
$instance['title'] = strip_tags( $new_instance['title'] );
|
2011-04-20 17:46:33 -04:00
|
|
|
$instance['number'] = (int) $new_instance['number'];
|
|
|
|
$this->flush_widget_cache();
|
|
|
|
|
|
|
|
$alloptions = wp_cache_get( 'alloptions', 'options' );
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( isset( $alloptions['widget_twentyeleven_ephemera'] ) ) {
|
2011-04-20 17:46:33 -04:00
|
|
|
delete_option( 'widget_twentyeleven_ephemera' );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2011-04-20 17:46:33 -04:00
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
2011-04-26 14:34:52 -04:00
|
|
|
|
2013-09-25 12:50:11 -04:00
|
|
|
/**
|
|
|
|
* Flush widget cache.
|
|
|
|
*
|
|
|
|
* @since Twenty Eleven 1.0
|
|
|
|
*/
|
2011-04-20 17:46:33 -04:00
|
|
|
function flush_widget_cache() {
|
|
|
|
wp_cache_delete( 'widget_twentyeleven_ephemera', 'widget' );
|
2011-04-26 14:34:52 -04:00
|
|
|
}
|
2011-04-20 17:46:33 -04:00
|
|
|
|
|
|
|
/**
|
2013-09-25 12:50:11 -04:00
|
|
|
* Set up the widget form.
|
|
|
|
*
|
2011-04-20 17:46:33 -04:00
|
|
|
* Displays the form for this widget on the Widgets page of the WP Admin area.
|
2013-09-25 12:50:11 -04:00
|
|
|
*
|
|
|
|
* @since Twenty Eleven 1.0
|
2017-11-30 18:11:00 -05:00
|
|
|
*/
|
2011-04-20 17:46:33 -04:00
|
|
|
function form( $instance ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
|
2011-04-27 00:45:11 -04:00
|
|
|
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 10;
|
2018-08-16 21:51:36 -04:00
|
|
|
?>
|
2011-04-27 00:45:11 -04:00
|
|
|
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'twentyeleven' ); ?></label>
|
|
|
|
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /></p>
|
|
|
|
|
|
|
|
<p><label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php _e( 'Number of posts to show:', 'twentyeleven' ); ?></label>
|
|
|
|
<input id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" type="text" value="<?php echo esc_attr( $number ); ?>" size="3" /></p>
|
2011-04-20 17:46:33 -04:00
|
|
|
<?php
|
|
|
|
}
|
2015-04-12 17:29:32 -04:00
|
|
|
}
|