Skip to content

Instantly share code, notes, and snippets.

View mboynes's full-sized avatar

Matthew Boynes mboynes

View GitHub Profile
@mboynes
mboynes / html_attributes.js
Last active August 29, 2015 13:57
Get html attributes from a given html tag
function get_html_attributes(s) {
var reg = /\s+([^\t\n\r\f \/>"'=]+)(?:\s*=\s*(['"])(.*?)\2)?/,attr = {};
while ((result = reg.exec(s)) !== null) {
attr[result[1]] = result[3];
s = s.replace(reg,'');
}
return attr;
}
@mboynes
mboynes / functions.php
Created February 28, 2014 04:00
WPSE 135707
<?php
function add_video_post_type() {
$labels = array(
'name' => _x( 'Videos', 'Post Type General Name', 'kibble' ),
'singular_name' => _x( 'Video', 'Post Type Singular Name', 'kibble' ),
'menu_name' => __( 'Videos', 'kibble' ),
'parent_item_colon' => __( 'Parent Item:', 'kibble' ),
'all_items' => __( 'All Items', 'kibble' ),
@mboynes
mboynes / ks_timesheet.js
Created February 20, 2014 14:52
Global keyboard shortcut for the Bonus Time Redmine plugin
viewRmTimesheet = function() {
var timesheet_link = $('.bonus-time');
if (timesheet_link.length > 0) {
ks_dispatcher.go(timesheet_link.attr('href'));
}
}
if ( ks_dispatcher && ks_dispatcher.ks_managers && ks_dispatcher.ks_managers.length && ks_dispatcher.ks_managers[0] && ks_dispatcher.ks_managers[0].keys ) {
ks_dispatcher.ks_managers[0].keys.t = {
press: viewRmTimesheet.bind(this),
<?php
# Prerequisite post type and meta fields for Recipe 3: Creating Post "Sections"
function recipe_3_prereq() {
register_post_type( 'wordcamp', array(
'public' => true,
'label' => 'WordCamps'
) );
# See http://fieldmanager.org
if ( class_exists( 'Fieldmanager_Field' ) ) {
@mboynes
mboynes / get-terms-by-overlap.php
Created June 7, 2013 21:38
Get terms from one taxonomy that relate to terms from another taxonomy through published posts.
<?php
/**
* Get terms from one taxonomy that relate to terms from another taxonomy through published posts.
* For instance, get all tags that are set on posts in the category "WordPress".
*
* @param array $args An array of options. Must contain at least 'term_ids' OR 'term_names'. Options are:
* string 'get_taxonomy' => the taxonomy whose terms you want to retrieve. Default is post_tag
* string 'through_taxonomy' => the taxonomy whose term(s) you're providing. Default is category
* array 'term_ids' => an array of term IDs through which to find overlapping terms
<!DOCTYPE html>
<!--[if IE 6]>
<html id="ie6" lang="en-US">
<![endif]-->
<!--[if IE 7]>
<html id="ie7" lang="en-US">
<![endif]-->
<!--[if IE 8]>
<html id="ie8" lang="en-US">
@mboynes
mboynes / wp_cycle.php
Last active February 1, 2016 17:29
wp_cycle
<?php
/**
* Cycle/alternate unlimited values of a given array.
*
* For instance, if you call this function five times with
* `wp_cycle( 'three', 'two', 'one' )`, you will in return get: three two one
* three two. This is useful for loops and allows you to do things like cycle
* HTML classes.
*
@mboynes
mboynes / .bash_git_color
Created February 6, 2013 15:03
Git Bash Tricks
c_purp=`tput setaf 4`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
@mboynes
mboynes / wp-tinymce-styles.php
Created January 11, 2013 22:12
WP & TinyMCE Styles Dropdown
<?php
/**
* Customize TinyMCE -- Add styles dropdown and add some custom styles. Selecting the style will add a class to the element.
*
**/
function my_tinymce_styles( $init ) {
$init['theme_advanced_buttons2_add_before'] = 'styleselect';
$init['theme_advanced_styles'] = 'Top Right Inset=insettop,Left Inset=insetleft,Right Inset=insetright';
return $init;
@mboynes
mboynes / class-pointers.php
Created September 5, 2012 14:10
Multisite tracking popup fix
<?php
/**
* @package Admin
*/
/**
* This class handles the pointers used in the introduction tour.
*
* @todo Add an introdutory pointer on the edit post page too.
*/