Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@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 / 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 / init_default_pmpro_discount_code.php
Last active November 16, 2020 07:43
Default to the blackfriday discount code if none is set. Paid Memberships Pro
/*
Default to the blackfriday discount code if none is set.
Add this code to a custom plugin.
*/
function init_default_pmpro_discount_code() {
//edit and uncoment this line to limit this to a specific page; note that "is_page" won't work yet
//if(strpos($_SERVER['REQUEST_URI'], '/blackfriday') === false) return;
if(!isset($_REQUEST['discount_code'])) {
$_REQUEST['discount_code'] = 'blackfriday';
@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 / pmpro_modal_checkout.php
Last active November 7, 2022 16:38
Example to add a modal checkout popup to every page with Paid Memberships Pro
<?php
/**
* Define the default level to use for the modal
*/
define('PMPRO_MODAL_CHECKOUT_DEFAULT_LEVEL', 1);
/**
* Load the checkout preheader on every page
* We won't be processing on every page, but we
* want the code that sets up the level and
@ideadude
ideadude / my_pmpro_orders_read_only_fields.php
Created December 26, 2017 17:34
make all fields (including transaction ids) editable on the orders page in the PMPro dashboard
/*
Make all fields (including transaction ids) editable on the orders page in the PMPro dashboard.
Add this code to a custom plugin.
*/
function my_pmpro_orders_read_only_fields($fields)
{
return array();
}
add_filter('pmpro_orders_read_only_fields', 'my_pmpro_orders_read_only_fields');
@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_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 @)