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
/**
* Quieten general chatter in Slack channels.
*
* If a channel is muted, it still pops up in the channel list whenever
* users start "chatting". These lines aim to hide those channels unless
* an @mention has taken place.
*
* Apply via dotJS or user style tool of choice!
*
* @dated 2016-11-15
@barryhughes
barryhughes / php-cli-xdebug-enable-disable.php
Created November 7, 2016 21:52
Simple helper script to automatically un/comment the XDebug directive
<?php
/**
* Comment/uncomment the PHP CLI directive that loads XDebug.
*
* Useful for turning XDebug on or off completely, so we can debug
* CLI scripts or turn off XDebug *completely* for something of a
* performance win.
*
* Sample usage:
*
@barryhughes
barryhughes / tribe-events-tickets-is-on-sale-replacement.php
Last active October 14, 2016 17:14
Event timezone aware drop-in replacement for tribe_events_tickets_is_on_sale() (ET 4.3)
<?php
/**
* Checks if the ticket is on sale (in relation to it's start/end sale dates).
*
* Drop in replacement for the function of the same name bundled in Event Tickets
* itself. It converts the ticket start/end sale dates to UTC before making its
* comparison. This version should live in a mu-plugin file, ie:
*
* wp-content/mu-plugins/tribe-events-tickets-is-on-sale-replacement.php
*
<?php
/**
* Assign venues to events.
*
* Useful after importing a bunch of events via CSV for testing;
* finds events without an assigned venue and assigns one at random.
*/
$assign_venues_to_events = function() {
global $wpdb;
@barryhughes
barryhughes / detect-empty-filtered-month-view.php
Last active October 5, 2016 22:28
Stub/example of reliably detecting if month view is empty, even if filtered via Filter Bar, early enough to perform a redirect (TEC 4.2.x/4.3)
<?php
/**
* Stub: take action if month view contains no events.
*
* Currently (in TEC 4.2/4.3) the month view template object does not
* reliably determine if there are any events available until late in the request
* (and if a Filter Bar filter is applied, it will be too late to perform a
* redirect).
*
* This function works around this to detect if month view is empty nice and
@barryhughes
barryhughes / custom-all-recurring-events-slug.php
Last active August 4, 2017 06:32
Recurring event: modifies /all/ URLs to use a custom slug in place of 'all' (written for ECP 4.2.6)
<?php
/**
* Takes care of modifying the "all" keyword used in the all-recurring-events
* view to something else.
*/
class Events_Custom_All_Link {
protected $keyword = '';
public function __construct( $keyword = 'each' ) {
$this->keyword = sanitize_key( $keyword );
<?php
/**
* Event tag support exploration. Incomplete.
*
* This snippet sets out to support /events/tag/(term)/ type URLs in The Events Calendar.
* These routes are registered by the plugin yet are not officially supported or used
* any place, though some users may try to utilize them in any case.
*
* This snippet assumes list view is the default view and tries to modify the pagination
* links to keep the visitor within the /events/tag/(term)/ part of the events archive
@barryhughes
barryhughes / tec-featured-audio-integration.php
Created July 15, 2016 02:34
Integrate The Events Calendar and Featured Audio plugins
<?php
/**
* Scans for recurring events and triggers an update to rebuild the
* child posts for each. This is delegated to a scheduled event, so
* that it happens in the "background" and doesn't slow down normal
* operations.
*/
class Rebuild_Recurrence {
const WORKER_TASK = 'tribe_63556_task';
const FIX_STATUS = 'tribe_63556_status';
-- Get the missing order post IDs
SELECT post_id as missing_order,
-- "Estimate" the date by looking at the next available post's date
(
SELECT post_date
FROM wp_posts
WHERE ID > post_id
ORDER BY ID ASC
LIMIT 1
) as nearest_date