Last active
September 13, 2017 14:57
-
-
Save keesiemeijer/ef760592e2f7e039155ea0dfec3d3c6d to your computer and use it in GitHub Desktop.
Widget with checkbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'widgets_init', 'register_my_scheduled_posts_widget' ); | |
function register_my_scheduled_posts_widget() { | |
register_widget( 'My_Scheduled_Posts_Widget' ); | |
} | |
class My_Scheduled_Posts_Widget extends WP_Widget { | |
public function __construct() { | |
$widget_ops = array( | |
'classname' => 'scheduled_recent_entries', | |
'description' => __( 'Your site’s most recent (scheduled) Posts.' ), | |
'customize_selective_refresh' => true, | |
); | |
parent::__construct( 'scheduled-recent-posts', __( 'Scheduled Posts' ), $widget_ops ); | |
} | |
/** | |
* Widget display. | |
*/ | |
public function widget( $args, $instance ) { | |
$status_future = (bool) $instance['status_future']; | |
/* ***** Query for recent posts and display them in the front end here ***** */ | |
} | |
/** | |
* Update widget settings. | |
*/ | |
public function update( $new_instance, $old_instance ) { | |
$instance = $old_instance; | |
$instance['status_future'] = isset( $new_instance['status_future'] ) ? (bool) $new_instance['status_future'] : false; | |
return $instance; | |
} | |
/** | |
* Widget settings form. | |
*/ | |
public function form( $instance ) { | |
$status_future = isset ( $instance['status_future'] ) ? (bool) $instance['status_future'] : false; | |
?> | |
<p> | |
<input class="checkbox" type="checkbox" <?php checked( $status_future, true ); ?> id="<?php echo $this->get_field_id( 'status_future' ); ?>" name="<?php echo $this->get_field_name( 'status_future' ); ?>"> | |
<label for="<?php echo $this->get_field_id( 'status_future' ); ?>"><?php _e( 'Show posts with future dates only?', 'custom-post-type-date-archives' ); ?></label> | |
</p> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment