Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@kimcoleman
kimcoleman / cleanup-user-fields-avatars.php
Last active March 6, 2026 17:32
UNTESTED: Cleanup script: Remove User Fields Avatar meta after PMPro migration.
<?php
/**
* Cleanup script: Remove User Fields Avatar meta after PMPro migration.
* Use the migration script first: https://gist.github.com/kimcoleman/bab980d8eba1c59fc1be966eaa23a5d5
*
* Run this as a WP-CLI command.
* Save this code to a file cleanup-user-fields-avatars.php.
* Put the file in your WordPress root directory (the same folder where wp-config.php lives).
*
* WP-CLI usage: wp eval-file cleanup-user-fields-avatars.php
@kimcoleman
kimcoleman / migrate-user-fields-avatars.php
Created March 6, 2026 17:15
UNTESTED: Migration script: PMPro User Fields Avatar (wp_user_avatar) → PMPro Avatars
<?php
/**
* Migration script: PMPro User Fields Avatar (wp_user_avatar) → PMPro Avatars
*
* Run this as a WP-CLI command.
* Save this code to a file migrate-user-fields-avatars.php
* Put the file in your WordPress root directory (the same folder where wp-config.php lives).
*
* WP-CLI usage: wp eval-file migrate-user-fields-avatars.php
*
@kimcoleman
kimcoleman / cleanup-bua.php
Created March 6, 2026 17:07
Cleanup script: Remove Basic User Avatars meta + files after PMPro migration.
<?php
/**
* Cleanup script: Remove Basic User Avatars meta + files after PMPro migration.
* Use the migration script first: https://gist.github.com/kimcoleman/f031b36f4a685eff315390ccc19889b1
*
* Run this as a WP-CLI command.
* Save this code to a file cleanup-bua.php.
* Put the file in your WordPress root directory (the same folder where wp-config.php lives).
*
* WP-CLI usage: wp eval-file cleanup-bua.php
@kimcoleman
kimcoleman / pmpro_migrate_basic_user_avatars.php
Created March 6, 2026 16:56
Migration script: Basic User Avatars → PMPro Avatars
<?php
/**
* Migration script: Basic User Avatars → PMPro Avatars
*
* Run this as a WP-CLI command.
* Save this code to a file migrate-avatars.php.
* Put the file in your WordPress root directory (the same folder where wp-config.php lives).
*
* WP-CLI usage: wp eval-file migrate-avatars.php
* Update the $dry_run value to "false" to run the actual migration.
@kimcoleman
kimcoleman / my_pmpro_patterns_admin_menu.php
Created February 17, 2026 15:28
Add an admin menu link for Patterns
<?php
/**
* Add an admin menu link for Patterns
*/
function my_pmpro_patterns_admin_menu() {
add_menu_page( 'Patterns', 'Patterns', 'edit_posts', 'edit.php?post_type=wp_block', '', 'dashicons-editor-table', 22 );
}
add_action( 'admin_menu', 'my_pmpro_patterns_admin_menu' );
@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