Skip to content

Instantly share code, notes, and snippets.

View mustardBees's full-sized avatar

Phil Wylie mustardBees

View GitHub Profile
@mustardBees
mustardBees / gist:4434372
Last active December 10, 2015 12:28
Replace the WooCommerce registration function
/**
* Custom WooCommerce registration process
*/
function iweb_woocommerce_process_registration() {
// Duplicate of woocommerce_process_registration() with our modifications
}
/**
* Replace the WooCommerce registration function
*
@mustardBees
mustardBees / gist:4475788
Created January 7, 2013 15:24
Add Mixcloud oEmbed support to WordPress
/**
* Register additional oEmbed providers
*
* @author Syed Balkhi
* @link http://goo.gl/tccJh
*/
function iweb_register_additional_oembed_providers() {
wp_oembed_add_provider( 'http://www.mixcloud.com/*', 'http://www.mixcloud.com/oembed' );
}
add_action( 'init', 'iweb_register_additional_oembed_providers' );
@mustardBees
mustardBees / iweb-logout-url-shortcode.php
Created February 4, 2013 14:41
Allows you to place a logout link within the WordPress editor.
/**
* Return logout URL and redirect to homepage
*
* Allows you to place a logout link within the WordPress editor. In visual
* view set the link to [logout-url], in text view, use
* <a href="[logout-url]">logout</a>.
*
* @author Phil Wylie
* @link http://goo.gl/025f5
*/
@mustardBees
mustardBees / iweb_get_dynamic_sidebar.php
Last active December 16, 2015 12:19
WordPress, get a sidebar as displayed on another page
<?php
/**
* Get sidebar as displayed on another page
*
* A dirty way to grab a sidebar as it's displayed on another page. Useful for
* when widgets output a menu and you need to display the same menu on a post
* type archive/single page.
*
* @author Phil Wylie
* @link http://goo.gl/qYf8H
@mustardBees
mustardBees / functions.php
Created May 10, 2013 08:56
Add additional image sizes to the WordPress media upload/insert interface
<?php
/**
* Add additional image sizes to the WordPress media upload/insert interface
*
* @author Daniel Roizer
* @link http://goo.gl/0tKD0
*/
function iweb_additional_image_sizes( $sizes ) {
$additional_image_sizes = array(
'banner' => 'Banner'
@mustardBees
mustardBees / functions.php
Last active December 17, 2015 14:39
Get an excerpt from a specific post ID or post object with a variable excerpt length
<?php
/**
* Get the excerpt of a specific post ID or object
*
* @author Pippin Williamson
* @link http://goo.gl/lhtZD
* @param object/int $post The ID or object of the post to get the excerpt of
* @param int $length The length of the excerpt in words
* @param string $tags The allowed HTML tags. These will not be stripped out
* @param string $extra Text to append to the end of the excerpt
@mustardBees
mustardBees / metaboxes.php
Last active December 17, 2015 18:09
Example code to populate a CMB select field with posts from a custom post type.
<?php
/**
* Get a list of downloads
*
* Return an array of downloads suitable for CMB's select field.
*
* Example CMB select field usage:
*
* array(
* 'name' => 'Download',
@mustardBees
mustardBees / front-page.php
Created June 3, 2013 15:51
WordPress template snippet to display an image from a CMB file field. Make sure you've registered your CMB field with 'save_id' => true. When the field is saved, the attachment ID will be saved in a custom field and can be accessed by appending _id to your chosen custom field id.
<?php $attachment_id = get_post_meta( get_the_ID(), '_cmb_image_id', true ); ?>
<?php if ( ! empty( $attachment_id ) ) : ?>
<?php echo wp_get_attachment_image( $attachment_id, 'thumbnail' ); ?>
<?php endif; ?>
@mustardBees
mustardBees / functions.php
Last active December 18, 2015 08:59
Include CMB's init.php on the 'init' WordPress hook
<?php
/**
* Initialise CMB
*
* @author Phil Wylie
* @link http://goo.gl/MhJPe
*/
function pw_initialise_cmb() {
if ( ! class_exists( 'cmb_Meta_Box' ) ) {
require 'lib/init.php';
$('a#show-map').click(function(e) {
e.preventDefault();
$('#map-container').show();
google.maps.event.trigger(map, 'resize');
map.setCenter(latLng);
});