Skip to content

Instantly share code, notes, and snippets.

@stephenharris
stephenharris / get-todays-event.php
Created February 19, 2013 18:18
Get 'todays' event with Event Organiser. (Today means running today - might have started before today).
<?php
/**
* Returns today's event (or false if it one doesn't exist). If there is more than one it simply returns the first one.
* By 'today' I mean running today (though could have started earlier). You can change altering it slightly.
*
* @see http://wp-event-organiser.com/documentation/function/eo_get_events/
*
*/
function sh_get_todays_event(){
@stephenharris
stephenharris / possible-bug-with-remove-action.php
Last active December 14, 2015 09:18
Possible bug with `remove_action()`. An hook is trigged. If a function removes itself from that that hook, all functions added with priority 10 are not triggered * on that specific instance.
<?php
/**
* Possible Bug With remove_action()/remove_filter()
*
* Only been tested with the pre_get_posts hook
*
* A hook is trigged. If a function removes itself from that that hook, all functions
* added with priority 10 are not triggered on that specific instance.
*
@stephenharris
stephenharris / event-body-class.php
Last active December 15, 2015 05:08
A function which adds classes to event pages corresponding to the event
<?php
/**
* A function which adds classes to event pages corresponding to the event
* E.g. adds 'eo-event-cat-[cat slug]' class for each category the event belongs to.
* Adds 'eo-event-venue-[venue slug]' if the event has a venue
* Adds time based class: eo-event-future/past/running for future/past/running events
*
* @url http://wordpress.org/support/topic/problem-with-highlight-in-menu-change-url-of-events?replies=8#post-3458829
* Not tested
*/
@stephenharris
stephenharris / debugging-main-query.php
Created March 24, 2013 16:18
Very simple script for debugging queries
<?php
/**
* Will print to the page the main query used for that page. It will do this only for admins.
* This can be put in your theme's functions.php, but should be removed when its no longer needed.
*/
add_action( 'posts_request', 'debug_post_request', 10, 2 );
function debug_post_request( $r, $query ){
if( current_user_can( 'manage_options' ) && $query->is_main_query() ){
@stephenharris
stephenharris / who-killed-wordpress.php
Created April 3, 2013 18:01
Who killed WordPress? Useful for when you're get rogue 'Are you sure messages?' Not for production folks...
<?php
function who_killed_me( $handler ){
print_r( wp_debug_backtrace_summary() );
return $handler;
}
add_filter( 'wp_die_handler', 'who_killed_me' );
?>
@stephenharris
stephenharris / currencies.php
Created April 23, 2013 13:46
The eventorganiser_get_currencies() function used in Event Organiser Pro to return details of the support currencies (human-readable name, symbol, HTML symbol).
<?php
/**
* Returns an array of available currencies.
*
* Applies the filter 'eventorganiser_currencies'. Returns an array of the form
*
* currency identifier => array(
* 'name' => currency name,
* 'symbol' => currency symbol,
* 'symbol_html' => symbol in html
@stephenharris
stephenharris / color_luminance.php
Created May 7, 2013 14:19
Lighten or darken a given colour
<?php
/**
* Lightens/darkens a given colour (hex format), returning the altered colour in hex format.7
* @param str $hex Colour as hexadecimal (with or without hash);
* @percent float $percent Decimal ( 0.2 = lighten by 20%(), -0.4 = darken by 40%() )
* @return str Lightened/Darkend colour as hexadecimal (with hash);
*/
function color_luminance( $hex, $percent ) {
// validate hex string
@stephenharris
stephenharris / eo-exclude-by-cat.php
Last active December 17, 2015 08:08
Simple shortcode to list events excluded by category
<?php
/**
* Simple shortcode to list events excluded by category
* @see http://wp-event-organiser.com/forums/topic/shortcodes-in-widget-i-need-to-exclude-category/
*
* ## Usage
* [events_excluded_cats exclude_cats="1,12,18"]
*/
function innonet_events_excluded_cats_handler( $atts, $content = null ){
$taxs = array('category','tag','venue');
@stephenharris
stephenharris / exclude-event-cats.php
Created May 17, 2013 16:49
Excludes specified event categories from any event query. Untested.
<?php
/**
* Excludes specified event categories from any event query. Untested.
*/
add_action( 'pre_get_posts','harris_exclude_event_terms' );
function harris_exclude_event_terms( $query ) {
if ( $query->is_main_query() && eventorganiser_is_event_query( $query ) ) {
@stephenharris
stephenharris / event-categorgy-color.php
Created May 22, 2013 19:35
Prints colours of event categories to header on front-end
<?php
/**
* Prints colours of event categories to header on front-end
* @See http://wp-event-organiser.com/blog/tutorial/using-event-colours-in-your-theme/
* @See http://wp-event-organiser.com/blog/tutorial/adding-event-colour-to-your-menu/
*
*/
add_action( 'wp_print_styles', 'my_print_event_cat_colours' );
function my_print_event_cat_colours(){