Skip to content

Instantly share code, notes, and snippets.

View labsecrets's full-sized avatar

LabSecrets labsecrets

View GitHub Profile
@labsecrets
labsecrets / bpdev_get_age_from_dob
Created April 13, 2012 19:20 — forked from sbrajesh/bpdev_get_age_from_dob
Get Age from BuddyPress datebox field data
/**
* This now works on both members list and individual profile pages. Note that "birthdate" is name of profile date field - change as needed
* Get Age from BuddyPress date of Birth
* <a href='http://buddypress.org/community/members/param/&#039; rel='nofollow'>@param</a> string $dob_field_name :name of the DOB field in xprofile, like Dob or Date of Birth
* <a href='http://buddypress.org/community/members/param/&#039; rel='nofollow'>@param</a> int $user_id : the user for which you want to retrieve the age
* <a href='http://buddypress.org/community/members/param/&#039; rel='nofollow'>@param</a> string $format: the way you want to print the difference, look t <http://php.net/manual/en/dateinterval.format.php&gt; for the acceptable agrs
* @return string :the formatted age in year/month
*/
function bpdev_get_age_from_dob($birthdate,$user_id=false,$format="%y Years, %m Month(s), %d days"){
@labsecrets
labsecrets / pmpro-redirect-non-members.php
Created June 27, 2012 05:42 — forked from strangerstudios/pmpro-redirect-non-members.php
Paid Memberships Pro Redirect Non-members to Login/Homepage
/*
Redirect to login or homepage if user is logged out or not a member
Add this code to your active theme's functions.php file.
*/
function my_template_redirect()
{
global $current_user;
$okay_pages = array(pmpro_getOption('billing_page_id'), pmpro_getOption('account_page_id'), pmpro_getOption('levels_page_id'), pmpro_getOption('checkout_page_id'), pmpro_getOption('confirmation_page_id'));
@labsecrets
labsecrets / gist:3064591
Created July 7, 2012 04:21 — forked from strangerstudios/gist:2185226
Delete the WordPress User When a Paid Memberships Pro Member Cancels His Account
/*
Requires PMPro v1.4+
Code to delete WP user accounts when a member cancels their PMPro account.
Users are not deleted if:
(1) They are not cancelling their membership (i.e. $level_id != 0)
(2) They are an admin.
(3) The level change was initiated from the WP Admin Dashboard
(e.g. when an admin changes a user's level via the edit user's page)
*/
function my_pmpro_after_change_membership_level($level_id, $user_id)
@labsecrets
labsecrets / gist:3065164
Created July 7, 2012 06:51 — forked from strangerstudios/gist:1894897
Adding Shipping Address to Paid Memberships Pro
<?php
/*
Plugin Name: PMPro Shipping
Plugin URI: https://gist.github.com/gists/1894897/
Description: Add shipping to the checkout page and other updates.
Version: .2.1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
Note that this plugin requires PMPro 1.3.19 or higher to function fully.
<?php
/**
* Database emtpying and file removing class.
*
* Truncates all necessary tables in the defined database and removes
* any files uploaded by the demo user.
*
* @since 1.0.0
*
* @author Thomas Griffin
@labsecrets
labsecrets / fix-bbpress-roles-in-s2member.php
Created November 21, 2012 14:23 — forked from nerrad/fix-bbpress-roles-in-s2member.php
Fix for s2member and bbPress 2.2 plus new roles
<?php
/*
Plugin Name: Fix bbPress roles for s2member
Plugin URI: http://roughsmootheng.in
Version: 1.0
Description: This plugin adds s2member roles to the user_role_map for bbPress.
Author: Darren Ethier
Author URI: http://www.roughsmootheng.in
*/
<?php
/**
* Custom Add To Cart Messages
* Add this to your theme functions.php file
**/
add_filter( 'woocommerce_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
global $woocommerce;
// Output success messages
<?php
// This will dump information about all plans the currently signed in member has access to
var_dump(memberful_wp_user_plans_subscribed_to(wp_get_current_user()->ID));
// This will print all downloads the currently signed in member has access to, including those granted by a subscription
var_dump(memberful_wp_user_downloads( wp_get_current_user()->ID ));
// You can also pass the id of a specific user to get the plans for that specific user. E.g
<!DOCTYPE html>
<html>
<head>
<title>Wistia Upload Widget via API </title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<style>
#wistia { width: 500px; height: 75px; }
</style>
</head>
<body>
/*
Only let level 1 members sign up if they use a discount code.
Place this code in your active theme's functions.php or a custom plugin.
*/
function my_pmpro_registration_checks_require_code_to_register($pmpro_continue_registration)
{
//only bother if things are okay so far
if(!$pmpro_continue_registration)
return $pmpro_continue_registration;