Skip to content

Instantly share code, notes, and snippets.

View supercleanse's full-sized avatar

Blair Williams supercleanse

View GitHub Profile
@supercleanse
supercleanse / my_google_authorship.php
Last active August 29, 2015 14:02
MemberPress.com's Google Authorship Customizations
<?php
// This is the code we use on MemberPress.com to customize the Genesis Author Box
// Uses the 'genesis_author_box' to add Google Authorship
add_filter('genesis_author_box', 'my_author_box_output');
function my_author_box_output( $output, $context, $pattern, $gravatar, $title, $description ) {
global $post;
if(isset($post) and $post->post_type=='post')
@supercleanse
supercleanse / sub_create.php
Created April 25, 2014 21:24
Example of how to use the sub-create hooks
<?php
add_action("mepr-upgraded-recurring-sub", "upgraded_recurring_sub");
function upgraded_recurring_sub( $sub ) { ... }
add_action("mepr-upgraded-single-sub", "upgraded_single_sub");
function upgraded_single_sub( $txn ) { ... }
add_action("mepr-upgraded-sub", "upgraded_sub");
function upgraded_sub( $type, $sub ) { if( $type==='single' ) { /* sub is a txn */ } else { /* sub is a sub */ } }
<?php
$my_affiliate_url = 'http://example.com?aff=123';
$download_qr_code = false;
$pretty_link_id = prli_create_pretty_link( $my_affiliate_url );
if(!$pretty_link_id) {
header('HTTP/1.1 404 Not Found');
exit;
}
@supercleanse
supercleanse / roles_lookup.php
Created April 9, 2014 17:29
Updating roles via a lookup array when MemberPress Transaction completes
<?php
/*
Plugin Name: MemberPress Products to User Roles
Plugin URI: http://memberpress.com
Description: Assigns a member to a User Role depending on what Product they purchased.
Version: 1.0.0
Author: Caseproof, LLC
Author URI: http://caseproof.com
Copyright: 2004-2013, Caseproof, LLC
*/
@supercleanse
supercleanse / user_active_for_product_nav.php
Created March 31, 2014 16:51
An example of rendering a nav bar with links for only the products the current user is active on.
<ul class="nav">
<?php
$product_ids = array( 'Bronze' => 1812,
'Silver' => 8171,
'Gold' => 4191 );
foreach( $product_ids as $label => $id ) {
if(current_user_can("memberpress_product_authorized_{$id}")) {
$product = new MeprProduct($id);
@supercleanse
supercleanse / current_user_active_subscriptions.php
Created March 31, 2014 16:37
Get active product subscriptions for the current user
<?php
$user = MeprUtils::get_currentuserinfo();
// Alternatively you can just create a user from a user id directly
// $user = new MeprUser($user_id);
if( $user ) {
$active_product_ids = $user->active_product_subscriptions();
@supercleanse
supercleanse / mp_active.php
Last active January 4, 2016 20:49
Determine if a user is active or not for a specific product
<?php
/** Returns true if a specified user is active for a specified product ... false if the user isn't active */
function is_user_active_for_product( $user_id, $product_id ) {
global $wpdb;
$mepr_db = new MeprDb();
$sql = "SELECT COUNT(*) " .
"FROM {$mepr_db->transactions} " .
"WHERE user_id=%d " .
@supercleanse
supercleanse / mp_custom_account_nav.php
Created January 28, 2014 03:30
Add custom tabs to the MemberPress Account Page
<?php
add_action('mepr_account_nav', 'custom_account_nav', 10, 1);
function custom_account_nav($user) {
$mepr_options = MeprOptions::fetch();
$whaa_url = $mepr_options->account_page_url('action=whaa');
?>
<span class="mepr-nav-item custom-whaa">
<a href="<?php echo $whaa_url; ?>" id="mepr-account-whaa"><?php _e('Whaa', 'memberpress'); ?></a>
</span>
@supercleanse
supercleanse / auto_enroll.php
Last active October 11, 2022 04:14
Automatically create a lifetime transaction for a specific product each time a user registers.
<?php
if(is_plugin_active('memberpress/memberpress.php')) {
add_action( 'user_register', 'mp_auto_enroll' );
//add_action( 'gform_user_registered', 'mp_auto_enroll', 10, 4 );
function mp_auto_enroll($user_id, $user_config=array(), $entry='', $user_pass='') {
$txn = new MeprTransaction();
$txn->user_id = $user_id;
@supercleanse
supercleanse / wordpress_repo_release_recipe.txt
Created December 8, 2013 00:25
This isn't an actual script ... more like a recipe even though it could be converted into a script
# git commands executed within git working dir
git commit -am "Bump to 1.5.0"
git push origin master
git tag 1.5.0
git push origin tag 1.5.0
cd /path/to/svn/working/dir