Skip to content

Instantly share code, notes, and snippets.

@mgratch
Created March 11, 2019 22:24
Show Gist options
  • Save mgratch/4ccbb1e73d615d553b92560475fe68aa to your computer and use it in GitHub Desktop.
Save mgratch/4ccbb1e73d615d553b92560475fe68aa to your computer and use it in GitHub Desktop.
Use Elementor Pro & Elementor Hello Theme Customization on Attendee Registration Page with Modern Tribe Event Tickets.
<?php
/**
* Load Elementor template if available.
*
* @param $template
*
* @return string
*/
function redirect_virtual_templates_to_index( $template ) {
global $wp_query;
// If returning the index.php page run it through elementors location manager,
// to try and load a template.
if ( 'index.php' === substr( $template, - 9 ) ) {
// Make sure Elementor is loaded.
if ( class_exists( '\ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager' ) ) {
$instance = new \ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager();
// Un-do page spoof settings.
$wp_query->is_page = true;
$wp_query->is_singular = true;
$wp_query->is_archive = false;
// Return the location of the Elementor template that is in use (if there is one.)
$template = $instance->template_include( basename( $template ) );
// Get the Current instance of the Attendee Registration Template.
$instance = tribe( 'tickets.attendee_registration.template' );
// Override the current pages content with the attendee registration content. (Perhaps this could be appended?)
$instance->set_page_content( $wp_query );
}
}
return $template;
}
add_filter( 'tribe_tickets_attendee_registration_page_template', 'redirect_virtual_templates_to_index', 20 );
/**
* Use Elementor Page Settings.
*
* @param $posts
*
* @return array|null
*/
function use_attendee_registration_page_without_file( $posts ) {
global $wp, $wp_query;
// Only first one time for the attendee-registration page and only once.
if ( ! $wp_query->is_main_query() || '1' !== $wp_query->get( 'attendee-registration' ) || '1' === $wp_query->get( 'elementor-attendee-registration' ) ) {
return $posts;
}
// Mark that we've been here before.
$wp->add_query_var( 'elementor-attendee-registration' );
$wp_query->set( 'elementor-attendee-registration', '1' );
$post = get_page_by_path($wp->request);
if ( ! empty( $post->ID ) && 0 !== $post->ID ) {
// Empty posts
$posts = null;
// Unspoof Attendee Registration Page. (Slightly.)
$posts[] = $post = get_page_by_path($wp->request);
// This is a single page treat it as such.
$wp_query->is_page = true;
$wp_query->is_singular = true;
$wp_query->is_archive = false;
$wp_query->current_post = $post->ID;
}
return $posts;
}
add_filter( 'the_posts', 'use_attendee_registration_page_without_file' , 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment