<?php
/**
* The Events Calendar - Community Events: Enqueue Advanced Custom Fields into
* the Community Events add/edit form pages.
*
* This will get ACF loaded but you will need to add your own additional code to
* get ACF to do anything at all on the Community Events forms.
*
* @see cliff_is_community_page
*
* @link https://gist.github.com/cliffordp/9c88e97e5f2392b1c36eabb248a50b11
* @link https://www.advancedcustomfields.com/
* @link https://theeventscalendar.com/support/forums/topic/where-to-place-acf_form_head-to-save-submitted-data/
*/
add_action( 'wp_head', 'cliff_add_acf_to_ce' );
function cliff_add_acf_to_ce() {
if (
! function_exists( 'acf_form_head' )
|| ! function_exists( 'cliff_is_community_page' )
|| false === cliff_is_community_page()
) {
return;
}
acf_form_head();
}
/**
* Return TRUE if we are in the Community Events Add Event or Edit Event form.
*
* @return bool
*/
function cliff_is_community_page() {
$main = tribe( 'community.main' );
if ( empty( $main ) ) {
// Community Events is not active (or may somehow not be loaded correctly)
return false;
}
$event_post_type = Tribe__Events__Main::POSTTYPE;
$action = Tribe__Utils__Array::get( $main->context, 'action' );
$ce_post_type = Tribe__Utils__Array::get( $main->context, 'post_type', $event_post_type ); // assume event post type if not set
// bail if we are not doing what is expected from the start
if ( $event_post_type !== $ce_post_type ) {
return false;
}
if (
'edit' === $action
|| 'add' === $action
) {
return true;
} else {
// if empty( $action ), you might be in the Community Events List view
return false;
}
}