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 / 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:
*
/**
* 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 );