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_refund_reason.php
Created April 28, 2022 10:15
Add an order meta field for "Refund Reason" so admin can track why people are asking for a refund.
<?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 April 25, 2022 15:54
Filter to use the Basic User Avatar on the BuddyPress Profile.
<?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 April 10, 2022 11:30
Filter to show WordPress Toolbar for Editor Role using the Hide Admin Bar From Non-Admins plugin.
<?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;
@kimcoleman
kimcoleman / pmpro_add_google_tag_manager_to_body.php
Created April 7, 2022 13:19
Fallback to add GTM to body of page.
<?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 April 7, 2022 13:17
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.
<?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 January 3, 2024 16:12
Builds the dataLayer and loads GTM tracking in the head. Includes Custom Dimensions and Ecommerce data for Paid Memberships Pro.
<?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 April 5, 2022 01:18
Hide tags from display if there is only one post in the taxonomy.
<?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 March 23, 2022 00:41
Example post content using the [membership] shortcode.
[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 March 17, 2022 10:37
Customizing font sizes for headings in Memberlite
h1,
h2,
.h1,
.h2 {
font-size: 3.2rem;
line-height: 4.4rem;
}
.entry-content h1,
.entry-content .h1 {
font-size: 4.7rem;
@kimcoleman
kimcoleman / pmpro_expiration_date_shortcode_bbpress_profile.php
Last active February 21, 2022 11:39 — forked from strangerstudios/pmpro_expiration_date_shortcode_bbpress_profile.php
Show a member's expiration date on bbPress profile page.
<?php
/**
* Use this recipe in conjunction with PMPro bbPress Add On to show the expiration date on single forum user profile.
*
* 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.
*
*/
function my_bbp_template_before_user_profile_pmpro_expiration_date() {
$user_id = bbp_get_user_id( 0, true, false );