Skip to content

Instantly share code, notes, and snippets.

View nickpelton's full-sized avatar

Nick Pelton nickpelton

  • Rocketgenius/Gravityforms
  • Minneapolis, MN
View GitHub Profile
@nickpelton
nickpelton / localwp-no-conflict.sh
Created July 20, 2022 20:43
zsh avoid conflicts with localwp shell and custom php, mysql, or other custom binaries
# Don't load custom stuff if LocalWP shell
if [[ -z ${PHPRC+z} ]]
then
echo "Export custom binaries"
# Eg.
# export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"
# export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"
fi
@nickpelton
nickpelton / install-gravity-forms-and-all-add-ons.sh
Created July 20, 2022 21:56
Install and Activate Gravity Forms and all add-ons via Gravity Forms CLI
#!/bin/zsh
# Script to force install Gravity Forms and All Add-ons via Gravity Forms CLI (https://docs.gravityforms.com/category/add-ons-gravity-forms/wp-cli-add-on/)
# Note: You must `define('GF_LICENSE_KEY','your_license_key')` with a valid Elite or higher License key
# Install Gravity Forms Core Plugin
wp gf install --force --activate
addons=(
"gravityforms2checkout"
@nickpelton
nickpelton / localize-script-002.php
Last active July 15, 2017 13:15
WP: wp_localize_script admin-ajax url
<?php
// Setup our data
$myDataArray = array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
);
// Pass data to myscript.js on page load
wp_localize_script( "myScript", "myLocalizedData", $myDataArray );
@nickpelton
nickpelton / Dockerfile
Created August 3, 2016 20:24 — forked from jbrinley/Dockerfile
PHP7 FPM dockerfile
# Use Alpine Linux
FROM alpine:latest
# Environments
ENV TIMEZONE Etc/UTC
ENV PHP_MEMORY_LIMIT 512M
ENV MAX_UPLOAD 50M
ENV PHP_MAX_FILE_UPLOAD 200
ENV PHP_MAX_POST 100M
@nickpelton
nickpelton / gist:4566877
Created January 18, 2013 18:20 — forked from jonathanmoore/gist:2640302
Share counts from popular Social Apps

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@nickpelton
nickpelton / trackjs-ignore.js
Created September 18, 2014 14:37
TrackJS ignore Chrome browser extensions
window._trackJs = {
onError: function (payload){
if(payload.file.indexOf("chrome://") !== -1){ return false; } // many extensions have a source file of chrome://some/extension/path.js
return true;
}
// other stuff
}
@nickpelton
nickpelton / ajax-endpoint.php
Created April 26, 2014 18:40
WP: AJAX Nounce
<?php
/**
* Setup JSON Ajax endpoint
*/
add_action('wp_ajax_secure_endpoint', 'secure_endpoint_callback_function');
add_action('wp_ajax_nopriv_secure_endpoint', 'secure_endpoint_callback_function');
function secure_endpoint_callback_function(){
<?php
/**
* Setup JSON Ajax endpoint for Javascript async access to WP data
*/
add_action('wp_ajax_load_posts', 'load_post_callback'); // Enable for logged-in users
add_action('wp_ajax_nopriv_load_posts', 'load_post_callback'); // Enable for anonymous users
function load_post_callback(){
@nickpelton
nickpelton / localize-script.php
Last active August 29, 2015 14:00
WP: Localize Script
<?php
// enque script
wp_enqueue_script( "myScript", get_template_directory_uri()."/js/myscript.js", array('jquery'), '1.0',true);
// Setup our data
$myDataArray = array(
'data' => array( // Add some data
'person' => array(
'name'=>'Nick',
@nickpelton
nickpelton / ajax-endpoint.php
Last active August 29, 2015 14:00
WP: AJAX in WordPress - 2
<?php
/**
* Setup JSON Ajax endpoint for Javascript async access to WP data
*/
add_action('wp_ajax_my_action_1', 'my_callback_function_1'); // Enable for logged-in users
add_action('wp_ajax_nopriv_my_action_1', 'my_callback_function_1'); // Enable for anonymous users
function my_callback_function_1(){