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_template_url_parameter_at_checkout.php
Created October 8, 2024 13:19
Redirect away from checkout if the secret URL parameter is missing.
<?php
/**
* Redirect away from checkout if the secret URL parameter is missing.
*/
function my_pmpro_template_url_parameter_at_checkout() {
global $pmpro_pages;
// Return early if we are not on a PMPro page.
if ( empty( $pmpro_pages ) ) {
return;
@kimcoleman
kimcoleman / my_pmpro_remove_no_access_message_from_bbp_is_forum_archive.php
Created September 12, 2024 17:03
Remove the restricted messages shown on the /forums/ archive in BuddyBoss.
<?php
/**
* Remove the restricted messages shown on the /forums/ archive in BuddyBoss.
* BuddyBoss is running the /forums/ page content through the the_content filter, which detects protected forums within the loop.
*/
function my_pmpro_remove_no_access_message_from_bbp_is_forum_archive( $text ) {
// Check if we are on the homepage.
if ( function_exists( 'bbp_is_forum_archive' ) && bbp_is_forum_archive() ) {
// Return an empty string.
return '';
@kimcoleman
kimcoleman / my_pmpro_check_and_upgrade_level_on_login.php
Created August 9, 2024 20:11
UNTESTED: Check if a user is already at level 1. If they have been at that level for 30 days, upgrade them to level 2.
<?php
/**
* UNTESTED: Check if a user is already at level 1. If they have been at that level for 30 days, upgrade them to level 2.
*
* 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_check_and_upgrade_level_on_login( $user_login, $user ) {
@kimcoleman
kimcoleman / my_custom_pmpro_stripe_card_element_style.php
Created July 31, 2024 13:48
Upcoming filter in PMPro v 3.1.2 or higher (not currently released) to adjust the appearance of Stripe Card Element styles.
<?php
/**
* Upcoming filter in PMPro v 3.1.2 or higher (not currently released) to adjust the appearance of Stripe Card Element styles.
* Refer to this Stripe documentation for available properties: https://docs.stripe.com/js/appendix/style
*/
function my_custom_pmpro_stripe_card_element_style($styles) {
$custom_styles = array(
'base' => array(
'color' => '#FFFFFF',
'::placeholder' => array(
@kimcoleman
kimcoleman / my_pmpro_element_class_an2c.php
Created July 30, 2024 18:13
Show the First and Last Name fields in a single column
<?php
/**
* Show the First and Last Name fields in a single column
*
* 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_lifter_llms_plan_get_checkout_url.php
Created July 26, 2024 19:20
Some logic to set up free access plans that require PMPro membership level to enroll in.
/**
* Require a specific membership level IDs to enroll in free access plans.
*/
function my_pmpro_llms_access_plan_is_available_to_user( $access, $user_id, $access_plan ) {
// Bail if streamline is not enabled.
if ( ! get_option( 'pmpro_lifter_streamline' ) ) {
return $access;
}
// If the plan isn't free, let LifterLMS handle it.
@kimcoleman
kimcoleman / my_pmpro_enqueue_theme_frontend_css.php
Created July 18, 2024 19:38
Legacy code to enqueue a theme or child theme's version of frontend.css for PMPro v3.1+.
<?php
/**
* Enqueue your theme or child theme's version of the legacy frontend.css file.
* Note: PMPro v3.1+ css selectors have been overhauled and many of the legacy class names are no longer supported.
*/
function my_pmpro_enqueue_theme_frontend_css() {
if ( is_admin() ) {
return;
}
@kimcoleman
kimcoleman / blank_base.css
Last active September 4, 2024 12:10
Sample file for theme developers include the CSS classes for v3.1 of Paid Memberships Pro elements.
.pmpro_message { }
.pmpro_message.pmpro_success { }
.pmpro_message.pmpro_error { }
.pmpro_message.pmpro_alert { }
.pmpro_message a { }
.pmpro_success a { }
.pmpro_error a { }
.pmpro_alert a { }
@kimcoleman
kimcoleman / my_pmproup_wp_parent_page_redirect.php
Last active May 14, 2024 17:34
Redirect the Top Level User Page (parent page of all user pages) to a custom page (not the homepage, which is default for non-admins in the User Pages Add On).
<?php
/**
* Redirect the main user page parent to a custom page.
*/
function my_pmproup_wp_parent_page_redirect() {
global $wpdb, $post, $current_user;
$options = pmproup_getOptions();
if ( ! is_admin() && ! empty($post) && ! empty($options['parent_page'] ) && $post->ID == $options['parent_page'] ) {
@kimcoleman
kimcoleman / my_pmpro_profile_page_meta.php
Created May 14, 2024 13:14
Filters the Yoast meta title and meta description on the profile page to display the user's display name and biography.
<?php
/**
* Filters the Yoast meta title on the profile page to display the user's display name.
*
* @param string title The current page's generated title.
* @return string The filtered title.
*/
function my_pmpro_profile_page_meta_title( $title ) {
global $pmpro_pages;