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 / payment-association.php
Last active November 2, 2016 18:25
Ok. Working with HABTM table. Payment Transactions belong to many Invoices. But trying to assign the association between a single payment and multiple invoices using the link() function doesn't seem to be working. Here is my code:
/*
* Apply Payments to Invoices
*/
public function applyPayments() {
$this->loadModel('PaymentMethods');
$invoices = $this->Invoices
->find( 'summary' )
->where([ 'Invoices.id IN' => $this->request->data( 'invoices' ) ]);
// Add totals:
/**
* Converts single-key metadata into multiple keys.
*
* @when before_wp_load
*/
$datagram_convert = function() {
$datagrams = WP_CLI::runcommand(
'post list --post_type=datagram --format=json',
[
@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);