Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / pmpro_level_cost_text_filter_pricing_page.php
Created November 6, 2017 09:50
Update prices on the pricing page for current members with Paid Memberships Pro.
/*
Update Prices on the Pricing page for current members.
Add this code to a custom plugin.
*/
function pmpro_level_cost_text_filter_pricing_page($cost, $level, $tags, $short) {
//if we're not on the pricing page, just return
global $pmpro_pages;
if(!is_page($pmpro_pages['levels']))
return $cost;
@ideadude
ideadude / pmpro_confirmation_url_to_upsell.php
Last active November 15, 2017 06:57
Redirect the Paid Memberships Pro confirmation to a page for a specific upsell unless the user already has that level.
<?php
/*
Redirect to a URL promoting an upsell unless the user already has that level.
Add this code into a custom plugin.
*/
function pmpro_confirmation_url_to_upsell($rurl, $user_id, $pmpro_level) {
$upsell_level_id = 2; //change this
$upsell_url = 'https://example.com/upsell-page/'; //change this
@ideadude
ideadude / my_pmpro_pre_handle_404.php
Last active November 22, 2017 13:05 — forked from strangerstudios/my_pmpro_pre_handle_404.php
If we 404, and the slug matches a pmpro discount code, redirect
/*
If we 404, and the slug matches a discount code, redirect
Add this code to a custom plugin
*/
function my_pmpro_pre_handle_404($preempt, $wp_query) {
global $wpdb;
//make sure we're 404ing
if(!is_404())
@ideadude
ideadude / test_mark_code_posts_for_gpl.php
Created December 3, 2017 19:00
If a post has a code block, add a GPL note to the bottom of the post. (For Gutenberg issue #3773)
/**
* If a post has a code block, add a GPL note to the bottom of the post.
* This gist is meant to be run with the pull requests related to this
* issue on the Gutenberg GitHub repo: https://github.com/WordPress/gutenberg/issues/3773
*/
function test_mark_code_posts_for_gpl($content) {
if(gutenberg_content_has_block($content, 'core/code'))
$content .= '<p><strong>All code in this post is licensed under the GPL.</p>';
return $content;
@ideadude
ideadude / update_wp_pmpro_membership_orders.sql
Created December 26, 2017 17:44
Example of using SQL to edit a PMPro Order
#set order 1 to have user_id 1. change the order and user ids.
UPDATE wp_pmpro_membership_orders SET user_id = '1', status = 'success' WHERE id = 1 LIMIT 1;
@ideadude
ideadude / bbpress_role_is_iu_post_user_import.php
Created December 26, 2017 22:01
Set a user's bbpress role when importing using the Import Users From CSV Plugin
/*
Add this code to a custom plugin.
*/
function bbpress_role_is_iu_post_user_import( $user_id ) {
//if you had a column in your import with the role in it, you can grab it from user meta instead of setting it here
$new_role_forum_role='bbp_participant';
bbp_set_user_role( $user_id, $new_role_forum_role );
}
add_action( 'is_iu_post_user_import', 'bbpress_role_is_iu_post_user_import');
@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_registration_checks_no_email_user_login.php
Created December 29, 2017 22:10
Stop users from setting their username to an email address with Paid Memberships Pro
/*
Stop users from setting their username to an email address
Add this code to a custom plugin.
*/
function pmpro_registration_checks_no_email_user_login($continue) {
//if there are earlier problems, don't bother checking
if(!$continue)
return;
//make sure the username passed in doesn't look like an email address (contains a @)
@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>