Skip to content

Instantly share code, notes, and snippets.

View thomasgriffin's full-sized avatar
👋

Thomas Griffin thomasgriffin

👋
View GitHub Profile
jQuery.getJSON('http://freegeoip.net/json/', function(location) {
var d = new Date(),
curr_date = d.getDate(),
curr_month = d.getMonth(),
curr_year = d.getFullYear(),
fulldate = curr_date + "-" + curr_month + "-" + curr_year;
$('<input id="date" type="hidden" name="custom_date" value="' + full_date + '" />').appendTo($('#your-form-id-here'));
$('<input id="ip" type="hidden" name="custom_ip" value="' + location.ip + '" />').appendTo($('#your-form-id-here'));
$('<input id="country" type="hidden" name="custom_country" value="' + location.country_name + '" />').appendTo($('#your-form-id-here'));
});
@thomasgriffin
thomasgriffin / gist:8787961
Created February 3, 2014 17:11
Remove YouTube controls from video.
<?php
add_filter( 'tgmsp_youtube_query_args', 'tgm_soliloquy_remove_youtube_controls' );
function tgm_soliloquy_remove_youtube_controls( $query_args ) {
$query_args['controls'] = '0';
return $query_args;
}
jQuery(document).ready(function($){
$(document).on('OptinMonsterInit', function(event, data){
// If video is playing (add your own logic here), remove the optin.
if ( data.optin ) {
$('#om-' + data.optin).remove();
}
});
});
jQuery(document).ready(function($){
$(document).on('OptinMonsterOptinSuccess', function(event, data){
// An optin has been processed. You can send this information to GA for analytics.
console.log(data);
});
});
@thomasgriffin
thomasgriffin / gist:8862970
Created February 7, 2014 13:55
Allow variable "custom" pricing for upgrades using a specific input field name "envira-custom-price". Change to whatever suits your needs.
<?php
add_filter( 'edd_add_to_cart_item', 'tgm_cp_add_to_cart_item' );
add_filter( 'edd_ajax_pre_cart_item_template', 'tgm_cp_add_to_cart_item' );
function tgm_cp_add_to_cart_item( $cart_item ) {
if ( ! empty( $_POST['post_data'] ) ) {
$post_data = array();
wp_parse_str( $_POST['post_data'], $post_data );
if ( isset( $post_data['envira-custom-price'] ) ) {
$cart_item['options']['custom_price'] = edd_sanitize_amount( $post_data['envira-custom-price'] );
<?php
add_filter( 'optin_monster_cap', 'tgm_om_editor_cap' );
function tgm_om_editor_cap( $cap ) {
// Replace with the relevant capability needed for your editors.
return 'edit_others_posts';
}
<?php
add_filter( 'optinmonster_output', 'tgm_om_hide_optins' );
function tgm_om_hide_optins( $optins ) {
// Return an empty array if no user is logged in. Change this to your logic for determining where customers come from.
if ( ! is_user_logged_in() ) {
return array();
}
// Return the potentially modified optins.
@thomasgriffin
thomasgriffin / gist:9057466
Last active August 29, 2015 13:56
Autoplay Vimeo videos on both load and transition.
<?php
add_action( 'soliloquy_api_on_load', 'tgm_soliloquy_autoplay_vimeo_on_load' );
function tgm_soliloquy_autoplay_vimeo_on_load( $data ) {
ob_start();
?>
var slide_video = soliloquy_<?php echo $data['id']; ?>.find('.soliloquy-item:not(.soliloquy-clone):eq(' + currentIndex + ') .soliloquy-video-icon');
if ( slide_video.length > 0 ) {
var video_type = slide_video.data('soliloquy-video-type');
if ( 'vimeo' == video_type ) {
@thomasgriffin
thomasgriffin / gist:9058101
Created February 17, 2014 20:09
Autoplay YouTube videos on both load and transition.
<?php
add_action( 'soliloquy_api_on_load', 'tgm_soliloquy_autoplay_youtube_on_load' );
function tgm_soliloquy_autoplay_youtube_on_load( $data ) {
ob_start();
?>
var slide_video = soliloquy_<?php echo $data['id']; ?>.find('.soliloquy-item:not(.soliloquy-clone):eq(' + currentIndex + ') .soliloquy-video-icon');
if ( slide_video.length > 0 ) {
var video_type = slide_video.data('soliloquy-video-type');
if ( 'youtube' == video_type ) {
@thomasgriffin
thomasgriffin / gist:9058111
Created February 17, 2014 20:09
Autoplay Wistia videos on load and transition.
<?php
add_action( 'soliloquy_api_on_load', 'tgm_soliloquy_autoplay_wistia_on_load' );
function tgm_soliloquy_autoplay_wistia_on_load( $data ) {
ob_start();
?>
var slide_video = soliloquy_<?php echo $data['id']; ?>.find('.soliloquy-item:not(.soliloquy-clone):eq(' + currentIndex + ') .soliloquy-video-icon');
if ( slide_video.length > 0 ) {
var video_type = slide_video.data('soliloquy-video-type');
if ( 'wistia' == video_type ) {