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 / gist:d73e97f08afafafee14a8f2c939781e6
Last active June 19, 2018 13:21
Improved code using transient to provide caching of API calls.
<?php
/**
* This code retrieves course data from an external API and displays it in the user's
* My Account area. A merchant has noticed that there's a delay when loading the page.
*
* 1) What changes would you suggest to reduce or remove that delay?
* 2) Is there any other code changes that you would make?
*/
public function add_my_courses_section() {
$courses = null;
@holisticnetworking
holisticnetworking / scheduler.php
Created January 16, 2018 13:46
Adding submenu to page.
public function admin_menu() {
add_submenu_page(
'publish_status',
'Scheduled Jobs',
'Scheduled Jobs',
'manage_options',
'admin.php?page=scheduled_jobs',
[ &$this, 'display_schedule' ]
);
}
@holisticnetworking
holisticnetworking / autoload.php
Created January 13, 2018 02:34
Autoloading for both WordPress classes and PSR2 files in a /vendor directory.
<?php
/**
* PSR4 autoloader using spl_autoload_register
* @package HN_Reactive
* @author Thomas J Belknap <tbelknap@holisticnetworking.net>
*/
namespace HN_Reactive;
spl_autoload_register( function ( $class ) {
@holisticnetworking
holisticnetworking / create-table.php
Created January 5, 2018 17:44
Table creation for scheduling.
private function do_table() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $this->table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
created datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
modified datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
interval TEXT NOT NULL,
@holisticnetworking
holisticnetworking / gulpfile.log
Created December 30, 2017 22:50
Output from my gulpfile.js
MacBook-Pro-3:HNReactiveBuildTools tomb$ gulp watch-child
[17:48:26] Using gulpfile /Applications/MAMP/htdocs/HNReactive/wp-content/themes/HNReactiveBuildTools/gulpfile.js
[17:48:26] Starting 'sass'...
[17:48:26] Change detected. Building HNReactiveChild CSS...
[17:48:26] Finished 'sass' after 643 ms
[17:48:26] Starting 'watch-child'...
[17:48:27] Finished 'watch-child' after 191 ms
? Target theme slug? BubbleButt
[17:48:33] BubbleButt
[17:48:58] Starting 'sass'...
@holisticnetworking
holisticnetworking / gulpfile.js
Created December 30, 2017 22:45
User input sass watching.
/**
* HN Build Tools
* Contains build tools for developing HNReactive themes. This includes SASS compilation,
* CSS/JS minification and concatenation.
* @type {*|Gulp}
*/
"use strict";
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
@holisticnetworking
holisticnetworking / error.log
Created December 29, 2017 13:29
Full dump of Foundation installation log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/9.3.0_1/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'install',
1 verbose cli '--global',
1 verbose cli 'foundation-cli' ]
2 info using npm@5.6.0
3 info using node@v9.3.0
4 verbose npm-session 6ddaa9c6bd7dec72
5 silly install loadCurrentTree
@holisticnetworking
holisticnetworking / cdc-gov-open-calais.php
Created November 15, 2017 16:25
Sending CuRL to Open Calais
if(!empty($this->post)) {
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $this->resource);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: {$this->content_type}",
"omitOutputtingOriginalText: {$this->omit_original}",
"outputFormat: {$this->output_type}",
"x-ag-access-token : {$this->api_token}",
"x-calais-contentClass: {$this->content_class}",
"x-calais-language: {$this->language}",
@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 / 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);