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_getfile.php
Created September 15, 2021 15:49
Lock down non-WordPress files in *multiple private directories* with Paid Memberships Pro.
<?php
/*
This code handles loading a file from one or more protected directories.
This is a variation of the code presented here:
https://www.paidmembershipspro.com/locking-non-wordpress-files-folders-paid-memberships-pro/
(!) Be sure to change the $protected_directories arary below.
(!) Add this code to a code snippet or custom plugin.
(!) You should have a corresponding bit of code in your Apache .htaccess file
to redirect files to this script. You need one line per protected dir.
###
@ideadude
ideadude / gist:f437065fe9d3ff196266bd9839b431ce
Last active September 15, 2021 19:47
Custom pricing logic we had running on our site to support legacy prices and sales.
<?php
// This is an excerpt from *some of* the custom pricing logic we had running on our site to support legacy prices and sales.
// Our current custom pricing script is about 140 lines long.
/*
If purchasing PMPro Plus and they've had plus or core in the past,
calculate the appropriate price.
*/
if($level->id == 20 && is_user_logged_in()) {
// If the user has a current subscription, use the billing amount on file.
$user_level = pmpro_getMembershipLevelForUser();
@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( '[email protected]', $email ) ) { //change email here to the old email
$check = true;
}
@ideadude
ideadude / disable_wp_password_change_notification_email.php
Created July 23, 2021 12:35
Disable the wp_password_change_notification_email email in WordPress.
<?php
/**
* Disable the wp_password_change_notification_email email in WordPress.
* Add this code into a custom plugin or code snippet.
*/
function disable_wp_password_change_notification_email( $email ) {
// Removing the recipient email, disables the email.
$email['to'] = '';
return $email;
@ideadude
ideadude / convert_um_address_fields.php
Created July 21, 2021 18:47
Convert Ultimate Member address fields to use PMPro user meta keys.
<?php
/**
* Add this code into a Code Snippet and set the option to
* "run only once". Then click the play button from the Snippets
* page to run this script.
* These meta keys: address, city_name, state_name, country_name, postal_code, and phone_no
* will become: pmpro_baddress1, pmpro_bcity, pmpro_bstate, pmpro_bcountry, pmpro_bzipcode, and pmpro_bphone
*/
global $wpdb;
$sqlQuery = "UPDATE $wpdb->usermeta SET meta_key = 'pmpro_baddress1' WHERE meta_key = 'address'";
@ideadude
ideadude / my_email_var_membership_expiration.php
Last active February 21, 2022 15:37
PMPro: Show the next payment date instead of the expiration date for the !!membership_expiration!! email var if it's blank.
<?php
/**
* Show the next payment date instead of the expiration date
* for the !!membership_expiration!! email var if it's blank.
* Add this code into a custom plugin or Code Snippet.
* More information on how to add code snippets here: https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/
*/
function my_email_var_membership_expiration( $data, $email ) {
if ( empty( $data['membership_expiration'] ) ) {
$user = get_user_by( 'email', $data['user_email'] );
@ideadude
ideadude / my_make_country_and_state_select2.php
Created July 16, 2021 15:29
Make the country and state dropdowns select2 fields when using PMPro and the State Dropdowns Add On.
/**
* Make country and state dropdowns select2 fields.
* Requires both the pmpro-state-dropdowns and
* pmpro-register-helper plugins to be active.
*
* Add this to a custom plugin or code snippet.
* More info here: https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/
*/
function my_make_country_and_state_select2() {
if ( ! is_admin() ) {
@ideadude
ideadude / my_add_select_all_levels.php
Created July 15, 2021 18:30
Add "select all" option inside the PMPro Require Membership box
<?php
/**
* Add "select all" option inside the Require Membership box
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_add_select_all_levels() {
?>
@ideadude
ideadude / pmpro_courses_show_course_content_to_nonmembers.php
Created July 5, 2021 20:35
Hide course content from non-members when using the default module of PMPro Courses.
/**
* Hide course content from non-members.
* By default, PMPro Courses allows non-members to see the "content" of a course.
* Lessons are still hidden. By setting this filter to false, non-members will
* see the restricted view on the single course page.
*/
add_filter( 'pmpro_courses_show_course_content_to_nonmembers', '__return_false' );
@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
}