Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active May 22, 2020 21:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/82836c507db01515745db6e5172f4f76 to your computer and use it in GitHub Desktop.
Save cliffordp/82836c507db01515745db6e5172f4f76 to your computer and use it in GitHub Desktop.
The Events Calendar (V2 Views): Remove the "This event has passed." notice from single events.
<?php
/**
* The Events Calendar (V2 Views): Remove the "This event has passed." notice from single events.
*
* FYI: There are other places this same notice displays, such as embed view. To remove the notice from everywhere,
* remove the code snippet's "if..." logic.
*
* @link https://gist.github.com/cliffordp/82836c507db01515745db6e5172f4f76 This snippet.
* @link https://share.getcloudapp.com/YEud5m7d Screenshot of the notice that gets removed.
*/
function tec_remove_is_a_past_event_notice_on_event_single() {
/** @var \Tribe\Events\Views\V2\Template_Bootstrap $template */
$template = tribe( \Tribe\Events\Views\V2\Template_Bootstrap::class );
if ( $template->is_single_event() ) {
Tribe__Notices::remove_notice( 'event-past' );
}
}
add_action( 'tribe_pre_get_view', 'tec_remove_is_a_past_event_notice_on_event_single' );
@benklocek
Copy link

Hi Clifford,

I've been trying to figure out a way to pull in one of the V2 templates into my plugin for TEC, and this gist is the only bit that gives me hope.

Is there a way to use the Template_Bootstrap class to load the V2/list/event.php template within a WP_Query foreach loop? The templates all rely on being in an object context, since they use $this, but I can't figure out how to load them within the template context so the $this->template object is set.

Thanks!

@cliffordp
Copy link
Author

cliffordp commented May 22, 2020

@benklocek, if you have Events Calendar Pro, you could just use a shortcode: https://theeventscalendar.com/knowledgebase/k/events-calendar-pro-widget-shortcodes-overview/

But since you're trying to integrate to a third-party thing, these might help accomplish whatever you're doing:

@benklocek
Copy link

Oh, so close! That first gist almost does it. It pulls in the V1 templates, instead of the V2.

I haven't figured out a way to use a widget, as I'm creating a customized version of "Featured Events" based on a query variable for an organizer. The organizers are embedding a community calendar on their site, and we are "Featuring" their next two events just for them.

@cliffordp
Copy link
Author

I hit enter too soon, then GitHub went down for a short bit... I just now updated my previous reply.

Beyond what I've shared here, you'll have to continue on your own, especially with the custom scenario you're working within.

Good luck!

@benklocek
Copy link

benklocek commented May 22, 2020

One of your colleges sent this and I'm set:

$engine = new \Tribe__Template(); $engine->set_template_origin( tribe( 'tec.main' ) ) ->set_template_folder( 'src/views/v2' ) ->set_template_folder_lookup( true ) ->set_template_context_extract( true );

Then I'm using it like this with the results of a query:

$engine->template( 'list/event', [ 'event' => tribe_get_event( $event->ID ) ] );

@cliffordp
Copy link
Author

👍

@benklocek
Copy link

Yeah! That does the trick. Thank you, Clifford!

Thanks also for pointing me to the /tribe-ext-events-happening-now plugin. There is lots there for me to work with.

I love you guys!

@cliffordp
Copy link
Author

🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment