Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / my_pmpro_emails_custom_template_path.php
Last active April 3, 2021 04:07 — forked from strangerstudios/my_pmpro_emails_custom_template_path.php
Tell PMPro to look in the pages directory of this plugin for PMPro email templates.
<?php
/*
Tell PMPro to look in the pages directory of this plugin for PMPro email templates.
Add this code to a custom plugin.
Make sure that there is a /email/ directory in the plugin directory with your templates in it.
*/
function my_pmpro_email_custom_template_path($default_templates, $page_name) {
$default_templates[] = dirname(__FILE__) . '/email/' . $page_name . '.html';
return $default_templates;
@ideadude
ideadude / my_pmproec_after_validate_user.php
Last active April 13, 2021 18:25 — forked from strangerstudios/my_pmproec_after_validate_user.php
Redirect to the membership account page instead of the home page after email validation with the PMPro Email Confirmation add on.
/**
* Redirect to the membership account page instead of the home page after email validation with the PMPro Email Confirmation add on.
* Add this code to a custom WordPress plugin. https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmproec_after_validate_user() {
if( is_user_logged_in() ) {
wp_safe_redirect( '/membership-account/' );
} else {
wp_safe_redirect( wp_login_url( '/membership-account/' ) );
}
@ideadude
ideadude / show_pmpro_address_fields_on_edit_profile.php
Last active July 21, 2021 19:08 — forked from strangerstudios/show_pmpro_address_fields_on_edit_profile.php
Use PMPro Register Helper to add PMPro Billing Address fields to the edit user page for admins.
/*
Use PMPro Register Helper to add PMPro Billing Address fields to the edit user page for admins.
*/
function show_pmpro_address_fields_on_edit_profile()
{
//require PMPro and PMPro Register Helper
if(!defined('PMPRO_VERSION') || !defined('PMPRORH_VERSION'))
return;
$address_fields = array(
@ideadude
ideadude / my_pmpro_getfile.php
Last active July 25, 2021 10:14 — forked from strangerstudios/my_pmpro_getfile.php
How to protect non-WordPress files in a subdirectory of your site using Paid Memberships Pro.
<?php
/*
This code handles loading a file from the /protected-directory/ directory.
(!) Be sure to change line 19 below to point to your protected directory if something other than /protected/
(!) Be sure to change line 66 below to the level ID or array of level IDs to check for the levels you need.
(!) Add this code to your active theme's functions.php or a custom plugin.
(!) You should have a corresponding bit of code in your Apache .htaccess file to redirect files to this script. e.g.
###
@ideadude
ideadude / my_pmpro_ipn_check_receiver_email.php
Created August 31, 2021 17:09 — forked from andrewlimaza/my_pmpro_ipn_check_receiver_email.php
Allow other receiver/business email addresses for PMPro IPN Messages.
<?php
/**
* Allow other business email addresses for PMPro IPN Messages.
* To add this code to your site you may follow this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_ipn_check_receiver_email($check, $email) {
if ( in_array( 'bbb@gmail.com', $email ) ) { //change email here to the old email
$check = true;
}
@ideadude
ideadude / a-gettext-filter-4-pmpro.php
Last active October 5, 2021 01:31 — forked from pbrocks/a-gettext-filter-4-pmpro.php
Sometimes we may want to change the wording of the language used in a plugin or theme, but don't want to edit code directly. A cleaner way to go is to use the built in filter that WordPress has called 'gettext'. This filter will search your codebase for translatable strings and replace when an exact match is found.
<?php
/**
* This filter will search your codebase for translatable strings and replace when an exact match is found.
*
* Here we're changing 'Membership' to 'Subscription' for Paid Memberships Pro.
*
* Add this code to your PMPro Customizations Plugin
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* Note: When adding to your Customizations Plugin, be careful not to include the opening php tag on line 1 above.
*
@ideadude
ideadude / my_init_membership_level_translate.php
Last active November 3, 2021 13:55 — forked from strangerstudios/my_init_membership_level_translate.php
Translate Membership Level Names and Descriptions with Paid Memberships Pro
<?php
/*
* Filter membership level names and descriptions for translating.
*
* Add this code to a custom plugin or your active theme's functions.php file.
* Be sure to update the $pmpro_translated_levels array. Add a sub array for each locale.
* The sub array keys should be the membership level ids,
* and values should be an array with the name and description to translate to.
*
*/
@ideadude
ideadude / pmpro-prorate-initial-payment.php
Last active November 17, 2021 20:05 — forked from femiyb/pmpro-prorate-initial-payment.php
Prorate the initial payment. Useful for subscriptions that occur on the first of every month.
/**
* Prorate the initial payment at PMPro checkout based on the day of the month.
* You should use the Subscription Delays add on to set your subscription
* to delay until Y1-M1-01.
*/
function my_pmpro_checkout_level( $level ) {
$current_day = date( 'j' );
// Ignore if it's the first of the month.
if ( $current_day == 1 ) {
@ideadude
ideadude / my_pmpro_checkout_level.php
Last active December 5, 2021 13:07 — forked from strangerstudios/my_pmpro_checkout_level.php
Increase price at checkout if a certain value (e.g. added via PMPro Register Helper) is set.
<?php
/**
* If a user checked option1, then add $100 to the price.
*/
function my_pmpro_checkout_level($level) {
if( ! empty( $_REQUEST['option1'] ) || ! empty( $_SESSION['option1'] ) ) {
$level->initial_payment = $level->initial_payment + 100;
//$level->billing_amount = $level->billing_amount + 100; //to update recurring payments too
}
@ideadude
ideadude / affiliate_discount_codes.php
Last active January 5, 2022 20:51 — forked from strangerstudios/pmpro_ld2aff.php
Link Paid Memberships Pro discount codes to affiliate accounts from another plugin/service.
<?php
/*
Link discount codes to affiliates.
*/
//this is the parameter we're looking for to find affiliates... based on which plugin/etc you are using
define('PMPRO_LDC2AFF_KEY', 'wpam_id'); //Affiliates Manager Plugin
//define('PMPRO_LDC2AFF_KEY', 'pa'); //WordPress Lightweight Affiliates
//define('PMPRO_LDC2AFF_KEY', 'ref'); //AffiliateWP
//helper function to get the values from options and make sure they are an array