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 / force-merge-button.tec.4.6.3.php
Created November 2, 2017 21:10
Force the merge duplicate venues and organizers button to appear (The Events Calendar 4.6: Events > Settings > General screen)
<?php
/**
* Force the merge duplicate venue/organizer button to appear.
*
* Written for TEC 4.6.3, may or may not work with other versions.
*
* @param mixed $value
* @param mixed $default
* @param string $key
*
@barryhughes
barryhughes / ea-event-timezone-modifier.php
Last active November 1, 2017 23:06
Modifies the timezone of imported events (useful if for example the source feed is always UTC, but we wish to convert to some other timezone upon initial import)
<?php
class Imported_Events_Timezone_Modifier {
protected $source;
protected $target_timezone;
public function __construct( $source, $target_timezone ) {
$this->source = $source;
$this->target_timezone = $target_timezone;
}
@barryhughes
barryhughes / drop-db-tables.wp.php
Created September 12, 2017 21:38
Helper script to drop a bunch of imported tables from a WP test site.
<?php
/**
* Drop a bunch of tables.
*
* Update the prefix in the foreach definition then run via WP-CLI,
* ie "wp eval-file ../path/to/this-script.php".
*/
global $wpdb;
foreach ( $wpdb->get_col( "SHOW TABLES LIKE 'customer_db_%'" ) as $table ) {
@barryhughes
barryhughes / taxonomy.php
Created July 25, 2017 19:13
Replacement with categories/tags as checkboxes and hierarchical indents
<?php
// Don't load directly
defined( 'WPINC' ) or die;
$selected_terms = array();
$taxonomy_obj = get_taxonomy( $taxonomy );
$ajax_args = array(
'taxonomy' => $taxonomy,
);
@barryhughes
barryhughes / tickets.php
Created July 24, 2017 20:30
Replacement for eddtickets/tickets.php
<?php
/**
* Override for the standard EDD tickets form. Please create this at:
*
* [your-theme]/tribe-events/eddtickets/tickets.php
*
* @var bool $must_login
*/
global $edd_options;
<?php
add_filter( 'tribe_events_community_sanitize_submission', function( $submission) {
if ( empty( $_POST['tax_input'] ) ) {
return $submission;
}
$submission['tax_input'] = array();
foreach ( $_POST['tax_input'] as $taxonomy => $terms ) {
$taxonomy = filter_var( $taxonomy, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH );
<?php
// Don't load directly
defined( 'WPINC' ) or die;
$selected_terms = array();
$taxonomy_obj = get_taxonomy( $taxonomy );
$ajax_args = array(
'taxonomy' => $taxonomy,
);
@barryhughes
barryhughes / woo-get-ticket-purchaser-name.php
Last active July 5, 2017 13:48
Helper function to obtain the name of the individual who purchased a ticket (given the ticket/attendee ID)
<?php
function get_woo_ticket_purchaser_name( $ticket_id ) {
$wootickets = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
$attendee_objects = $wootickets->get_attendees_by_id(
$ticket_id,
Tribe__Tickets_Plus__Commerce__WooCommerce__Main::ATTENDEE_OBJECT
);
if ( count( $attendee_objects ) !== 1 ) {
@barryhughes
barryhughes / update_ecp_custom_field.func.php
Created June 19, 2017 13:02
Helper function: basic equivalent to update_post_meta() but targeting the ECP custom field implementation
<?php
/**
* Updates an Events Calendar PRO-style custom field.
*
* @param int $post_id
* @param string $field_label
* @param string $value
*/
function update_ecp_custom_field( $post_id, $field_label, $value ) {
$custom_fields = (array) tribe_get_option( 'custom-fields' );