Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
strangerstudios / gist:1981053
Created March 5, 2012 21:00
Membership Renewals/Extensions in Paid Memberships Pro
<?php
/*
Renewal/Extension Code for PMPro
If the user checking out currently has the same level he is checking out for, the initial payment is zeroed out and the subscription is setup to start on the date of the user's next payment.
Note this only works for monthly and annual subscriptions now. The my_getNextPaymentDate function would have to be updated to correctly calculate for subscriptions with periods > 1 (e.g. every 3 months), or daily or weekly subscriptions.
*/
//if checking out for the same level, waive the initial payment
function my_pmpro_checkout_level($level)
{
@strangerstudios
strangerstudios / gist:2035922
Created March 14, 2012 11:37
Using WordPress HTTPS with Paid Memberships Pro
<?php
/*
Some WordPress HTTPS Fixes
In general, if you are using Paid Memberships Pro, you do not want to use the WordPress HTTPS plugin. PMPro will also secure your links.
If you are still receiving SSL errors on your checkout page, try setting the "nuclear" option on the Payment Gateway and SSL settings page of PMPro (v 1.3.19+)
If you want to continue using WordPress HTTPS for some reason, add this code to your theme's functions.php or somewhere else to force Paid Memberships Pro
to follow WordPress HTTPS' rules for redirecting, etc.
*/
//if WordPress HTTPS is activated allow their force_ssl custom field to replace the besecure one
function pmpro_WordPressHTTPSForceSSL($besecure)
@strangerstudios
strangerstudios / gist:2185226
Last active April 16, 2021 01:15
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)
@strangerstudios
strangerstudios / gist:2216490
Created March 27, 2012 14:38
Using the jigoshop_sale_price filter to give Paid Memberships Pro members a site-wide discount.
function my_jigoshop_sale_price($price, $product)
{
if(pmpro_hasMembershipLevel())
{
//no sale price yet?
if(empty($price))
$price = $product->get_price();
$price = intval(($price * 0.90)*100)/100;
}
@strangerstudios
strangerstudios / gist:2232405
Created March 29, 2012 01:56
Pay Per Post for WordPress with Paid Memberships Pro
<?php
/*
Limiting posts per user.
Enable the Paid Memberships Pro plugin and then add this code to your functions.php or as a stand alone plugin.
Be sure to read through this code carefully. Update each function to suit your needs.
This code has not been tested. Feel free to post issues in the comments.
*/
//increment post limit when checking out
function my_pmpro_after_checkout($user_id)
{
@strangerstudios
strangerstudios / gist:2323424
Created April 6, 2012 22:07
Hide the Level Description from the Checkout Page with Paid Memberships Pro
<?php
/*
In Paid Memberships Pro v1.4+ the memberhsip level description is shown on the checkout page. This code will remove the description on the checkout page.
*/
function my_pmpro_remove_description_from_checkout_page($level)
{
$level->description = "";
return $level;
}
add_filter("pmpro_checkout_level", "my_pmpro_remove_description_from_checkout_page");
@strangerstudios
strangerstudios / my_pmpro_confirmation_redirect.php
Last active July 6, 2021 20:16
Redirect Paid Memberships Pro Confirmation to Another Page Based on Level
/*
This code will redirect users from the default PMPro confirmation page to a specific page depending on their level.
Set the confirmation_pages array. Array keys should be membership level ids and the values are the page ids. So array(1=>2) will redirect membership level with id = 1 to the page with id = 2.
*/
function my_pmpro_confirmation_redirect()
{
$confirmation_pages = array(1 => 2); //change this use your membership level ids and page ids
global $pmpro_pages;
@strangerstudios
strangerstudios / gist:2930051
Last active April 16, 2021 23:36
Use Paid Memberships Pro Filter to Force HTTPS on All Pages
/*
Add this into a custom plugin or your active theme's functions.php
*/
add_filter("pmpro_besecure", "__return_true");
@strangerstudios
strangerstudios / gist:3077376
Created July 9, 2012 16:11
Get a Domain from a URL in PHP
/**
* Get the "domain" from a URL. By domain, we mean the host name, minus any subdomains. So just the domain and TLD.
*
* @param string $url The URL to parse. (generally pass site_url() in WP)
* @return string The domain.
*/
function getDomainFromURL($url = NULL)
{
$domainparts = parse_url($url);
$domainparts = explode(".", $domainparts['host']);
@strangerstudios
strangerstudios / gist:3100614
Created July 12, 2012 20:08
Per-level Teaser Text for Paid Memberships Pro
<?php
/*
Plugin Name: PMPro Per-level Teasers
Plugin URI: http://www.paidmembershipspro.com/pmpro-per-level-teasers/
Description: Change the text shown when member content is filtered based on the membership level required to view that content.
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/