Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@kimcoleman
kimcoleman / update_contact_tags_on_category_view.php
Last active February 27, 2024 21:22
Add tags to contacts in FluentCRM when viewing a post in a specific category.
<?php
// Add tags to contacts when viewing a post in a specific category.
function update_contact_tags_on_post_view() {
// Return if they aren't logged in.
if ( ! is_user_logged_in() ) {
return;
}
// Return if the FluentCrmApi is not available.
if ( ! function_exists( 'FluentCrmApi' ) ) {
@kimcoleman
kimcoleman / optional-pmpro-3-0-database-updates.php
Last active February 19, 2024 18:58
Optional database updates to drop orphaned orders table columns and unused usermeta rows.
<?php
/**
* Optional database updates to drop orphaned orders table columns and unused usermeta rows.
*/
function run_optional_pmpro_upgrade_3_0() {
global $wpdb;
// PMPro Stripe Billing Limits Add On has been merged into core and no longer needs `pmpro_stripe_billing_limit` user meta.
$sqlQuery = "
DELETE FROM {$wpdb->usermeta}
@kimcoleman
kimcoleman / pmpro_upgrade_3_0_rerun.php
Created February 19, 2024 15:54
Re-run the PMPro v3.0 upgrade script.
<?php
/**
* Re-runs the 3.0 upgrade script.
*/
function pmpro_upgrade_3_0_rerun() {
global $wpdb;
// Create a subscription for each unique `subscription_transaction_id` in the orders table.
$sqlQuery = "
INSERT IGNORE INTO {$wpdb->pmpro_subscriptions} ( user_id, membership_level_id, gateway, gateway_environment, subscription_transaction_id, status )
@kimcoleman
kimcoleman / my_memberlite_remove_banner_on_events_archive.php
Last active February 17, 2024 12:07
Remove the Memberlite Banner from the category archive for The Events Calendar events.
<?php
/**
* Remove the Memberlite Banner from the category archive for The Events Calendar events.
*/
function my_memberlite_remove_banner_on_events_archive( $show ) {
// Let's not do this if it is not the homepage
$show = is_post_type_archive( array( 'tribe_events' ) ) ? false : true;
return $show;
}
add_filter( 'memberlite_banner_show', 'my_memberlite_remove_banner_on_events_archive', 15 );
@kimcoleman
kimcoleman / memberlite_modify_columns_ratio_for_blog.php
Created January 31, 2024 13:00
Add a sidebar to the Memberlite blog and archives pages when using the grid-style post layout.
<?php
function memberlite_modify_columns_ratio_for_blog( $r, $location ) {
// Check if the current page is a blog page
$maybe_add_sidebar = memberlite_is_blog();
if ( $maybe_add_sidebar && ! in_array( $location, array( 'header-right', 'header-left' ) ) ) {
// Set layout ratio for the blog main area and sidebar
$r = ( $location == 'sidebar' ) ? '4' : '8';
}
@kimcoleman
kimcoleman / my_custom_memberlite_woocommerce_hooks.php
Created January 31, 2024 12:58
Add a sidebar to the entire WooCommerce shop and product pages using the Memberlite theme.
<?php
function my_custom_memberlite_woocommerce_hooks() {
// Remove Memberlite hooks
remove_action( 'woocommerce_before_main_content', 'memberlite_woocommerce_before_main_content', 10 );
remove_action( 'woocommerce_after_main_content', 'memberlite_woocommerce_after_main_content', 10 );
// Add custom WooCommerce hooks
add_action( 'woocommerce_before_main_content', 'my_custom_memberlite_woocommerce_before_main_content', 10 );
add_action( 'woocommerce_after_main_content', 'my_custom_memberlite_woocommerce_after_main_content', 10 );
@kimcoleman
kimcoleman / my_pmpro_member_directory_sql_search_where_username_display_name_only.php
Last active December 21, 2023 20:36
Only search the PMPro Member Directory for matching usernames or display names.
<?php
/**
* Only search the PMPro Member Directory for matching usernames or display names.
*
* 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_member_directory_sql_search_where_username_display_name_only( $sql_search_where, $s ) {
@kimcoleman
kimcoleman / my_sws_apply_sitewide_sales_discount_to_live_price.php
Last active November 18, 2023 19:11
Sitewide Sales compatibility with RightPress Product Prices - Live Update.
<?php
/**
* Sitewide Sales compatibility with RightPress Product Prices - Live Update.
*/
function my_sws_apply_sitewide_sales_discount_to_live_price($price, $product) {
// Return early if Sitewide Sales is not active.
if ( ! defined ( 'SWSALES_VERSION' ) ) {
return $price;
}
@kimcoleman
kimcoleman / pmpro-tag-delete-inactive-users.php
Last active October 31, 2023 12:06 — forked from ideadude/tag_and_delete_inactive_users.php
Script to tag and delete inactive PMPro Members and users from WordPress.
<?php
/**
* Script to locate, tag, export, then delete inactive users in your Paid Memberships Pro / WordPress website.
*
* Once this snippet is in the site, admins can run the process by visiting /?delete_inactive_users=1 in the WordPress admin.
* Always back up user data before running any bulk delete script and remove this code after the process is done.
*/
function my_pmpro_tag_inactive_users() {
if ( ! defined( 'PMPRO_VERSION' ) ) {
exit;
@kimcoleman
kimcoleman / my_pmpro_has_membership_access_on_date.php
Last active October 30, 2023 11:36
Filter to only allow access to a protected post by post ID after a specific calendar date.
<?php
/**
* Filter to only allow access to a protected post by post ID after a specific calendar date.
*/
function my_pmpro_has_membership_access_on_date( $hasaccess, $post, $user ) {
// If they already don't have access, return.
if ( ! $hasaccess ) {
return $hasaccess;
}