Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / pmpro_is_downgrade_true.php
Created December 31, 2017 20:13
Tell the PMPro Proration Add On that every level change is a "downgrade" or sidegrade.
/*
Tell the PMPro Proration Add On that every level change is a "downgrade" or sidegrade.
This will cause the PMPro checkout to always charge $0 for level changes, while setting up
a subscription to charge the new plan price on the next payment date.
This is useful if you have all recurring membership levels that are basically payment plans vs
differently priced levels.
Add this code to a custom plugin.
@ideadude
ideadude / pmpro_modal_checkout_custom_level.php
Created January 8, 2018 17:14
Example to change which checkout level is used for modal checkout based on page
<?php
/**
* Define the default level to use for the modal
*/
$uri = $_SERVER['REQUEST_URI'];
$page_slug = '/about';
if( strpos($uri, $page_slug) !== false ) {
define('PMPRO_MODAL_CHECKOUT_DEFAULT_LEVEL', 2);
} else {
define('PMPRO_MODAL_CHECKOUT_DEFAULT_LEVEL', 1);
@ideadude
ideadude / pmprosm_sponsored_account_levels.php
Last active November 27, 2023 15:02
Example global settings for the PMPro Sponsored Members Add On
/*
Define the global array below for your main accounts and sponsored levels.
Array keys should be the main account level.
*/
global $pmprosm_sponsored_account_levels;
$pmprosm_sponsored_account_levels = array(
//set 5 seats at checkout
1 => array(
'main_level_id' => 1, //redundant but useful
'sponsored_level_id' => array(2,3), //array or single id
@ideadude
ideadude / my_pmprosm_string_replacement.php
Created January 23, 2018 22:15
Example showing how to replace strings in the PMPro Sponsored Members Add On
/*
Replace strings in the PMPro Sponsored Members Add On
Add this code to a custom plugin.
Note we check for 2 different but similar text domains. We SHOULD
set our text domains to match the slug of the plugin, but in this
case we used underscores instead of dashes and need to support both
for backwards compatability.
The original text must match exactly how it shows up in the code.
@ideadude
ideadude / cache_test.php
Created January 24, 2018 17:36
PHP Script to Use for Testing Server Caching
<?php
$now = date('Y-m-d H:i:s', time())
?>
<html><head><title>Cache Test (<?php echo $now;?>)</title></head>
<body>
<h1>Cache Test</h1>
<p><?php echo 'Time right now: <strong>' . $now . '</strong>'; ?>
</p>
<p>If this doesn't refresh on page load, then something is caching this page.</p>
<p>You can try adding ?t=arandomnumberorstring to the end of the URL to break the cache. You'll see the current time.</p>
@ideadude
ideadude / wp_maybe_disable_pmprobbp_check_forum.php
Last active December 23, 2019 09:30
Only redirect away from single topic and single reply pages in bbPress when running PMPro and PMPro bbPress
/*
Only redirect away from single topic and single reply pages.
Add this code to a custom plugin.
*/
function wp_maybe_disable_pmprobbp_check_forum() {
global $post;
if(function_exists('bbp_is_topic') && !bbp_is_topic($post->ID) && !bbp_is_reply($post->ID)) {
remove_action( 'template_redirect', 'pmprobbp_check_forum' );
remove_filter( 'pmpro_search_filter_post_types', 'pmprobb_pmpro_search_filter_post_types' );
@ideadude
ideadude / cleanup_pmpro_memberships_users.sql
Created February 7, 2018 19:43
Cleanup bad data in the wp_pmpro_memberships_users table of PMPro
#
# PMPro will sometimes get bad data in the wp_pmpro_memberships_users table.
# This happens often during imports and/or when levels are deleted.
# These queries below will search for bad records and inactivate them.
# Run queries (c) and (e) to deactivate the bad records.
# The other queries are for reference.
# IMPORTANT NOTE: If your DB prefix is not wp_, you will have to update it in the queries below
#
# (a) show latest entries in mu
SELECT * FROM wp_pmpro_memberships_users ORDER BY id DESC;
@ideadude
ideadude / init_create_my_administrator_user.php
Created February 13, 2018 17:23
Create a WordPress administrator user account via PHP/FTP.
<?php
/*
Sometimes you have FTP access to a site, but don't have a WP administrator account.
You can use this code to create one.
1. Add this code into any plugin or theme file that you know will be run.
2. Visit /?createmyadministratoruser=1.
3. Delete the code you added.
*/
function init_create_my_administrator_user() {
@ideadude
ideadude / pmpro_checkout_level_initial_payments_once.php
Created February 14, 2018 19:36
Make sure first period discounts set via the initial payment value can only be used once in Paid Memberships Pro
/**
* Make sure first period discounts can only be used once.
*
* If a user already checked out for another level in this group,
* set the initial payment to match the billing amount.
*
* Edit the array of level_ids below and then add this code into a custom plugin.
*/
function pmpro_checkout_level_initial_payments_once($level) {
if( !is_user_logged_in() ) {
@ideadude
ideadude / pmpro_checkout_level_custom_prorating_rules.php
Last active August 15, 2023 14:29
Override the default proration behavior in the PMPro Proration Add On
/*
1. Make sure PMPro and PMPro Proration are both active.
2. Edit the pmpro_checkout_level_custom_prorating_rules function below to your needs.
3. Then add this code into a custom plugin for your site.
*/
/**
* Swap in our custom prorating function.
*/
function init_custom_prorating_rules() {