Skip to content

Instantly share code, notes, and snippets.

View holisticnetworking's full-sized avatar
😎
Makin' teh codz.

Thomas Belknap holisticnetworking

😎
Makin' teh codz.
View GitHub Profile
@holisticnetworking
holisticnetworking / iterator.php
Created February 15, 2017 21:01
See line 19, where the problem lies.
if( $this->request->query( 'fmt' ) == 'items' ) :
$invoices = collection( $invoices )->map( function( $invoice, $key ) use ( $columns ) {
// Iterated through line items, rather than invoices:
$lis = collection( $invoice->line_items )->map( function( $line_item, $k ) use ( $invoice, $columns ) {
$line = [];
foreach( $columns as $ckey=>$meta ) :
// For line item lists:
if( preg_match( '/line_item/i', $meta ) ) :
$meta = preg_replace( '/line_item\./i', '', $meta );
$line[] = $line_item->{$meta};
Array
(
[0] => Array
(
[0] => Array
(
[0] => 290144
[1] => 01/31/17
[2] =>
[3] =>
// In AppController.php:
public function initialize() {
// Default title
$title = sprintf(
'%s: %s',
ucfirst( $this->name ),
$this->request->params['action']
);
$this->set( 'title', $title );
parent::initialize();
// CREDIT: http://stackoverflow.com/a/25497346/5418851
// Make sure all change events on autocomplete fields happen before submit:
$(document).on( 'submit', '#facet-search', function( e, changeDone ) {
changeDone = changeDone || false;
if( !changeDone ) {
e.preventDefault();
$( '.ui-autocomplete' ).trigger( 'change' );
$( e.currentTarget ).trigger( 'submit', true );
} else {
return true;
@holisticnetworking
holisticnetworking / dialog-open.js
Last active March 15, 2017 16:33
Generic function for opening a dialog with a spinner
/*
* Generic function for opening a dialog box
* @var str url: the URL for the content that will be loaded into the dialog
* @var obj data: a data object to pass to the URL
* @var obj options: the Dialog "options" object
* @var func complete: a callable function to be performed when the content loads into the dialog
*/
jQuery.fn.openDialog = function( url, data, options, complete ) {
var popup = $( "#popup" );
var content = $( "#popup-content" );
@holisticnetworking
holisticnetworking / dialog-div.php
Created March 15, 2017 16:37
The dialog box with spinner and content area.
<div id="popup">
<div id="spinner"><?= $this->Html->image('ajax-loader.gif', ['alt' => 'Please wait...']); ?></div>
<div id="popup-content">&nbsp;</div>
</div>
@holisticnetworking
holisticnetworking / wp-scholar-person-html.php
Created April 30, 2017 21:49
WP-Scholar Person CPT with escaped HTML
public static function name( $post ) {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'scholar_name_nonce' );
$prefix = get_post_meta( $post->ID, 'scholar_prefix', true );
$first = get_post_meta( $post->ID, 'scholar_first_name', true );
$middle = get_post_meta( $post->ID, 'scholar_middle_name', true );
$last = get_post_meta( $post->ID, 'scholar_last_name', true );
$gender = get_post_meta( $post->ID, 'scholar_gender', true );
$suffix = get_post_meta( $post->ID, 'scholar_suffix', true );
@holisticnetworking
holisticnetworking / wp-scholar-person-easyinputs.php
Created April 30, 2017 21:51
WP-Scholar Person CPT with EasyInputs
public static function name($post)
{
$ei = new EasyInputs([
'name' => 'Person',
'group' => 'name',
'type' => 'meta'
]);
// Use nonce for verification
wp_nonce_field(plugin_basename(__FILE__), 'scholar_name_nonce');
$prefix = get_post_meta($post->ID, 'scholar_prefix', true);
@holisticnetworking
holisticnetworking / display-column-headers.php
Created May 4, 2017 14:37
Displaying a list of column headers from an arbitrary number of columns.
/*
* Display column headers for the user-selected array of columns.
*
* @var str $query: The query array.
*/
public function displayColumnHeaders( $query ) {
$headers = '';
$sort = $query['sort'];
$direction = $query['direction'];
$arrow = sprintf('fa fa-sort-%s', $direction);
@holisticnetworking
holisticnetworking / foreach-customize-settings.php
Last active July 8, 2017 03:19
Iterating over several related theme mods to create both their settings and their controls.
// Icon Fonts:
foreach( ReactiveCustomizer::$icon_fonts as $slug=>$name ) :
$wp_customize->add_setting( 'hn_icon_fonts_' . $slug , array(
'default' => '0'
) );
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'icon_fonts_' . $slug, array(
'label' => __( $name, 'hn-reactive' ),
'section' => 'icon_fonts',
'settings' => 'hn_icon_fonts_' . $slug,
'type' => 'checkbox'