Last active
October 7, 2017 05:38
-
-
Save DanielFloeter/e0700945a74875f98759ca14afa0a258 to your computer and use it in GitHub Desktop.
Future Posts Extension widget
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 | |
/* | |
Plugin Name: Future Posts Extension | |
Plugin URI: http://tiptoppress.com/downloads/term-and-category-based-posts-widget/ | |
Description: Extension to show only Posts which are in the future with the 'The future is now' widget for the premium widget Term and Category Based Posts Widget. | |
Additional needed widgets: 'The future is now' (https://wordpress.org/plugins/the-future-is-now/) | |
Author: TipTopPress | |
Version: 0.1 | |
Author URI: http://tiptoppress.com | |
*/ | |
namespace termCategoryPostsPro\FuturePostsExtension; | |
// Don't call the file directly | |
if ( !defined( 'ABSPATH' ) ) exit; | |
/** | |
* Applied to the list of dates in the future | |
* | |
* @return array of sort orders | |
* | |
* @since 0.1 | |
*/ | |
function query_args ( $query_args, $this, $instance ) { | |
if (isset($instance['use_only_future_posts_filter']) && $instance['use_only_future_posts_filter']) { | |
$current_date = date('Y-m-d'); | |
$query_args['date_query'] = array( 'after' => $current_date ); | |
} | |
return $query_args; | |
} | |
add_filter( 'cpwp_query_args', __NAMESPACE__.'\query_args', 10, 3 ); | |
/** | |
* Adds a new Check box to the bottom of the Filter panel | |
* | |
* @return array of sort orders | |
* | |
* @since 0.1 | |
*/ | |
function cpwp_add_extensions_panel( $widget, $instance ) { | |
$instance = wp_parse_args( ( array ) $instance, array( | |
'use_only_future_posts_filter' => '' | |
) ); | |
$use_only_future_posts_filter = $instance['use_only_future_posts_filter']; | |
echo '<p>'. | |
'<label for="'.$widget->get_field_id('use_only_future_posts_filter').'">'. | |
'<input type="checkbox" class="checkbox" id="'.$widget->get_field_id('use_only_future_posts_filter').'" name="'.$widget->get_field_name('use_only_future_posts_filter').'" '; | |
echo checked( (bool) $instance["use_only_future_posts_filter"], true ).' />'; | |
echo _e( 'Show "Posts in the future" (filter extention)','categorypostspro' ). | |
'</label>'. | |
'</p>'; | |
} | |
add_filter('cpwp_bottom_filter_panel',__NAMESPACE__.'\cpwp_add_extensions_panel', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment