Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@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
}
@kimcoleman
kimcoleman / my_pmpro_set_submission_limit_by_level.php
Last active November 12, 2024 17:36
Set the submission limit of a WS Form based on the logged-in member's Membership Level.
<?php
/**
* Check how many posts a member has submitted to a specific form on page ID '48'.
* Hide the form if they have reached the submission limit for their Membership Level.
*/
function my_pmpro_submission_limit_hide_ws_form( $content ) {
// Return early if PMPro is not active or the user is not logged in.
if ( ! function_exists( 'pmpro_has_membership_access' ) || ! is_user_logged_in() ) {
return $content;
}
@kimcoleman
kimcoleman / my_pmpro_courses_lesson_nav.php
Last active October 31, 2024 13:06
Display navigation to next/previous lesson within a single course with Paid Memberships Pro and the PMPro Courses Add On
<?php
/**
* Display navigation to next/previous lesson within a single course.
*/
function my_pmpro_courses_lesson_nav( $course_id ) {
global $post;
// Fetch all lessons associated with the course in the correct order.
$lessons = pmpro_courses_get_lessons( $course_id );
@kimcoleman
kimcoleman / format_video_profile_field.php
Created October 28, 2024 20:45
Add a container to wrap a video oembed field and make it responsive.
<?php
/**
* Wrap the oembed video in a div so we can use custom CSS to make the video responsive inside the container.
* You must also add the following custom CSS to your site:
* .video-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; }
* .video-container iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
*/
function format_video_profile_field( $value, $original_value, $field_name ) {
// Return early if the field name is not 'video'
if ( 'video' !== $field_name ) {
@kimcoleman
kimcoleman / my_pmpro_kit_add_last_name_to_subscribe_fields.php
Created October 28, 2024 14:31
Send the custom field "last_name" to Kit.
<?php
function my_pmpro_kit_add_last_name_to_subscribe_fields( $subscribe_fields, $user_email ) {
// Get the user by email
$user = get_user_by( 'email', $user_email );
// If the user is found, add the last name to the fields
if ( $user ) {
$last_name = $user->last_name;
if ( $last_name ) {
$subscribe_fields['last_name'] = $last_name;
<?php
/**
* Add custom card classes to the Terms of Service (TOS) field in PMPro checkout.
*
* This function uses the 'pmpro_element_class' filter to add custom classes
* to the TOS fieldset, form fields, and other elements within the TOS area.
*
* @param array $class Array of element class names.
* @param string $element The element to return class names for.
*