Skip to content

Instantly share code, notes, and snippets.

@techslides
techslides / wp-sort.php
Last active October 29, 2017 14:05
Sort WordPress Posts by Modified Date using Query Param
<?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' );
@techslides
techslides / multiple-insert-on-duplicate-update.php
Created July 12, 2016 14:36
INSERT on duplicate update PHP function for WordPress multiple or batch operation
<?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} (";
@techslides
techslides / formidable-inplace-callback.js
Last active June 14, 2016 19:46
Call a function after in-place edit loads a form
//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();
@techslides
techslides / formidable-repeatable.php
Last active June 14, 2016 19:46
Create a repeatable section entry in Formidable Form
<?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";
@techslides
techslides / flatten.php
Created May 17, 2016 17:39
Flattening Arrays with 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);
@techslides
techslides / debug-wordpress-queries.php
Created January 15, 2016 20:02
Debug WP Queries. Include this file in functions.php and then add ?debug=sql to any WP URL
<?php
if ( !defined('SAVEQUERIES') && isset($_GET['debug']) && $_GET['debug'] == 'sql' )
define('SAVEQUERIES', true);
if ( !function_exists('dump') ) :
/**
* dump()
*
@techslides
techslides / twitter-auth.md
Created September 25, 2015 18:48 — forked from brandur/twitter-auth.md
Twitter auth

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"}% 
    
@techslides
techslides / edit.php
Last active February 3, 2019 18:59
Editing GravityForms Entries on The FrontEnd
<?php
//link on a page to edit an entry: <a href="http://domain.com/edit-page/?entry=1">Edit</a>
@techslides
techslides / image-to-dataurl.js
Created May 6, 2015 14:29
App Script as Image Proxy
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;
@techslides
techslides / pinterest-pin.js
Created April 22, 2015 18:14
Pinterest Pin Image Script
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'
}
});