Skip to content

Instantly share code, notes, and snippets.

View gthayer's full-sized avatar

Gary Thayer gthayer

View GitHub Profile
//add_action('wp_head', 'update_meta_values');
function update_meta_values() {
/*
* Takes a set of fields and resets them as part of a repeater
* To start, create a new repeater field and enter the slug in $new_repeater
* Find the fields you would like to move in wp_posts and set the post_parent to the new repeater's ID
*/
// Slug of the new repeater
add_action( 'admin_init', 'auto_distribute_cron' );
add_action( 'mtm_auto_distribute_cron', 'mtm_push_nondistributed_posts' );
if ( class_exists( 'WP_CLI' ) ) {
\WP_CLI::add_command( 'mtm_sj', 'mtm_push_nondistributed_posts' );
}
/**
* Initialize the scheduled 'mtm_auto_distribute_cron' action.
*
* @return void
@gthayer
gthayer / WooCommerce Popup Gallery - Magnific
Last active May 22, 2019 13:43
WooCommerce Popup Gallery - Magnific
/**
* Automatically distribute posts using Distributor's external connections.
* Only applies to published posts.
*
* @param [int] $post_id The post's ID.
* @return void
*/
function auto_distribute( $post_id ) {
// Do not run this on unless a post is being updated.
@gthayer
gthayer / main_analytics.js
Last active February 12, 2018 02:41
Google Analytics Plugin Wrapper
//Load GA Plugin. If unable to load, wait 50 milliseconds and attempt load again.
function providePlugin(pluginName, pluginConstructor) {
if (window.ga && document.body ) {
ga('provide', pluginName, pluginConstructor);
}
else {
window.setTimeout(function() {
providePlugin('main_analytics', gaEventsLoader);
},
50);
@gthayer
gthayer / gist:08802c53f3a2ef757eb5ee06ac1a7157
Created February 7, 2018 16:42
A/B Test Helper Functions
// Get URL Parameter
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
add_filter( 'gform_confirmation_12', 'social_share', 10, 4 );
function social_share( $confirmation, $form, $entry, $is_ajax ) {
global $post;
$page = get_permalink();
$facebook_og = get_post_meta( $post->ID, '_yoast_wpseo_opengraph-description', true );
$twitter = get_post_meta( $post->ID, '_yoast_wpseo_twitter-description', true );
$confirmation .= '<div class="social-share">';
$confirmation .= '<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=' . $page . '"><i class="fa fa-facebook" aria-hidden="true"></i></a>';
function change_acf_meta_keys() {
global $wpdb;
$values = array(
"0" => array(
'old_value' => 'foo1',
'new_value' => 'bar1',
),
"1" => array(
/*
* Mailchimp API Calls
* V. 3.0
*/
//Push users to mailchimp on GF form completion
function mailchimp_newsletter_push_form_8($entry, $form) {
$list_id = '';
$email = $entry[3];
@gthayer
gthayer / gist:db72a76d9066c2f53d990b83a44dba83
Last active May 10, 2017 19:44
Remove product thumbnail IDs from galleries.
/*
* Removes the product's thumbnail from the gallery if it's set in both. Useful after the Woo 3.0 update as the system now automatically add the image to the gallery.
* Drop this snippet in functions.php, reload the page, then delete the function.
*/
add_action( 'init', 'remove_duplicate_gallery_images' );
function remove_duplicate_gallery_images() {
// Get the products.