Skip to content

Instantly share code, notes, and snippets.

Avatar

Kim Coleman kimcoleman

View GitHub Profile
@kimcoleman
kimcoleman / my_memberlite_custom_color_mods.php
Created May 5, 2022
Memberlite filters to set custom colors for specific pages.
View my_memberlite_custom_color_mods.php
<?php
/**
* Memberlite filters to set custom colors for specific pages.
*/
// Filter the primary color on a page with the slug 'free'.
function my_memberlite_custom_color_primary( $current_mod ) {
if ( ! is_page( 'free' ) ) {
return $current_mod;
}
@kimcoleman
kimcoleman / my_pmpro_refund_reason.php
Created Apr 28, 2022
Add an order meta field for "Refund Reason" so admin can track why people are asking for a refund.
View my_pmpro_refund_reason.php
<?php
/**
* Add an order meta field for "Refund Reason" so admin can track
* why people are asking for a refund.
*/
function my_pmpro_refund_reason_after_order_settings( $order ) {
if ( empty( $order->id ) ) {
// This is a new order.
return;
}
@kimcoleman
kimcoleman / my_bua_bp_avatar.php
Created Apr 25, 2022
Filter to use the Basic User Avatar on the BuddyPress Profile.
View my_bua_bp_avatar.php
<?php
/**
* Filter to use the Basic User Avatar on the BuddyPress Profile.
*/
function my_bua_bp_avatar( $image, $params ) {
// Determine if user has a local avatar
$local_avatar = get_user_meta( $params['item_id'], 'basic_user_avatar', true );
if ( empty( $local_avatar ) ) {
return $image;
@kimcoleman
kimcoleman / my_habfna_show_admin_bar_roles.php
Created Apr 10, 2022
Filter to show WordPress Toolbar for Editor Role using the Hide Admin Bar From Non-Admins plugin.
View my_habfna_show_admin_bar_roles.php
<?php
/**
* Filter to show WordPress Toolbar for Editor Role using the
* Hide Admin Bar From Non-Admins plugin.
* https://wordpress.org/plugins/hide-admin-bar-from-non-admins/
*
*/
function my_habfna_show_admin_bar_roles( $habfna_show_admin_bar_roles ) {
$habfna_show_admin_bar_roles[] = 'editor';
return $habfna_show_admin_bar_roles;
View pmpro_add_google_tag_manager_to_body.php
<?php
/**
* Fallback to add GTM to body of page.
*
*/
function pmpro_add_google_tag_manager_to_body() {
// Don't track admins.
if ( current_user_can( 'manage_options' ) ) {
return;
} ?>
@kimcoleman
kimcoleman / pmpro_gtag_ecommerce_set_session.php
Created Apr 7, 2022
Add a session variable so we only push the ecommerce data to GTM on the first checkout, not any subsequent visit to the confirmation page.
View pmpro_gtag_ecommerce_set_session.php
<?php
/**
* Add a session variable so we only push the ecommerce data to GTM on the first checkout.
* Not any subsequent visit to the confirmation page.
*
*/
function pmpro_gtag_ecommerce_set_session( $user_id, $morder ) {
pmpro_set_session_var( 'pmpro_gtag_order', $morder->id );
}
add_action( 'pmpro_after_checkout', 'pmpro_gtag_ecommerce_set_session', 10, 2 );
@kimcoleman
kimcoleman / pmpro_add_google_tag_manager_to_head.php
Last active Apr 7, 2022
Builds the dataLayer and loads GTM tracking in the head. Includes Custom Dimensions and Ecommerce data for Paid Memberships Pro.
View pmpro_add_google_tag_manager_to_head.php
<?php
/**
* Builds the dataLayer and loads GTM tracking in the head.
* Includes Custom Dimensions and Ecommerce data.
*
*/
function pmpro_add_google_tag_manager_to_head() {
global $pmpro_pages;
// Don't track admins.
@kimcoleman
kimcoleman / my_get_the_terms.php
Created Apr 5, 2022
Hide tags from display if there is only one post in the taxonomy.
View my_get_the_terms.php
<?php
/**
* Hide tags from display if there is only one post in the taxonomy.
*
*/
function my_get_the_terms( $terms, $post_id, $taxonomy ) {
if ( $taxonomy === 'post_tag' ) {
foreach( $terms as $key => $term ) {
if ( $term->count < 2 ) {
unset( $terms[ $key ] );
@kimcoleman
kimcoleman / example-post-content-require-membership.html
Last active Mar 23, 2022
Example post content using the [membership] shortcode.
View example-post-content-require-membership.html
[membership level="0"]
Are you interested in learning what the meaning of life is?
Sign up today and we'll tell you!
[/membership]
[membership level="1"]
Thanks for being a member of our program.
The meaning of life is: 42.
@kimcoleman
kimcoleman / memberlite-heading-font-sizes.css
Created Mar 17, 2022
Customizing font sizes for headings in Memberlite
View memberlite-heading-font-sizes.css
h1,
h2,
.h1,
.h2 {
font-size: 3.2rem;
line-height: 4.4rem;
}
.entry-content h1,
.entry-content .h1 {
font-size: 4.7rem;