Skip to content

Instantly share code, notes, and snippets.

@elimn
Created February 14, 2017 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elimn/58f9058cd6f2c3abbd4567d960081968 to your computer and use it in GitHub Desktop.
Save elimn/58f9058cd6f2c3abbd4567d960081968 to your computer and use it in GitHub Desktop.
MT | ET | Hide tickets option in Community Events from anonymous users
<?php
/**
* Removes ticket providers except those specified in $enabled_providers
*/
function tribe_filter_ticket_providers() {
// This contains the list of provider we will allow
$enabled_providers = array(
'Tribe__Tickets__RSVP',
);
// The meat of this is a hack, that requires PHP 5.3+.
// @todo Once we get a proper filter for the ticket providers we can remove the hack.
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
_doing_it_wrong( $this->get_name(), 'Requires PHP 5.3 or newer.', 'N/A' );
return;
}
if ( ! class_exists( 'Tribe__Tickets__Tickets' ) ) {
return;
}
$current_providers = Tribe__Tickets__Tickets::modules();
$reflection = new ReflectionClass( 'Tribe__Tickets__Tickets' );
$reflect_prop = $reflection->getProperty( 'active_modules' );
$reflect_prop->setAccessible( true );
// Remove disabled providers from $current_providers.
foreach ( $current_providers as $class => $description ) {
if ( ! in_array( $class, $enabled_providers ) ) {
unset( $current_providers[ $class ] );
}
}
$reflect_prop->setValue( $current_providers );
}
if ( ! is_user_logged_in() ) {
add_action( 'init', 'tribe_filter_ticket_providers', 100 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment