Skip to content

Instantly share code, notes, and snippets.

View supercleanse's full-sized avatar

Blair Williams supercleanse

View GitHub Profile
@supercleanse
supercleanse / formintercept.js
Last active December 29, 2015 06:59
Intercept submission and serialize form data into an object.
$( "form" ).on( "submit", function(e) {
e.preventDefault();
var formdata = $(this).serializeArray();
// do something cool here
});
@supercleanse
supercleanse / facebook_auth.php
Created October 20, 2013 18:43
Facebook app connection code for PHP / WordPress
<?php
define('FBAUTH_FB_OAUTH_URL', 'https://www.facebook.com/dialog/oauth');
define('FBAUTH_FB_OAUTH_TOKEN_URL', 'https://graph.facebook.com/oauth/access_token');
define('FBAUTH_FB_GRAPH_DEBUG_TOKEN_URL', 'https://graph.facebook.com/debug_token');
define('FBAUTH_FB_GRAPH_PROFILE_URL', 'https://graph.facebook.com/me');
define('FBAUTH_FB_APP_ID', 'xxxx');
define('FBAUTH_FB_APP_SECRET', 'xxxx');
function fbauth_get_fb_token($code) {
global $post;
@supercleanse
supercleanse / maze_generator.rb
Created October 14, 2013 20:55
Maze Generator
# Maze Generating Tweet? Gah
#|--| Top=even/Left=odd
#|-----------| Row %(w+1)
#1,1,1,1,1,1,1,1
#w=6;h=3;m=(w+1)*3;n=(h+1)*3;g=[];s=m*n;s.times{|i|g<<(((i%m==(m-2))or(i%3==2)or(i>(s-m)))? 0: 1)}
#c=(s-3);(w*h).times({ s[(c+2)]=1; x=[(c>m)? (c-m): nil,(c%m==(m-3))? c+3: nil,c<(s-m)? c+m : nil,(c%m>0)? c-3: nil].compact.map{|j|j if(j[2]==0)}.sample;(x>(c+3))? g[x]=0: (x>c)? g[x+1]=0: (x<(c-3))? g[c]=0: g[c+1]=0;c=x})
#(w*h*2).times(|i|((i%2)==0)? print '+'+((g[(i/2)*3]==0)? " ": "-"): print ((g[((i/2)*3)+1]==0)? " ": "|")+' ')
w=80;h=40;g=[];v=[]
(h+1).times{|y|g[y]=[];(w+1).times{|x|g[y]<<[x==w ? 0 : 1,y==h ? 0 : 1]}}
@supercleanse
supercleanse / product_access_urls.php
Created October 10, 2013 20:15
List MemberPress product access urls in a page template.
<?php
if(MeprUtils::is_user_logged_in())
{
$user = MeprUtils::get_currentuserinfo();
$products = $user->active_product_subscriptions('products');
foreach($products as $product) {
if( !empty( $product->access_url ) ) {
?>
<a href="<?php echo $product->access_url; ?>"><?php echo $product->post_title; ?></a><br/>
@supercleanse
supercleanse / mp_ar_paid_signup_notification.php
Last active December 20, 2015 00:19
Affiliate Tracking on initial subscription in MemberPress & Affiliate Royale
<?php
add_action('mepr-txn-status-complete', 'mapsn_notification');
function mapsn_notification($txn) {
global $wpdb;
$mepr_db = new MeprDb();
$usr = $txn->user();
$usr_id = $usr->ID;
@supercleanse
supercleanse / current_user_subscriptions.php
Created June 27, 2013 22:31
List the active subscriptions for the current user. The $subscriptions variable will contain an array of memberpress product ids that the user is actively subscribed to. If you want to return an array of product objects instead pass the string 'products' ... or the latest transaction for each subscription you could pass the string 'transactions'…
<?php
$user = MeprUtils::get_currentuserinfo();
$subscriptions = $user->active_product_subscriptions();
@supercleanse
supercleanse / limit_payment_cycles_lifetime.php
Last active December 18, 2015 17:19
Lifetime access after limit_cycles reached
<?php
add_action( 'mepr-limit-payment-cycles-reached', 'cool_limit_payment_cycles_lifetime' );
function cool_limit_payment_cycles_lifetime( $mepr_subscription = null ) {
if( !is_a( $mepr_subscription, 'MeprSubscription' )
return false;
$txn = $mepr_subscription->latest_txn();
$txn->expires_at = 0; // Zero for lifetime expiration
$txn->store();
@supercleanse
supercleanse / lifetime_subscription_nav_link.php
Created June 14, 2013 22:55
Modify subscription nav to default to lifetime subs.
@supercleanse
supercleanse / js_redirect.html
Created June 3, 2013 22:16
Placing this script on the page will wait {delay_seconds} after the page is loaded and then will redirect to {redirect_url} ...
<script type="text/javascript">
$(document).ready(function() {
var redirect_url = 'http://example.com/cool';
var delay_seconds = 3;
setTimeout( function() {
window.location=redirect_url;
}, (delay_seconds * 1000) );
});
</script>
@supercleanse
supercleanse / stripe_request.php
Created June 3, 2013 20:40
This is the request wrapper I used with the Stripe gateway interface in MemberPress. It does some basic error handling and automatically decodes the json returned from stripe. You'd just wrap this function in a try / catch block for error handling ... but if alls good it should return a data structure.
<?php
function send_stripe_request( $endpoint,
$args=array(),
$method='post',
$domain='https://api.stripe.com/v1/',
$blocking=true ) {
$uri = "{$domain}{$endpoint}";
$arg_array = array( 'method' => strtoupper($method),
'body' => $args,