Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@kimcoleman
kimcoleman / option_pmpro_showexcerpts_on_pages.php
Last active December 3, 2025 15:43
Override the Advanced Setting to hide excerpts if this is 'page' post type in Paid Memberships Pro.
<?php
/*
* Override the Advanced Setting to hide excerpts if this is 'page' post type.
*
* 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/
*
*/
@kimcoleman
kimcoleman / protected_post_custom_post_thumbnail_html_css.css
Last active December 1, 2025 13:21
CSS to accompany the recipe on filtering the featured image and include an overlay if the post is protected.
/* Use this with the recipe here: https://gist.github.com/kimcoleman/faf2cd0a83f3ca7a5c6c368e371ad1f3 */
.pmpro_protected_post_featured_image {
position: relative;
overflow: hidden;
}
.pmpro_protected_post_featured_image img {
filter: grayscale(1) blur(5px);
}
.pmpro_protected_post_blur_mask {
-webkit-box-align: center;
@kimcoleman
kimcoleman / pmpro-tag-delete-inactive-users.php
Last active October 24, 2025 10:35 — forked from ideadude/tag_and_delete_inactive_users.php
Script to tag and delete inactive PMPro Members and users from WordPress.
<?php
/**
* Script to locate, tag, export, then delete inactive users in your Paid Memberships Pro / WordPress website.
*
* Once this snippet is in the site, admins can run the process by visiting /?delete_inactive_users=1 in the WordPress admin.
* Always back up user data before running any bulk delete script and remove this code after the process is done.
*/
function my_pmpro_tag_inactive_users() {
if ( ! defined( 'PMPRO_VERSION' ) ) {
exit;
@kimcoleman
kimcoleman / my_login_redirect_per_membership_level.php
Created May 17, 2020 13:53
Redirect members on login to a specific page based on their level.
<?php
/**
* Redirect members on login to a specific page based on their level.
*
* 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/
*
*/
@kimcoleman
kimcoleman / pmpro_monsterinsights_level_custom_dimension.php
Last active August 25, 2025 13:19
Add a new "Membership Level" dimension to track via MonsterInsights.
<?php
/**
* Add a new "Membership Level" Custom Dimension to your Google Analytics tracking code.
*
* Requires Paid Memberships Pro, MonsterInsights Pro and the MonsterInsights - Dimensions Addon.
*/
/**
* Filter for adding the new dimension as under Insights > Settings > Dimensions
*/
@kimcoleman
kimcoleman / my_first_last_display_name.php
Last active June 25, 2025 09:31
Set Display Name on Membership Checkout and for BuddyPress Name field.
<?php
/**
* Set Display Name on Membership Checkout and for BuddyPress Name field.
*/
function my_first_last_display_name( $user_id, $morder ) {
// Get user's first and last name.
$first_name = get_user_meta( $user_id, 'first_name', true );
$last_name = get_user_meta( $user_id, 'last_name', true );
@kimcoleman
kimcoleman / my_update_existing_user_nicenames.php
Created April 8, 2025 14:51
One-time update: Set user_nicename to a safe "first-name-last-name" format for existing users.
/**
* One-time update: Set user_nicename to a safe "first-name-last-name" format for existing users.
*/
function my_update_existing_user_nicenames() {
// Only run for admins to avoid performance hits or unauthorized access.
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
// Add a transient so we only run this once.
@kimcoleman
kimcoleman / my_set_safe_user_nicename.php
Created April 8, 2025 14:47
Filter the user nicename to use a sanitized first-name-last-name format.
<?php
/**
* Filter the user nicename to use a sanitized first-name-last-name format.
*/
function my_set_safe_user_nicename( $nicename ) {
if ( ! isset( $_POST['first_name'] ) || ! isset( $_POST['last_name'] ) ) {
return $nicename;
}
$first_name = sanitize_text_field( $_POST['first_name'] );
@kimcoleman
kimcoleman / pmpro_do_membership_account_shortcode.php
Created August 23, 2018 16:21
Show the pmpro_account shortcode on the WooCommmerce My Account page for members who have a history of membership through Paid Memberships Pro.
<?php
/**
* Show the pmpro_account shortcode on the WooCommmerce My Account page for members
* who have a history of membership through Paid Memberships Pro.
*/
function pmpro_do_membership_account_shortcode() {
global $wpdb, $current_user;
if( is_user_logged_in() && defined( 'PMPRO_VERSION' ) ) { ?>
<style> .pmpro_actionlinks {display: none; } </style>
<?php
@kimcoleman
kimcoleman / pmpro-expire-soon-banner.php
Last active March 11, 2025 21:31 — forked from travislima/pmpro-expire-soon-banner.php
Create a banner that will display a message to soon to be expiring members
<?php
/**
* This code will display a renewal reminder notification banner at the top of your website for members whose membership
* level will expire within 7 days of the date they visit your site.
* 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.
*/
function pmpro_show_banner_renewal_message() {
global $pmpro_pages;