Skip to content

Instantly share code, notes, and snippets.

View wkw's full-sized avatar

Wayne K. Walrath wkw

View GitHub Profile
@wkw
wkw / cfs_map_values_updated
Created May 5, 2014 17:57
Synchronize Wordpress Custom Meta Fields for Custom Field Suite. This will not work if your field group(s) use loop or relationship fields.
// source: https://uproot.us/forums/questions/1511/importing-data
/*
* ============================== EXPERIMENTAL CUSTOM FIELDS SUITE FIELD SYNC ============================
*
* Importing posts with custom fields even when their names match those in CFS groups. still doesn't make
* them visible to CFS. The map_fields_values below is from a forum post on uproot's site:
* https://uproot.us/forums/questions/1511/importing-data
*
* I have hard-coded the group ID for staff_bios into _sync_cfs_fields(). Call this function after
* import.
@wkw
wkw / sitepress.class.php-bug-amelioration.php
Last active August 29, 2015 14:01
WPML Language Switcher Bug Workaround
//
// referencing v3.1.5 of WPML sitepress plugin
// in file: sitepress-multilingual-cms/sitepress.class.php
// at or near line: 5898 (inside method `convert_url`)
//
Add these three lines of code after the first larger if/block.
if ( is_null( $code ) ) {
$code = $default_language;
@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 / 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 / gist:2556525
Created April 30, 2012 08:22 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@wkw
wkw / jqm-config.mods.js
Created August 16, 2012 12:05
jQueryMobile and Backbone.js
// see: http://coenraets.org/blog/2012/03/using-backbone-js-with-jquery-mobile/
// for context.
// this modifies original code (above) to also watch for dialogs being hidden
$('div[data-role="page"],div[data-role="dialog"]').live('pagehide', function (event, ui) {
$(event.currentTarget).remove();
});
@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',
// HELPER: #key_value
//
// Usage: {{#key_value obj}} Key: {{key}} // Value: {{value}} {{/key_value}}
//
// Iterate over an object, setting 'key' and 'value' for each property in
// the object.
Handlebars.registerHelper("key_value", function(obj, fn) {
var buffer = "",
key;