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
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() : '';
@barryhughes
barryhughes / simple-form-to-forum-post.php
Created January 14, 2017 23:58
Rudimentary example of taking form data and using it to create a (bbPress) forum topic
<?php
function post_to_bbp_shortcode() {
if ( 'success' === post_to_bbp_status() ) {
return post_to_bbp_success();
}
else {
return post_to_bbp_form();
}
}
@barryhughes
barryhughes / dynamically-update-countdown-widget__ecp.4.4.php
Created December 15, 2016 00:33
Auto update countdown widget: move it to the next available event if it's target has already started
<?php
/**
* Updates instances of the Countdown Widget so that they always
* point to an event which has not yet started.
*
* This works by intercepting events before the widget is rendered:
* if it looks like the event the widget is targeting has already
* started, the object will select the next upcoming event (if one
* is available) and set the widget to use that instead.
*
-- Quickly delete all events, organizers and venues
-- and their associated post meta data
--
-- (The Events Calendar 4.x)
DELETE wp_posts, wp_postmeta FROM wp_posts
INNER JOIN wp_postmeta ON wp_postmeta.post_id = wp_posts.ID
WHERE wp_posts.post_type IN (
'tribe_events',
'tribe_organizer',
'tribe_venue'
@barryhughes
barryhughes / plain-text-to-php-array.php
Created November 16, 2016 17:07
Transforms a plain text file into an array of paragraphs that can then be included from other scripts
<?php
/**
* Takes a plain text file and transforms it into a PHP array representation.
*
* Paragraphs are understood to be seperated by blank lines (so if the source
* text exclusively uses a different convention, such as the opening line of
* each paragraph being tabbed in, this won't work without adjustment).
*
* Example source:
*