Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@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 / my_pmpro_renew_or_change_payment_method.php
Created February 27, 2025 19:52
Let members switch payment methods but preserve their current subscription price and renewal date.
<?php
/**
* Get the next payment date for a user's level inclusive of subscriptions and expiration dates.
*
* If the current user has a subscription for a passed level ID, return the next payment date for that subscription.
* Otherwise, if the user has an expiration date set for the level, return that.
* Otherwise, return null.
*
* @param int $level_id The level ID to check for.
* @return int|null The next payment date/expiration date as a timestamp or null.
@kimcoleman
kimcoleman / my_coa_demo_pmpro_gettext_changes.php
Created December 12, 2024 15:27
Changing frontend plugin text using gettext filter. Used for the Condo Owner's Association Demo at https://coa.pmproplugin.com/
<?php
function my_coa_demo_pmpro_gettext_changes( $translated_text, $text, $domain ) {
if ( $domain == 'pmpro-shipping' ) {
if ( $text == 'Shipping Address' ) {
$translated_text = 'Mailing Address';
}
}
return $translated_text;
}
@kimcoleman
kimcoleman / condo_units_table_shortcode.php
Created December 12, 2024 15:26
Shortcode for Units directory. Used for the Condo Owner's Association Demo at https://coa.pmproplugin.com/
<?php
/**
* Shortcode to display a table of units, owners, and residents.
*/
function condo_units_table_shortcode( $atts ) {
global $wpdb;
// Shortcode attributes with defaults
$atts = shortcode_atts( array(
'meta_key' => 'unit', // The usermeta key to retrieve unit numbers
@kimcoleman
kimcoleman / my_coa_demo_add_custom_inline_style.php
Created December 12, 2024 15:25
Custom CSS added to wp_head. Used for the Condo Owner's Association Demo at https://coa.pmproplugin.com/
<?php
function my_coa_demo_add_custom_inline_style() {
echo '<style>
/* Custom CSS here */
.pmpro_member_directory_before,
.pmpro_member_directory_after {
display: none;
}
.pmpro_member_directory .pmpro_member_directory-item.pmpro_card {
margin-top: 60px;
@kimcoleman
kimcoleman / my_coa_demo_pmpro_add_memberslist_cols.php
Created December 12, 2024 15:24
Custom recipe to add columns to the Members List. Used for the Condo Owner's Association Demo at https://coa.pmproplugin.com/
<?php
function my_coa_demo_pmpro_add_memberslist_cols( $columns ) {
$columns['unit'] = 'Unit';
$columns['condo_status'] = 'Condo Status';
$columns['household_count'] = 'Household Members';
$columns['household_pet_count'] = 'Household Pets';
$columns['parking_spot_number'] = 'Parking Spot Number';
return $columns;
@kimcoleman
kimcoleman / my_coa_demo_template_redirect_lock_entire_site.php
Created December 12, 2024 15:23
Custom recipe to lock down everything but the homepage. Used for the Condo Owner's Association Demo at https://coa.pmproplugin.com/
<?php
function my_coa_demo_template_redirect_lock_entire_site(){
// If the user has a membership level, we don't need to lock down the site.
if ( ! function_exists( 'pmpro_hasMembershipLevel' ) || pmpro_hasMembershipLevel() ) {
return;
}
// If they have membership, return.
if ( pmpro_hasMembershipLevel() ) {
return;
@kimcoleman
kimcoleman / my_custom_user_page_template_redirect.php
Created December 5, 2024 17:36
Redirection for the User Pages Add On when you do not want to set the Top Level Page in Add On settings.
<?php
/**
* Redirection for the User Pages Add On.
*
* Note: This is only needed when you do not want to set the Top Level Page in Add On settings.
* If you have set a Top Level Page, the Add On has native logic for redirection.
*/
function my_custom_user_page_template_redirect() {
// Exit early if not on the control page.
if ( ! is_page( 'clients' ) ) {
@kimcoleman
kimcoleman / modify_pmpro_lesson_post_type_args.php
Created November 25, 2024 19:35
Modify the pmpro_lesson post type args to allow comments.
<?php
function modify_pmpro_lesson_post_type_args($args, $post_type) {
// Target only the 'pmpro_lesson' post type
if ($post_type === 'pmpro_lesson') {
// Merge 'comments' (discussion) support into the 'supports' array
if (isset($args['supports']) && is_array($args['supports'])) {
$args['supports'][] = 'comments'; // Add 'comments' support
} else {
$args['supports'] = array('comments'); // Create the supports array if it doesn't exist
}