Instantly share code, notes, and snippets.

View wp-sort.php
<?php
//put this into functions.php and add url param to homepage: sortby=updated
function custom_query_vars_filter($vars) {
$vars[] = 'sortby';
//$vars[] .= 'another';
return $vars;
}
add_filter( 'query_vars', 'custom_query_vars_filter' );
View multiple-insert-on-duplicate-update.php
<?php
//based on Wordpress Multiple Insert https://github.com/mirzazeyrek/wordpress-multiple-insert
function wp_insert_update_rows($row_arrays = array(), $wp_table_name) {
global $wpdb;
$wp_table_name = esc_sql($wp_table_name);
$update = "";
$query = "";
$query_columns = "";
$query. = "INSERT INTO {$wp_table_name} (";
View formidable-inplace-callback.js
//change the formibdale.js file here: https://github.com/Strategy11/formidable-forms/blob/master/js/formidable.js#L3547
success:function(html){
$cont.children('.frm-loading-img').replaceWith(html);
$edit.removeClass('frm_inplace_edit').addClass('frm_cancel_edit');
$edit.html(cancel);
//ADD THIS: call some function if it is defined
if (typeof inlineEditCallback == 'function') {
inlineEditCallback();
View formidable-repeatable.php
<?php
/*
We know our form has ID 1
The name field has ID 5, the repeatable section has ID 10, and 2 fields in repeatabale section are ID 11 and ID 12
But, how do we know that form_id is 2 below?
*/
$parent_form_id = 1;
$child_name = "John";
View flatten.php
<?php
//Good Article: http://www.cowburn.info/2012/03/17/flattening-a-multidimensional-array-in-php/
//Exmaple: http://www.tehplayground.com/#9zwqvG1XM
$aa = array("first name"=>"john","last name"=>"smith","more data"=>array("age"=>"12","role"=>"manager"),"gender"=>"male");
//flatten with keys
$output = iterator_to_array(new RecursiveIteratorIterator(
new RecursiveArrayIterator($aa)), TRUE);
View debug-wordpress-queries.php
<?php
if ( !defined('SAVEQUERIES') && isset($_GET['debug']) && $_GET['debug'] == 'sql' )
define('SAVEQUERIES', true);
if ( !function_exists('dump') ) :
/**
* dump()
*
View twitter-auth.md

Easy Twitter API OAuth 2 Access

  1. Go to your applications. Create a new one, and find the values in the Consumer Key and Consumer Secret fields.

  2. Use OAuth client information to produce an OAuth 2 access token:

    curl -i --user <consumer_key>:<consumer_secret> -X POST https://api.twitter.com/oauth2/token -d "grant_type=client_credentials"
    
    {"access_token":"<oauth2_token>","token_type":"bearer"}% 
    
View edit.php
<?php
//link on a page to edit an entry: <a href="http://domain.com/edit-page/?entry=1">Edit</a>
View image-to-dataurl.js
function doGet(e) {
var url = decodeURIComponent(e.parameter.url);
try {
var response = UrlFetchApp.fetch(url);
} catch (e) {
return e.toString();
}
var type = response.getHeaders()['Content-Type'];
var b64 = Utilities.base64Encode(response.getContent());
var data = 'data:'+type+';base64,'+b64;
View pinterest-pin.js
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
pageSettings: {
loadImages: true,
loadPlugins: true,
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
}
});