Skip to content

Instantly share code, notes, and snippets.

View wkw's full-sized avatar

Wayne K. Walrath wkw

View GitHub Profile
@wkw
wkw / wp-api-batch.php
Created August 30, 2016 16:03 — forked from joehoyle/wp-api-batch.php
Batch endpoint for the WP REST API
<?php
/**
* Plugin Name: WP REST API Batch Requests
* Description: Enabled a multi / batch requests endpoint for the WP RES API
* Author: Joe Hoyle
* Version: 1.0-alpha1
* Plugin URI: https://github.com/WP-API/WP-API
* License: GPL2+
*/
@wkw
wkw / wp-admin-notices.php
Created August 1, 2016 20:29
Reusable WordPress Admin Notices PHP class
<?php
/**
* source: http://wordpress.stackexchange.com/a/222027/3844
*
* USAGE:
* add_action('admin_notices', [AdminNotice::getInstance(), 'displayAdminNotice']);
* $notice = AdminNotice::getInstance();
* $notice->displayError(__('Better flee, an error occurred.', 'herp'));
*
*/
@wkw
wkw / detect-mobile.js
Created June 25, 2016 15:52
Detect mobile devices by presence of touch handlers.
// https://hacks.mozilla.org/2013/04/detecting-touch-its-the-why-not-the-how/
if (('ontouchstart' in window) ||
(navigator.maxTouchPoints > 0) ||
(navigator.msMaxTouchPoints > 0)) {
/* browser with either Touch Events of Pointer Events
running on touch-capable device */
}
@wkw
wkw / autosaver.js
Created June 14, 2016 14:36 — forked from mjangda/autosaver.js
How to hook into and pass your plugin data though WordPress Autosave
// Must be in an external file or loaded at the end of wp_footer()
jQuery(document).ajaxSend(function(e, x, a) {
var awesome = 1;
a.data += '&' + jQuery.param( {is_awesome: awesome} );
});
@wkw
wkw / fisher-yates-shuffle.js
Created May 18, 2016 15:57
Fisher-Yates Shuffle in JavaScript
// https://bost.ocks.org/mike/shuffle/
// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
function shuffle(array) {
var m = array.length, t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
@wkw
wkw / httpsExpressApp.js
Created May 15, 2016 17:04 — forked from ryanhanwu/httpsExpressApp.js
Express JS HTTP + HTTPs server (including auto redirect)
var express = require('express'),
routes = require('./routes'),
upload = require('./routes/upload'),
http = require('http'),
https = require('https'),
fs = require('fs'),
path = require('path'),
httpApp = express(),
app = express(),
certPath = "cert";
@wkw
wkw / self-signed-ssl-certificates.txt
Last active June 6, 2022 13:53 — forked from kyledrake/gist:d7457a46a03d7408da31
Creating a self-signed SSL certificate, and then verifying it on another Linux machine
# Procedure is for Ubuntu 14.04 LTS.
# Using these guides:
# http://datacenteroverlords.com/2012/03/01/creating-your-own-ssl-certificate-authority/
# https://turboflash.wordpress.com/2009/06/23/curl-adding-installing-trusting-new-self-signed-certificate/
# https://jamielinux.com/articles/2013/08/act-as-your-own-certificate-authority/
# Generate the root (GIVE IT A PASSWORD IF YOU'RE NOT AUTOMATING SIGNING!):
openssl genrsa -aes256 -out ca.key 2048
openssl req -new -x509 -days 7300 -key ca.key -sha256 -extensions v3_ca -out ca.crt
@wkw
wkw / wp_hide_menu.php
Last active March 8, 2016 19:19
Show WordPress CPT Menu only for specific user
[Removing Menus](http://wordpress.stackexchange.com/questions/28782/possible-to-hide-custom-post-type-ui-menu-from-specific-user-roles)
[get user info](https://codex.wordpress.org/Function_Reference/wp_get_current_user)
<?php
function wpse28782_remove_menu_items() {
$allow_username = 'dev_admin';
$remove_posttype_name = 'something';
if (is_user_logged_in()) {
@wkw
wkw / scopes.txt
Created February 4, 2016 17:09 — forked from iambibhas/scopes.txt
Sublime Text 2: Snippet scopes
Here is a list of scopes to use in Sublime Text 2 snippets -
ActionScript: source.actionscript.2
AppleScript: source.applescript
ASP: source.asp
Batch FIle: source.dosbatch
C#: source.cs
C++: source.c++
Clojure: source.clojure
CoffeeScript: source.coffee
@wkw
wkw / Namespace_Module_Block_Adminhtml_Edit_Tab_XXXX.php
Created November 1, 2015 20:22 — forked from SchumacherFM/Namespace_Module_Block_Adminhtml_Edit_Tab_XXXX.php
Magento backend admin: Edit form with a multiselect field with product categories
<?php
/* Set up: */
class Namespace_Module_Block_Adminhtml_News_Edit_Tab_Linking {
protected function _prepareForm(){
...
$fieldSet->addField('product_categories', 'multiselect',