Skip to content

Instantly share code, notes, and snippets.

Steve Taylor gyrus

View GitHub Profile
@gyrus
gyrus / uk_postcode_regex.php
Created Oct 9, 2015
Regular expression to match a UK postcode
View uk_postcode_regex.php
<?php
preg_match( '/([A-Za-z]{1,2}[0-9]{1,2})[\s]*([0-9][A-Za-z]{2})/', 'WC1N 3XX', $matches );
@gyrus
gyrus / hierarchical_cpt_template.php
Created Sep 25, 2015
Re-route template for hierarchical custom post types
View hierarchical_cpt_template.php
<?php
add_filter( 'page_template', 'pilau_hierarchical_cpt_template' );
/**
* Re-route template for hierarchical custom post types
*
* Not sure why this is needed????
*
* @param string $template
* @return string
View custom_post_type_authors.php
<?php
add_action( 'cmb2_init', 'pilau_cmb2_custom_fields' );
/**
* Register custom fields
*/
function pilau_cmb2_custom_fields() {
// Loop through CPTs
foreach ( get_post_types( array( '_builtin' => false ), 'objects' ) as $cpt ) {
View cmb-select-with-optgroups.php
<?php
function cmb_opt_groups( $args, $defaults, $field_object, $field_types_object ) {
// Only do this for the field we want (vs all select fields)
if ( '_cmb_option_field' != $field_types_object->_id() ) {
return $args;
}
$option_array = array(
'Group 1' => array(
@gyrus
gyrus / admin.css
Created Jun 22, 2015
Hide recurring instances in admin for The Events Calendar WordPress plugin
View admin.css
// Optional - a bit of spacing
.filter-checkbox {
margin: 0 .8em;
}
@gyrus
gyrus / free.php
Created Jun 18, 2015
Free custom filter for Events Calendar Pro Filter Bar
View free.php
<?php
/**
* Free? filter
*
* @package Young_Hackney
* @since 0.1
*/
class TribeEventsFilter_Free extends TribeEventsFilter {
public $type = 'checkbox';
@gyrus
gyrus / .bashrc
Last active Aug 29, 2015
Linux .bashrc aliases
View .bashrc
# Edit the hosts file
alias edit-hosts='sudo gedit /etc/hosts'
# Edit this file
alias edit-bash='sudo gedit ~/.bashrc'
# Apply changes in this file to current terminal session
alias refresh-bash='source ~/.bashrc'
# Switch to local web root
@gyrus
gyrus / pilau_protocol_relative_image_urls.php
Created Apr 16, 2015
Filter images sent to editor to make the URLs protocol-relative for possible SSL
View pilau_protocol_relative_image_urls.php
<?php
add_filter( 'image_send_to_editor', 'pilau_protocol_relative_image_urls', 999999 );
/**
* Filter images sent to editor to make the URLs protocol-relative for possible SSL
*/
function pilau_protocol_relative_image_urls( $html ) {
// Replace protocols with relative schema
$html = str_replace( array( 'http://', 'https://' ), '//', $html );
@gyrus
gyrus / pilau_wp_head.php
Last active Aug 29, 2015
Wrapper for wp_head() which manages SSL
View pilau_wp_head.php
/**
* Wrapper for wp_head() which manages SSL
*
* @uses wp_head()
* @param bool $ssl
* @return void
*/
function pilau_wp_head( $ssl = false ) {
if ( ! $ssl || WP_LOCAL_DEV ) {
@gyrus
gyrus / pilau_ie10classes.js
Created Apr 8, 2015
jQuery HTML classes for IE 10+
View pilau_ie10classes.js
/*
* A hack to add classes to the HTML element (a la Paul Irish) for IE 10+
* IE 10 and over no longer support conditional classes. However, sometimes
* you still need to target IE above 9!
*/
jQuery( document ).ready( function( $ ) {
var html = $( html );
if ( /MSIE 1[01]\.\d+;/.test( navigator.userAgent ) || /Trident/.test( navigator.userAgent ) ) {
html.addClass( 'ie' );
if ( /MSIE 10\.\d+;/.test( navigator.userAgent ) ) {
You can’t perform that action at this time.