Skip to content

Instantly share code, notes, and snippets.

Avatar

Barry Hughes barryhughes

View GitHub Profile
View random-fact-string.php
<?php
/**
* Get a string containing a random fact.
*
* If a random fact cannot be fetched from the external service, a default is
* supplied instead.
*
* @return string
*/
@barryhughes
barryhughes / single-event-nav.link-to-events-from-same-cat.php
Created Apr 20, 2018
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)
View single-event-nav.link-to-events-from-same-cat.php
@barryhughes
barryhughes / programmatically-add-woocommerce-etp-ticket.php
Created Apr 4, 2018
Programmatically add a WooCommerce ticket (Event Tickets Plus 4.7.1)
View programmatically-add-woocommerce-etp-ticket.php
<?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' => ''
],
View events-by-tea-flavour.php
<?php
add_action( 'init', 'register_tea_flavours', 100 );
add_action( 'parse_query', 'focus_on_events_for_tea_flavour_queries' );
function register_tea_flavours() {
register_taxonomy( 'tea_flavours', TribeEvents::POSTTYPE, array(
'label' => 'Tea Flavours'
) );
register_taxonomy_for_object_type( 'tea_flavours', TribeEvents::POSTTYPE );
}
View hide-events-tagged-with-x.php
<?php
/**
* Remove events tagged with any of the slugs listed below from
* event views.
*
* We deliberately avoid use of TEC functions and constants etc
* so that this doesn't break should that plugin temporarily be
* deactivated.
*/
add_filter( 'pre_get_posts', function( $query ) {
View ip-address-protected-map-key.tec-views-v2.php
<?php
/**
* Facilitates dictating a separate (IP-address protected) Google Maps
* API key for server-side geocoding requests.
*/
class Server_Side_Google_Maps_Key {
/**
* @var string
*/
private $key = '';
@barryhughes
barryhughes / fetch-csv-file.php
Created Jan 12, 2020
Load a CSV file and transform to an array. Simple helper for quick and dirty scripting.
View fetch-csv-file.php
<?
/**
* Given a path to a valid CSV file, returns an array containing the data
* (an array of arrays, with outer arrays representing the rows and inner
* arrays representing the columns).
*
* @param string $path_to_csv
*
* @return array
*/
View woocommerce.get_or_create_attribute.php
<?php
namespace WooCommerce_Helpers {
/**
* Looks for an existing WooCommerce attribute with the same label, or else
* creates a new attribute using the provided information.
*
* If a new attribute is successfully created, or an existing attribute is
* matched, the attribute object will be returned. Otherwise, bool false is
* returned.
*
@barryhughes
barryhughes / php-streams.http-basic-auth.php
Last active Dec 31, 2019
HTTP authentication with file_get_contents() | PHP
View php-streams.http-basic-auth.php
<?php
/**
* Make an HTTP request with basic authentication, using 'pure PHP'.
*
* @see https://www.php.net/manual/en/wrappers.http.php
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication
*/
$username = 'http_username';
$password = 'http_password';
@barryhughes
barryhughes / password-reset-link-generator.wp-cli.php
Last active Dec 20, 2019
Handy dandy WordPress password reset link generator (command line). Useful when we want to create a URL to share with a customer because they are for whatever reason having difficulties using the regular password reset facilities.
View password-reset-link-generator.wp-cli.php