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
@barryhughes
barryhughes / photo-view.fit-events-into-rows.php
Created April 23, 2018 15:20
Modifies the layout mode used by photo view, such that events are clearly ordered into rows. May also need supporting CSS changes.
<?php
/**
* Adds some JS to photo view that instructs Isotope to use a different
* layout mode ("fitRows"), which some may feel offers a more chronologically
* accurate view of events.
*
* Supporting CSS changes may also be needed for the best possible result.
*/
add_action( 'wp_footer', function() {
if ( ! function_exists( 'tribe_is_photo' ) || ! tribe_is_photo() ) {
@barryhughes
barryhughes / full-list-on-map-view.php
Last active April 23, 2018 14:54
Include the same range of events within map view as are shown in list view (ie, include events that are not associated with venues or that are associated with venues which lack geodata)
<?php
/**
* Display the same range of events within map view as are shown in regular list view.
*/
add_action( 'init', function() {
if ( class_exists( 'Tribe__Events__Pro__Geo_Loc' ) ) {
$ecp_geoloc = Tribe__Events__Pro__Geo_Loc::instance();
remove_action( 'tribe_events_pre_get_posts', array( $ecp_geoloc, 'setup_geoloc_in_query' ) );
}
} );
@barryhughes
barryhughes / single-event-nav.link-to-events-from-same-cat.php
Created April 20, 2018 09:37
For single event pages, this snippet changes the next/previous event query so it only looks at events assigned to the same categories as the current event (TEC 4.6.x)
@barryhughes
barryhughes / custom_event_category_capabilities.php
Created April 10, 2018 00:05
Setting custom capabilities for event category management (TEC 4.6.13)
<?php
add_filter( 'tribe_events_register_event_cat_type_args', function( $args ) {
$args['capabilities'] = [
'manage_terms' => 'manage_tribe_events_categories',
'edit_terms' => 'manage_tribe_events_categories',
'delete_terms' => 'manage_tribe_events_categories',
'assign_terms' => 'manage_tribe_events_categories',
];
return $args;
@barryhughes
barryhughes / programmatically-add-woocommerce-etp-ticket.php
Created April 4, 2018 18:39
Programmatically add a WooCommerce ticket (Event Tickets Plus 4.7.1)
<?php
Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance()->ticket_add( $event_id, [
'ticket_name' => 'Test ticket ' . uniqid(),
'ticket_provider' => 'Tribe__Tickets_Plus__Commerce__WooCommerce__Main',
'ticket_price' => '100',
'tribe_ticket' => [
'mode' => 'global',
'event_capacity' => '100',
'capacity' => ''
],
<?php
function ecp_fix_tag_order( $sql, $query ) {
// Only modify the main query, if it is a tag archive query
if ( ! $query->is_main_query() || ! $query->is_tag() ) {
return $sql;
}
$has_event_start_date = (bool) strpos( $sql, 'AS EventStartDate' );
$orders_by_post_date = (bool) strpos( $sql, 'ORDER BY post_date DESC' );
<?php
class Resolve_Tribe_Customizer_JS_Error {
static function init() {
add_action( 'wp_print_footer_scripts', array( __CLASS__, 'capture' ), 14 );
add_action( 'wp_print_footer_scripts', array( __CLASS__, 'filter' ), 16 );
}
static function capture() {
ob_start();
}
<?php
/**
* Delete attendees if the order they are associated with is changed to a status of "refunded".
*
* Designed to work with Event Tickets Plus 4.7.1. Note that re-stocking of inventory must be
* handled separately/by taking advantage of WooCommerce's own facilities for this.
*/
class Delete_Attendees_Upon_Refund {
static function init() {
add_action( 'woocommerce_order_status_refunded', array( __CLASS__, 'on_refund' ) );
@barryhughes
barryhughes / event-list-remove-events-that-have-already-started.php
Created March 21, 2018 22:33
Remove events (from the upcoming events list) that have already started | TEC 4.6.x
<?php
/**
* "Filter out" events that have already started from list view.
*
* This deviates from the default behaviour which will include events
* that started in the past but are ongoing (have not yet ended).
*/
add_filter( 'posts_where', function( $sql, $query ) {
global $wpdb;
@barryhughes
barryhughes / reorder-photo-view_reverse-by-page.php
Created March 15, 2018 15:23
Reverses the order of posts on each individual photo view page (but does not reverse the sequence as a whole ... for TEC/ECP 4.5/4.6). In other words, this doesn't necessarily mean we'll see the furthest-in-the-future event first, rather it means each page on photo view will contain the same range of events but in the reverse order.
<?php
function photo_view_reorder_posts( $posts ) {
remove_filter( 'the_posts', 'photo_view_reorder_posts' );
return array_reverse( $posts );
}
function photo_view_reorder_listen( $query ) {
if (
'photo' === $query->get( 'eventDisplay' )
|| tribe_is_ajax_view_request( 'photo' )