cliff
11/15/2017 - 2:19 AM

The Events Calendar PRO: enable comments on single Venue pages.

The Events Calendar PRO: enable comments on single Venue pages.

<?php

/**
 * The Events Calendar PRO: enable comments on single Venue pages.
 *
 * @link https://gist.github.com/cliffordp/50a6ad0b2f23a1824b6c621a3e54b2e6
 * @link https://theeventscalendar.com/support/forums/topic/comments-on-organizer-and-venue/
 */
add_filter( 'tribe_events_register_venue_type_args', function ( $args ) {
	$args['supports'][] = 'comments';

	return $args;
} );

/**
 * Force "Allow Comments" to TRUE for all Venues.
 */
add_filter( 'comments_open', function ( $open, $post_id ) {
	if (
		function_exists( 'tribe_is_venue' )
		&& tribe_is_venue( $post_id )
	) {
		return true;
	} else {
		return $open;
	}
}, 10, 2 );

/**
 * Load the Comments Form on the Venue single page. Quite a bit of hackery to
 * accomplish this, but it should work reliably.
 */
add_action( 'tribe_events_single_venue_after_upcoming_events', function () {
	/**
	 * Needed because of the comment form's `global $id` and `global $post`
	 * thinking it's an event, not a venue. Possibly a bug in the Venue single
	 * page but maybe not.
	 */
	wp_reset_postdata();

	/**
	 * Remove TEC's hijacking of the comments template so it's no longer
	 * /wp-content/plugins/the-events-calendar/src/admin-views/no-comments.php
	 * and therefore we get to use the theme's comments.php file, as expected.
	 *
	 * comments_template() is not needed to load the comments form because it is
	 * already loading after removing TEC's hijacking of the comments template.
	 */
	remove_filter( 'comments_template', array( 'Tribe__Events__Template_Factory', 'remove_comments_template' ) );
	remove_filter( 'comments_template', array( 'Tribe__Events__Templates', 'load_ecp_comments_page_template' ) );
} );