Skip to content

Instantly share code, notes, and snippets.

View contemplate's full-sized avatar

Ted Barnett contemplate

View GitHub Profile
@contemplate
contemplate / functions.php
Last active April 25, 2026 20:51
BPGES integration with BuddyBoss
/**
* Prevent duplicate emails between BPGES and BuddyBoss Group Subscriptions.
*
* The problem: Both systems send emails on group activity.
* - BuddyBoss hooks bp_groups_posted_update → sends 'groups-new-activity' immediately
* - BPGES hooks bp_activity_after_save → sends 'bp-ges-single' immediately for supersub/sub users
* Result: Users on "All Email" or "New Topics" get two emails per post.
*
* The solution: Let each system handle what it does best.
* - 'supersub' (All Email) → BuddyBoss sends immediate email, BPGES is blocked
@contemplate
contemplate / functions.php
Created January 28, 2025 16:43
WooCommerce Subscriptions Conditional Reminder Email Ability
/**
* Add a new "Subscription Reminders" tab in the Product Data panel
* for Simple Subscription products only.
*/
add_filter( 'woocommerce_product_data_tabs', 'wcs_add_subscriptions_reminders_tab_simple' );
function wcs_add_subscriptions_reminders_tab_simple( $tabs ) {
// Only add this tab for subscription products (excluding variable-subscriptions).
// The "show_if_subscription" class ensures the tab is visible only for "simple subscription".
$tabs['wcs_sub_reminders_simple'] = array(
@contemplate
contemplate / class-wc-sc-purchase-credit.php
Created December 10, 2024 04:02
WC Smart Coupons Accept AM / PM time to schedule gifts
jQuery('form.woocommerce-checkout').on('change', 'input.gift_sending_date_time', function(e){
let date_time_wrapper = jQuery(this).closest('.email_sending_date_time_wrapper');
let gift_sending_date_time = jQuery(date_time_wrapper).find('.gift_sending_date_time').val();
if ('' === gift_sending_date_time) {
return;
}
// Split the date and time correctly
let gift_sending_date_time_parts = gift_sending_date_time.split(' ');
let gift_sending_date = gift_sending_date_time_parts[0]; // Date part (e.g., '23-12-2024')
@contemplate
contemplate / functions.php
Created November 17, 2024 21:35
LearnDash Lesson Progress Bar shortcode
// Register the shortcode
add_shortcode( 'learndash_lesson_progress', 'learndash_lesson_progress_bar' );
function learndash_lesson_progress_bar ( $atts = array(), $content = '' ) {
global $learndash_shortcode_used;
$learndash_shortcode_used = true;
$atts = shortcode_atts(
array(
'lesson_id' => 0,
@contemplate
contemplate / functions.php
Created July 19, 2024 21:15
LearnDash Category Progress shortcode
add_shortcode( 'learndash_category_progress', 'learndash_category_progress', 10, 3 );
function learndash_category_progress( $atts = array(), $content = '', $shortcode_slug = 'learndash_category_progress' ) {
global $learndash_shortcode_used;
$learndash_shortcode_used = true;
$atts = shortcode_atts(
array(
'course_category_id' => 0,
'user_id' => 0,
'array' => false,
@contemplate
contemplate / functions.php
Created April 10, 2024 14:24
WPC Product Bundles for WooCommerce Shortcode
// Hook into init action to set bundled_position to "no" if the shortcode is used
function wpc_set_bundled_position() {
add_filter('woosb_get_setting', 'wpc_disable_bundled_position', 10, 3);
}
// Function to set bundled_position to "no" if the shortcode is used
function wpc_disable_bundled_position($setting, $name, $default) {
// Check if the shortcode is used on the current page
if ($name === 'bundled_position' && wpc_is_show_bundled_shortcode_used()) {
return 'no';
@contemplate
contemplate / functions.php
Created March 15, 2024 16:28
Divi Theme: Replace Top Header with a Header Sidebar Area
// Register custom sidebar
function custom_register_sidebars() {
register_sidebar( array(
'name' => 'Header',
'id' => 'header_sidebar',
'description' => 'Widgets in this area will be shown in the header.',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
@contemplate
contemplate / functions.php
Created February 8, 2024 04:40
WooCommerce Memberships: exclude post loops on forced public pages
// Initialize the global flag on the wp action hook
add_action('wp', 'initialize_force_public_page_flag');
function initialize_force_public_page_flag() {
global $is_force_public_page, $wp_query;
$is_force_public_page = false;
if (!empty($wp_query->queried_object_id)) {
$is_force_public_page = get_post_meta($wp_query->queried_object_id, '_wc_memberships_force_public', true) === 'yes';
}
}
@contemplate
contemplate / functions.php
Created February 3, 2024 18:27
ACF Relational Field Shortcode Expanded
/**
* Output an ACF post relationship field type using a shortcode:
* [acf_relationship_field field="field_name" show="all"]
* You can also pass `post_id` as an attribute
*
* Show parameter accepts any comma seperated combination of: all, title, title_linked, date, author, post_excerpt, post_content
*
* Works with Post Object and Relationship fields, when the return
* format is both post object and post ID
*
@contemplate
contemplate / functions.php
Created January 15, 2024 16:19
AffiliateWP: limit leaderbaord to specific affiliate group
add_filter( 'affwp_leaderboard_defaults', 'group_affwp_leaderboard_defaults', 10 );
function group_affwp_leaderboard_defaults( $defaults ) {
$defaults['connected_to'] = array(
'get_connectable' => 'affiliate',
'where_connectable' => 'group',
'where_id' => 2, // ID of the affiliate group
'where_group_type' => 'affiliate-group',
);
return $defaults;