Skip to content

Instantly share code, notes, and snippets.

TechSlides techslides

Block or report user

Report or block techslides

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@techslides
techslides / wp-sort.php
Last active Oct 29, 2017
Sort WordPress Posts by Modified Date using Query Param
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' );
@techslides
techslides / multiple-insert-on-duplicate-update.php
Created Jul 12, 2016
INSERT on duplicate update PHP function for WordPress multiple or batch operation
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} (";
@techslides
techslides / formidable-inplace-callback.js
Last active Jun 14, 2016
Call a function after in-place edit loads a form
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();
@techslides
techslides / formidable-repeatable.php
Last active Jun 14, 2016
Create a repeatable section entry in Formidable Form
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";
@techslides
techslides / flatten.php
Created May 17, 2016
Flattening Arrays with PHP
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);
@techslides
techslides / debug-wordpress-queries.php
Created Jan 15, 2016
Debug WP Queries. Include this file in functions.php and then add ?debug=sql to any WP URL
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"}% 
    
@techslides
techslides / edit.php
Last active Feb 3, 2019
Editing GravityForms Entries on The FrontEnd
View edit.php
<?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
App Script as Image Proxy
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;
@techslides
techslides / pinterest-pin.js
Created Apr 22, 2015
Pinterest Pin Image Script
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'
}
});
You can’t perform that action at this time.