Created
June 22, 2015 22:58
-
-
Save gyrus/6647f96b20db8e0bf337 to your computer and use it in GitHub Desktop.
Hide recurring instances in admin for The Events Calendar WordPress plugin
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
// Optional - a bit of spacing | |
.filter-checkbox { | |
margin: 0 .8em; | |
} |
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
jQuery( document ).ready( function( $ ) { | |
// Adjust query string according to checkbox and reload page | |
$( '#hide_recurring_filter' ).on( 'change', function( e ) { | |
var el = $( this ); | |
var hr = ( el.is( ':checked' ) ? '1' : '0' ); | |
var qs = window.location.search; | |
if ( qs.indexOf( 'hide_recurring' ) === -1 ) { | |
qs += '&hide_recurring=' + hr; | |
} else { | |
qs = qs.replace( /(hide_recurring=)[^\&]+/, '$1' + hr ); | |
} | |
window.location.href = window.location.pathname + qs; | |
}); | |
}); |
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( 'restrict_manage_posts', 'pilau_admin_filters_restrict_manage_posts' ); | |
/** | |
* Add the checkbox into the event screen filters | |
*/ | |
function pilau_admin_filters_restrict_manage_posts() { | |
global $post_type; | |
if ( class_exists( 'TribeEvents' ) && $post_type == TribeEvents::POSTTYPE ) { | |
$hide_recurring_events = isset( $_REQUEST['hide_recurring'] ) ? (bool) $_REQUEST['hide_recurring'] : true; | |
?> | |
<label class="filter-checkbox" for="hide_recurring_filter" title="<?php _e( 'Clicking this will reload the page' ); ?>"><input type="checkbox" name="hide_recurring" id="hide_recurring_filter" value="1" <?php checked( $hide_recurring_events ); ?>> <?php _e( 'Hide recurring instances' ); ?></label> | |
<?php | |
} | |
} | |
add_action( 'pre_get_posts', 'pilau_admin_filters_pre_get_posts' ); | |
/** | |
* Do the query manipulation to hide recurring instances | |
*/ | |
function pilau_admin_filters_pre_get_posts( $query ) { | |
if ( is_admin() ) { | |
global $pagenow, $post_type; | |
if ( class_exists( 'TribeEvents' ) && $post_type == TribeEvents::POSTTYPE && $pagenow == 'edit.php' ) { | |
$hide_recurring_events = isset( $_REQUEST['hide_recurring'] ) ? (bool) $_REQUEST['hide_recurring'] : true; | |
if ( $hide_recurring_events ) { | |
$query->query_vars['post_parent'] = 0; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment