Skip to content

Instantly share code, notes, and snippets.

View DavidWells's full-sized avatar
😃

David Wells DavidWells

😃
View GitHub Profile
@DavidWells
DavidWells / manual-flush-leads-mapping-transient.php
Last active August 29, 2015 13:56 — forked from anonymous/manual-flush-leads-mapping-transient.php
Manually reset lead mapping fields in WordPress Leads
/* Add to functions.php file. Refresh wordpress admin, then remove this code */
// OR run /wp-admin/?clear_lead_custom_field_cache=1 and it will flush the cache
add_action('init', 'manual_flush_inbound_form_map_transient')
if (!function_exists('manual_flush_inbound_form_map_transient')) {
// Refresh transient
function manual_flush_inbound_form_map_transient(){
delete_transient('wp-lead-fields');
}
}
@DavidWells
DavidWells / functions.php
Last active August 29, 2015 13:57 — forked from BFTrick/functions.php
Disable inbound now shortcode styles. Add this snippet to your themes functions.php file
//dequeue css from plugins
add_action('wp_print_styles', 'inbound_dequeue_css', 100);
function inbound_dequeue_css() {
wp_dequeue_style( 'inbound-shortcodes' );
}
<?php
function create_onetime_nonce( $action = -1 ) {
$time = time();
$nonce = wp_create_nonce( $time . $action );
set_transient( '_nonce_' . $time, 1, 60*60 ); // adjust the lifetime of the transient
return $nonce . '-' . $time;
}
function verify_onetime_nonce( $_nonce, $action = -1 ) {
@list( $nonce, $time ) = explode( '-', $_nonce );
@DavidWells
DavidWells / Wordpress :: Add jQuery Script with enqueue
Created December 4, 2012 01:34
Wordpress :: Add jQuery Script with enqueue
/** Add jquery script for responsive slider
This is for use with a child theme!
If not use: get_template_directory_uri() instead
*/
function fws_add_the_scripts() {
wp_enqueue_script(
'custom_script',
get_stylesheet_directory_uri() . '/js/responsiveslides.min.js',
array('jquery')
);
@DavidWells
DavidWells / wordpress-set-transient.php
Last active December 21, 2015 20:29 — forked from aprakasa/gist:4264372
Wordpress loop transient
<?php
/**
* Using transients on a single loop inside WordPress
*
* @link http://speckyboy.com/2011/12/14/website-speed-part-3-caching-wordpress/
* /
$loop = get_transient( 'loop' );
if ( false === $loop ) {
// Show the last 100 tweets from the custom post type tweets.
@DavidWells
DavidWells / env.js
Created October 29, 2017 05:20 — forked from cardoni/env.js
serverless custom domain setup
// eslint-disable-next-line import/no-extraneous-dependencies
const { argv } = require('yargs');
let { stage = 'dev' } = argv;
module.exports.getDomainName = () => new Promise((resolve, reject) => {
stage = `${stage}`.toLowerCase();
if (!stage || stage == null || stage === 'dev') {
return resolve('dev-api.yourdomain.com');
@DavidWells
DavidWells / serverless.yml
Created October 29, 2017 04:58 — forked from Pwntus/serverless.yml
SLS existing S3 lambda trigger
functions:
TriggerFunc:
handler: handlers.main
resources:
Resources:
# Bucket 'TriggeredBucket'
TriggeredBucket:
Type: AWS::S3::Bucket
@DavidWells
DavidWells / get-window-user-props.js
Created December 3, 2018 00:11 — forked from alexrqs/get-window-user-props.js
Get window properties defined by the user
(function () {
var results, currentWindow,
// create an iframe and append to body to load a clean window object
iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
// get the current list of properties on window
currentWindow = Object.getOwnPropertyNames(window);
@DavidWells
DavidWells / async-foreach.js
Created October 22, 2018 04:10 — forked from Atinux/async-foreach.js
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@DavidWells
DavidWells / refresh-token.js
Created August 23, 2020 16:41 — forked from pfulop/refresh-token.js
how to refresh amplify token
const refreshToken = async () => {
const refreshPromise = new Promise(async (resolve) => {
const user = await Auth.currentAuthenticatedUser();
const session = await Auth.currentSession();
user.refreshSession(session.refreshToken, async (res, newSession) => {
if (newSession) {
await Auth.currentUserCredentials();
}
resolve('ok');