Move `load_ecp_into_page_template` to a custom hook

Home Forums Calendar Products Events Calendar PRO Move `load_ecp_into_page_template` to a custom hook

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1550779
    Andy Clements
    Participant

    For years, I’ve had issues with the way Tribe Events inserts its custom templates, and for years, I’ve tried to fix it, to no avail.

    Because Tribe Events hooks in to the_content to insert its templates, many filters get applied to the markup that I don’t want to be applied. For example, line breaks (<br>) get added when line breaks appear in the templates, paragraph tags wrap comments, etc. It’s essentially just as bad as using a shortcode.

    The solution I’ve been trying to implement is rather simple; I want to unhook load_ecp_into_page_template from the_content, and instead hook it in to tribe_events_templates. This sounds easy, but because of the way the classes are constructed, I’ve had a hell of a time figuring out exactly how to do this.

    I would greatly appreciate a little guidance from one of your developers on how to achieve this goal.

    The line in question is located at src/Tribe/Templates.php:293. It’s part of the function setup_ecp_template, which is part of the class Tribe__Events__Templates, which extends the class Tribe__Templates.

    If I’m going about this completely wrong, please let me know. Any guidance on how to display the templates without passing them through the_content() would be great.

    #1550785
    Andy Clements
    Participant

    To be clear, the hook tribe_events_templates is a custom one that I want to add to my theme; the name can change if it needs to, that doesn’t particularly matter.

    #1552546
    Sky
    Keymaster

    Hi Andy!

    Thanks for reaching out. I’m not sure if this is possible outside of the Tribe_Events_Templates class, and without using the_content.

    This sort of customization is a bit beyond the scope of what I can provide for you here. However, we do have a special queue for customization requests that I can add you to. There’s no guarantees of if and when someone will be able to fulfill this request, but someone will take a look at it as soon as possible.

    Thanks, and good luck!

    Sky

    #1555301
    Andy Clements
    Participant

    I think I finally figured this out with the following code:

    // determine if the current page is a tribe page
    function is_tribe_page() {
        $queried_object = get_queried_object();
    
        $post_id = isset($post) ? $post->ID : (isset($queried_object->ID) ? $queried_object->ID : 0);
        $term_id = isset($queried_object->term_id) ? $queried_object->term_id : 0;
    
        if (function_exists("tribe_is_month") && tribe_is_month() && !is_tax()) {
        	return array(
                "archive"  => true,
                "view"     => "month",
                "taxonomy" => false,
                "term_id"  => 0,
            );
        } elseif (function_exists("tribe_is_month") && tribe_is_month() && is_tax()) {
            return array(
                "archive"  => true,
                "view"     => "month",
                "taxonomy" => true,
                "term_id"  => $term_id,
            );
        } elseif (function_exists("tribe_is_past") && tribe_is_past() && !is_tax()) { // List View Page
            return array(
                "archive"  => true,
                "view"     => "list",
                "mode"     => "past",
                "taxonomy" => false,
                "term_id"  => 0,
            );
        } elseif (function_exists("tribe_is_upcoming") && tribe_is_upcoming() && !is_tax()) {
            return array(
                "archive"  => true,
                "view"     => "list",
                "mode"     => "upcoming",
                "taxonomy" => false,
                "term_id"  => 0,
            );
        } elseif (function_exists("tribe_is_past") && tribe_is_past() && is_tax()) {
            return array(
                "archive"  => true,
                "view"     => "list",
                "mode"     => "past",
                "taxonomy" => true,
                "term_id"  => $term_id,
            );
        } elseif (function_exists("tribe_is_upcoming") && tribe_is_upcoming() && is_tax()) {
            return array(
                "archive"  => true,
                "view"     => "list",
                "mode"     => "upcoming",
                "taxonomy" => true,
                "term_id"  => $term_id,
            );
        } elseif (function_exists("tribe_is_week") && tribe_is_week() && !is_tax()) {
            return array(
                "archive"  => true,
                "view"     => "week",
                "taxonomy" => false,
                "term_id"  => 0,
            );
        } elseif (function_exists("tribe_is_week") && tribe_is_week() && is_tax()) {
            return array(
                "archive"  => true,
                "view"     => "week",
                "taxonomy" => true,
                "term_id"  => $term_id,
            );
        } elseif (function_exists("tribe_is_day") && tribe_is_day() && !is_tax()) {
            return array(
                "archive"  => true,
                "view"     => "day",
                "taxonomy" => false,
                "term_id"  => 0,
            );
        } elseif (function_exists("tribe_is_day") && tribe_is_day() && is_tax()) {
            return array(
                "archive"  => true,
                "view"     => "day",
                "taxonomy" => true,
                "term_id"  => $term_id,
            );
        } elseif (function_exists("tribe_is_map") && tribe_is_map() && !is_tax()) {
            return array(
                "archive"  => true,
                "view"     => "map",
                "taxonomy" => false,
                "term_id"  => 0,
            );
        } elseif (function_exists("tribe_is_map") && tribe_is_map() && is_tax()) { // Map View Category Page
            return array(
                "archive"  => true,
                "view"     => "map",
                "taxonomy" => true,
                "term_id"  => $term_id,
            );
        } elseif (function_exists("tribe_is_photo") && tribe_is_photo() && !is_tax()) { // Photo View Page
            return array(
                "archive"  => true,
                "view"     => "photo",
                "taxonomy" => false,
                "term_id"  => 0,
            );
        } elseif (function_exists("tribe_is_photo") && tribe_is_photo() && is_tax()) { // Photo View Category Page
            return array(
                "archive"  => true,
                "view"     => "photo",
                "taxonomy" => true,
                "term_id"  => $term_id,
            );
        } elseif (function_exists("tribe_is_event") && tribe_is_event() && is_single()) { // Single Events
            return array(
                "single"    => true,
                "post_type" => "tribe_events",
                "post_id"   => $post_id,
            );
        } elseif (function_exists("tribe_is_venue") && tribe_is_venue()) { // Single Venues
            return array(
                "single"    => true,
                "post_type" => "tribe_venue",
                "post_id"   => $post_id,
            );
        } elseif (get_post_type() === "tribe_organizer" && is_single()) { // Single Organizers
            return array(
                "single"    => true,
                "post_type" => "tribe_organizer",
                "post_id"   => $post_id,
            );
        } else {
            return false;
        }
    }
    
    // remove wpautop from tribe events pages
    function tribe_remove_content_filters() {
        if (is_tribe_page()) {
            remove_filter("the_content", "wpautop", 12);
            remove_filter("acf_the_content", "wpautop", 12);
        }
    }
    add_action("loop_start", "tribe_remove_content_filters", 999);
    #1571729
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Move `load_ecp_into_page_template` to a custom hook’ is closed to new replies.