Skip to content

Instantly share code, notes, and snippets.

View dwanjuki's full-sized avatar

David Wanjuki dwanjuki

  • Nairobi, Kenya
  • 20:14 (UTC +03:00)
View GitHub Profile
@dwanjuki
dwanjuki / pmproeewe-per-level-schedules.php
Last active November 6, 2026 09:10
Per-level schedules for the Extra Expiration Warning Emails Add On
<?php
/**
* Per-level schedules for the PMPro Extra Expiration Warning Emails Add On.
*
* Edit my_pmproeewe_level_schedules() to set, for each level ID, how many days before
* expiration to send a warning and which email template to use. Levels can share a
* day value with different templates.
*
* How it works: the Add On runs one combined schedule (every day value used by any level).
* For each member it finds, this snippet checks whether the member's level has an email
@dwanjuki
dwanjuki / my_login_redirect_to_buddyboss_profile.php
Created November 2, 2026 15:11
Redirect members to their BuddyBoss profile page on login.
<?php
/**
* Redirect members to their BuddyBoss profile page on login.
*
* Uses BuddyBoss's dynamic /members/me/ link, which resolves to the
* logged-in user's profile. Requires the BuddyBoss Platform (or BuddyPress)
* profiles component to be active.
* See: https://buddyboss.com/docs/dynamic-user-profile-links/
*
* You can add this recipe to your site by creating a custom plugin
<?php
/**
* Display the "short" level cost text when using the {{ membership_cost }} email variable.
*
* 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_pmpro_email_data_membership_cost_short( $data, $email ) {
@dwanjuki
dwanjuki / my_pmpro_hide_no_access_message_homepage.php
Last active October 30, 2026 09:49
Hide the PMPro "Membership Required" content message card on the blog homepage.
<?php
/**
* Hide the PMPro protected content message card on the blog homepage.
*
* 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_pmpro_hide_no_access_message_homepage( $html, $level_ids ) {
@dwanjuki
dwanjuki / my_pmpro_redirect_logged_out_from_restricted_content.php
Created October 23, 2026 12:28
Redirect logged-out visitors away from restricted content to the login page.
<?php
/**
* Redirect logged-out visitors away from restricted content to the login page.
*
* When a logged-out visitor hits a post/page that requires membership,
* they are redirected to the login page with a redirect_to parameter
* pointing back to the content.
*
* 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.
@dwanjuki
dwanjuki / my_pmpro_block_cancel_for_expiring_levels.php
Last active October 9, 2026 14:48
Prevent members from cancelling a membership that has an expiration date
<?php
/**
* Prevent members from cancelling a membership that has an expiration date.
*
* - Removes the "Cancel" link from the Membership Account page and Billing page
* for any level with an expiration date set for that member.
* - Blocks cancellation processing via the pmpro_cancel_should_process filter.
*
* 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.
@dwanjuki
dwanjuki / my_pmprolpv_always_restrict_posts_from_category.php
Created October 8, 2026 11:25
Prevent the Limit Post Views Add On from granting free access to posts in specific categories
<?php
/**
* Prevent the Limit Post Views Add On from granting free access to posts in specific categories.
*
* 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/
*/
<?php
/**
* Allow Membership Managers to import members using Import Members from CSV.
*
* 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/
*/
@dwanjuki
dwanjuki / my_pmprogl_sync_set_expiration_date.php
Created September 22, 2026 08:20
Apply Set Expiration Date to Gift MEmbership Levels
<?php
/**
* Save the Set Expiration Date from the target Gift Level to the gift discount
* code after gift purchase.
*
* 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/
*/
@dwanjuki
dwanjuki / my_pmpro_has_subscription_for_level.php
Last active September 17, 2026 09:22
Helper function to check if a user has an active subscription for a level, or a cancelled subscription where the associated membership level is still active
<?php
/**
* Check if a user has an active subscription for a level,
* or a cancelled subscription where the associated membership level is still active
* (paid through until its scheduled expiration date).
*
* @param int $user_id User ID.
* @param int $level_id Membership Level ID.
* @return bool True if active subscription or active paid-through cancelled subscription.
*/