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 / remove-featured-events.php
Created May 3, 2018 19:16
Removes featured events from event queries, unless the query is specifically for featured events
<?php
/**
* Unset the cheque payment option if any of the existing cart items happen to
* be a ticket for an event which belongs to a specific category.
*
* @param array $available_gateways
*
* @return array
*/
function maybe_unset_gateway_by_category( $available_gateways ) {
<?php
/**
* Adds some JS to enforce a limit on the length of the submitted title.
*
* Modify the limit value (`var limit = 65`) according to your needs, etc.
* Remember that this is frontend only, nothing is enforced server side.
*
* Tested with Community Events 4.5.9.
*/
add_action( 'tribe_events_community_form', function() {
@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();
}