Skip to content

Instantly share code, notes, and snippets.

View wkw's full-sized avatar

Wayne K. Walrath wkw

View GitHub Profile
@wkw
wkw / gist:141f8e39537afc5ed4a2
Created October 3, 2014 21:17
CFS Transfer Fields between Posts
/**
* Get CFS fields for a post.
* pass post_id in $_GET('id')
*
* invoke with: /wp-admin/admin-ajax.php?action=cfs_values&id=10
* include raw=1 to get the unencoded data: /wp-admin/admin-ajax.php?action=cfs_values&id=10&raw=1
*/
function ajax_get_cfs_post_values(){
$options = array('format' => 'raw');
@wkw
wkw / BackboneJS Dirty JSON Cleaner
Created November 23, 2014 18:36
While building a WordPress BackboneJS Admin app, I found that some errant plugins are improperly injecting content into the ajax response stream when they should not (e.g., styles, or snippets of javascript). Also, if WordPress error reporting it turned on, you may be getting PHP notices/warnings. All of this causes the json response to fail to …
Backbone.$.ajaxSetup({
// look for invalid json responses
dataFilter: function(data, type){
var d = null;
//-------------------------------------------
function tryParse(resp){
try {
JSON.parse(resp);
@wkw
wkw / Geocode-Address-Google-Maps-API
Last active May 26, 2020 00:54
Geolocate Address with Google Maps API. Have used this code in WordPress admin on a few projects. Not overly generalized or documented in this version.
/*
*
* Adds Geolocate button for Locations CPT custom address field
* On button click, gathers address field components and looks up the geolocation with google
* maps api.
*
* DEPENDENCIES:
* must load //maps.googleapis.com/maps/api/js?sensor=false&key=<YOUR-API-KEY>
*/
/* jshint ignore:start */
@wkw
wkw / wp-exports-posts-csv.php
Created March 23, 2015 22:43
Export selected fields of all WordPress posts as CSV file
<?php
/*
* Stick this in your functions.php, or include it from a separate file,
* edit the post types you want to export,
* then use the URL: http://your-blog.com/?_inventory=1
*
*/
function return_csv_download($array_data, $filename){
header('Content-Type: text/csv'); // you can change this based on the file type
@wkw
wkw / ask.sh
Last active August 29, 2015 14:20
# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.
ask() {
# http://djm.me/ask
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
@wkw
wkw / URLUtils.js
Last active August 29, 2015 14:24 — forked from Yaffle/URLUtils.js
/*jslint regexp: true, maxerr: 50, indent: 2 */
(function (global) {
"use strict";
function URLUtils(url, baseURL) {
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
if (!m) {
throw new RangeError();
}
@wkw
wkw / 0_reuse_code.js
Last active August 29, 2015 14:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@wkw
wkw / Events fired during order submit process
Last active May 8, 2017 02:13 — forked from adrian-green/Events fired during order submit process
Main events fired during one-page checkout in Magento
### Events during order submit process
`core_copy_fieldset_customer_account_to_quote`
`core_copy_fieldset_sales_convert_quote_to_order`
`sales_convert_quote_to_order`
`core_copy_fieldset_sales_convert_quote_address_to_order`
`sales_convert_quote_address_to_order`
`core_copy_fieldset_sales_convert_quote_address_to_order_address`
`sales_convert_quote_address_to_order_address`
@wkw
wkw / README.md
Last active April 5, 2024 08:26
WordPress functions to selectively disable WPEngine site caching temporarily.

Controlled WPEngine Cache Busting

This technique was used to control WPEngine's caching by making WPE think there was a WordPress CMS user logged in by setting a fake cookie.

This code was developed to display site-wide dynamic content when a user authenticated against an external (non-WordPress) service.

N.B.: this worked as of 10/2015, but WPE may make infratructure changes which break the technique.

Usage

@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',