Skip to content

Instantly share code, notes, and snippets.

View barryhughes's full-sized avatar

Barry Hughes barryhughes

  • Automattic
  • Vancouver Island, Canada
View GitHub Profile
<?php
add_filter( 'tribe_events_community_sanitize_submission', function( $submission) {
if ( empty( $_POST['tax_input'] ) ) {
return $submission;
}
$submission['tax_input'] = array();
foreach ( $_POST['tax_input'] as $taxonomy => $terms ) {
$taxonomy = filter_var( $taxonomy, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH );
<?php
// Don't load directly
defined( 'WPINC' ) or die;
$selected_terms = array();
$taxonomy_obj = get_taxonomy( $taxonomy );
$ajax_args = array(
'taxonomy' => $taxonomy,
);
@barryhughes
barryhughes / woo-get-ticket-purchaser-name.php
Last active July 5, 2017 13:48
Helper function to obtain the name of the individual who purchased a ticket (given the ticket/attendee ID)
<?php
function get_woo_ticket_purchaser_name( $ticket_id ) {
$wootickets = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
$attendee_objects = $wootickets->get_attendees_by_id(
$ticket_id,
Tribe__Tickets_Plus__Commerce__WooCommerce__Main::ATTENDEE_OBJECT
);
if ( count( $attendee_objects ) !== 1 ) {
@barryhughes
barryhughes / update_ecp_custom_field.func.php
Created June 19, 2017 13:02
Helper function: basic equivalent to update_post_meta() but targeting the ECP custom field implementation
<?php
/**
* Updates an Events Calendar PRO-style custom field.
*
* @param int $post_id
* @param string $field_label
* @param string $value
*/
function update_ecp_custom_field( $post_id, $field_label, $value ) {
$custom_fields = (array) tribe_get_option( 'custom-fields' );
This line is indented with an initial tab.
This line is not indented.
@barryhughes
barryhughes / other-url-date-range-ext.php
Created May 17, 2017 13:28
Other URL import - extend date range options (TEC 4.5.x REST API / Other URL imports)
<?php
/**
* Supports accessing and importing events upto 2yrs in the future when using
* the "Other URL" import feature.
*
* Note that the source site may have a cap on the number of events it will
* "yield". The "tribe_rest_event_max_per_page" filter hook can be used there
* to increase that, if it is a site under your own control.
*/
<?php
/**
* Alter list view queries to be accurate to the minute (vs accurate to the second)
* to give additional opportunities for persistent caching to kick in.
*/
add_action( 'tribe_events_pre_get_posts', function( $event_query ) {
// Only modify event list queries
if ( 'list' !== $event_query->get( 'eventDisplay') ) {
return;
}
@barryhughes
barryhughes / enable-multiple-venues.tec.4.4.7.php
Created April 26, 2017 14:08
Enable support for multiple venues (in TEC / CE ~4.4.x)
<?php
/**
* Enable support for multiple venues.
*/
add_filter( 'tribe_events_linked_post_type_args', function( $args ) {
$args['allow_multiple'] = true;
return $args;
}, 100 );
@barryhughes
barryhughes / temp-workaround-76297.php
Created April 4, 2017 23:21
Temp workaround: require that a new or existing venue is submitted via the CE frontend submission form
<?php
/**
* Require that a new or existing venue is specified when events are submitted via
* the frontend submission form provided by Community Events.
*
* This is a temporary workaround for bug #76297.
*/
function ce_submissions_require_venue( array $submission ) {
// Unhook self
<?php
$mini_cal_event_atts = tribe_events_get_widget_event_atts();
$post_date = tribe_events_get_widget_event_post_date();
$post_id = get_the_ID();
$organizer_ids = tribe_get_organizer_ids();
$multiple_organizers = count( $organizer_ids ) > 1;
$city_name = ! empty( $city ) ? tribe_get_region() : '';