Skip to content

Instantly share code, notes, and snippets.

View mrbobbybryant's full-sized avatar

Bobby Bryant mrbobbybryant

View GitHub Profile
<?php
<label class="layout-label">
<input type="radio"
name="package_template_layout"
class="layout-input"
value="three-column-layout"
<?php checked( $layout, "three-column-layout" ); ?>/>
<img class="layout-image" src="<?php echo get_template_directory_uri() . '/images/package-layouts/InvestorPlace_Layout_1.png'; ?>" width="1182" height="1294" >
</label>
@mrbobbybryant
mrbobbybryant / filter.php
Created January 11, 2016 15:28
array_filter wrapper
<?php
$users = array( 'John', "Bobby", 'Alex' );
function filter( $fn ) {
return function( $arr ) use ( $fn ) {
return array_filter( $arr, $fn );
};
}
function get( $value ) {
@mrbobbybryant
mrbobbybryant / typechecks.js
Last active January 6, 2016 20:00
Javascript type checking
var typeOf = function( type ) {
return function( value ) {
if ( typeof value !== type ) {
throw new TypeError( 'Expected a ' + type + '!' );
} else {
return value;
}
};
};
@mrbobbybryant
mrbobbybryant / functional.php
Last active January 3, 2016 06:21
Just some functional programming ideas
<?php
//Closure Example
$add = function($x) {
return function($y) use ($x) {
return $x + $y;
};
};
$addTen = $add(10);
@mrbobbybryant
mrbobbybryant / events.js
Last active December 17, 2015 20:28
pub/sub pattern
var events = {
events: {},
subscribe: function (eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},
unsubscribe: function(eventName, fn) {
if (this.events[eventName]) {
this.events[ eventName ] = this.events[ eventName ].filter( function( eventFn ) {
return eventFn !== fn;
@mrbobbybryant
mrbobbybryant / once.js
Created December 14, 2015 14:38
Ensures a function is only called once.
//Once
function once(fn) {
var done = false;
return function() {
return done ? void 0 : ((done = true), fn.apply(this, arguments));
};
}
var askedOnBlindDate = once(function () {
@mrbobbybryant
mrbobbybryant / maybe.js
Created December 14, 2015 01:35
This function allows you to only call a function if it has everything it needs to run. So it "May" run.
function maybe(fn) {
return function() {
var i;
if ( arguments.length === 0 ) {
return;
} else {
for(i = 0; i < arguments.length; i++) {
if (arguments[i] == null) return;
}
return fn.apply(this, arguments);
@mrbobbybryant
mrbobbybryant / set_taxonomy_term_term_order.php
Last active November 18, 2015 19:18
Allows you to update the taxonomy term order within the term_relationship table in WordPress
<?php
/**
* Update an objects term order in the term relationships table
* @param int $term_order
* @param int $object_id post_od
* @param int $tt_id term_taxonomy_id
*
* @return int
*/
function set_taxonomy_term_term_order( $term_order, $object_id, $tt_id ) {
arrayDiff: function( current, selected ) {
return selected.filter( function(data) {
return current.indexOf(data) === -1;
} );
},
extractArrayValue: function( array, value ) {
return array.map( function(data) {
return data[value];
@mrbobbybryant
mrbobbybryant / wp_editor.php
Created November 13, 2015 02:19
example of wp_editor
<?php
$content = get_post_meta( $post->ID, 'principle_duties', true );
if ( ! isset( $content ) ) {
$content = 'What I want it to say';
}
$editor = 'principle_duties';
$settings = array(
'textarea_rows' => 8,