Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@kimcoleman
kimcoleman / my_pmpro_reports_extras.php
Last active April 16, 2021 01:23 — forked from strangerstudios/my_pmpro_reports_extras
Add a Custom Report to the Memberships > Reports Screen in Paid Memberships Pro.
<?php
/**
* Add a Custom Report to the Memberships > Reports Screen in Paid Memberships Pro.
*
* For each report, add a line like:
* global $pmpro_reports;
* $pmpro_reports['slug'] = 'Title';
*
* For each report, also write two functions:
* pmpro_report_{slug}_widget() to show up on the report homepage.
@kimcoleman
kimcoleman / hidden_level_content_pmpro_text_filter.php
Created June 6, 2019 21:50
Show a unique message on content restricted for a hidden membership level.
<?php
/**
* Show a unique message on content restricted for a hidden membership level.
*
*/
function hidden_level_content_pmpro_text_filter( $text ) {
global $post;
$access = pmpro_has_membership_access( $post->ID, NULL, true );
$level_ids = $access[1];
@kimcoleman
kimcoleman / show_disallowed_level_names_content_filter.php
Created June 6, 2019 21:51
Reveal the level name for a disallowed level in the PMPro content message on restricted content.
<?php
/**
* Reveal the level name for a disallowed level in the PMPro content message on restricted content.
*
*/
function show_disallowed_level_names_content_filter( $r, $post_membership_levels_ids, $post_membership_levels_names ) {
return true;
}
add_filter( 'pmpro_membership_content_filter_disallowed_levels', 'show_disallowed_level_names_content_filter', 10, 3 );
@kimcoleman
kimcoleman / one_time_trial_delay_pmpro_registration_checks.php
Last active September 30, 2020 13:35
Offer one-time trials using the Subscription Delays Add On
<?php
/**
* This code stores data when a user checks out for a level.
* If that user tries to checkout for the same level, the Subscription Delay is removed.
* The user is instead charged for their first subscription payment at checkout.
*
*/
// Record when users gain the trial level.
function one_time_trial_save_trial_level_used( $level_id, $user_id ) {
@kimcoleman
kimcoleman / simple_paid_checkout_signup.php
Last active April 4, 2021 03:36
Simplify paid level checkouts by removing Account Information section and generating username and password.
<?php
/**
* Simplify paid level checkouts by removing Account Information section and generating username and password.
* You must be capturing full Billing Information for this recipe to work.
*/
/**
* Hide the Account Information Section
*/
function simple_checkout_hide_account_information_section( $skip_account_fields, $current_user ) {
@kimcoleman
kimcoleman / simple_checkout_email_only_signup.php
Created July 3, 2019 13:58
Only require Email Address to create user.
<?php
/**
* Only require Email Address to create user.
* This recipe requires Paid Memberships Pro and the Register Helper Add On.
*
* Note: this recipe depends on a future patch to Paid Memberships Pro core plugin in order to function.
*/
/**
* Hide the Account Information Section
@kimcoleman
kimcoleman / pmpro_show_spots_available.php
Last active April 12, 2024 06:54 — forked from andrewlimaza/pmpro_show_spots_available.php
Show number of spots available for a membership level Paid Memberships Pro.
<?php
/**
* This will show '0/X spots available.' on membership level if a limit is set from (https://www.paidmembershipspro.com/limit-number-members-membership-level/)
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* For help, post a support thread on www.paidmembershipspro.com
*/
function pmpro_show_spots_available( $expiration_text, $level ) {
global $wpdb;
@kimcoleman
kimcoleman / invalid_email_addresses_pmpro_registration_checks.php
Last active July 1, 2025 09:51
Exclude specific email domains from membership signup.
<?php
/**
* Exclude specific email domains from membership signup.
* Make sure to edit the $invalid_domains array defined further below
* to include only the domains you'd like to block.
*
*/
function invalid_email_addresses_pmpro_registration_checks( $value ) {
$email = $_REQUEST['bemail'];
@kimcoleman
kimcoleman / my_require_user_login.php
Created August 29, 2019 13:01
Restrict your WordPress site for logged in users only.
<?php
/**
* Restrict your WordPress site for logged in users only.
*
*/
function my_require_user_login() {
global $current_user;
// Allow logged in users.
if ( is_user_logged_in() ) {
@kimcoleman
kimcoleman / redirect_bbpress_no_access_levels_page.php
Created August 30, 2019 18:07
Redirect users without access to a single bbPress forum to the Membership Levels page.
<?php
/**
* Redirect users without access to a single bbPress forum to the Membership Levels page.
*
*/
function redirect_bbpress_no_access_levels_page( $redirect_to, $forum_id ) {
global $pmpro_pages;
$redirect_to = get_permalink( $pmpro_pages['levels'] );