Skip to content

Instantly share code, notes, and snippets.

Avatar

Barry Hughes barryhughes

View GitHub Profile
@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
@barryhughes
barryhughes / custom-event-category-templates.php
Created Oct 25, 2018
An example of using a different theme template for different event categories.
View custom-event-category-templates.php
<?php
/**
* Use custom templates for event views when specific categories
* have been requested.
*/
class Event_Category_Templates {
/**
* This will be true if an event view has been requested.
*
* @var bool
@barryhughes
barryhughes / bbpress-topic-ordering.php
Last active Nov 23, 2019
bbPress 2.6.x: don't allow "bumped" topics to surface to the top.
View bbpress-topic-ordering.php
<?php
/**
* Order bbPress topic archives by post date (date created), not by last activity.
*
* This can be added either within a standalone plugin or to a theme's functions.php
* file.
*
* @param array $args
*
* @return array
You can’t perform that action at this time.