Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / pmpro_register_helper_depends_field_example.php
Created October 28, 2019 02:49
Example of one RH field depending on another.
<?php
// This code should be placed into context of adding RH fields
// like this: https://www.paidmembershipspro.com/documentation/register-helper-documentation/code-examples/
//define the fields
$fields = array();
$fields[] = new PMProRH_Field(
'budget', // input name, will also be used as meta key
'select', // type of field
array(
@ideadude
ideadude / my_send_pmpro_confirmation_emails_from_dashboard.php
Last active October 24, 2024 15:31
Always send the checkout_free confirmation email in PMPro when changing a user's level in the admin dashboard.
<?php
/**
* Always send the checkout_free confirmation email
* when changing a user's level in the admin dashboard.
*/
function my_send_pmpro_confirmation_emails_from_dashboard( $level_id, $user_id, $cancel_level_id ) {
// If we're not in the dashboard, this is probably a checkout on the frontend
if ( ! is_admin() ) {
return;
}
@ideadude
ideadude / alternative_loadStripeLibrary.php
Created October 9, 2019 20:04
Alternative loadStripeLibrary() method for the Stripe gateway class in PMPro. Used for debugging.
/**
* Alternative loadStripeLibrary() method that will die and output
* the location of the file that previously loaded a different version
* of the Stripe API library.
*
* THIS CODE IS FOR DEBUGGING PURPOSES ONLY
*
* Find the loadStripeLibrary() method of classes/gateways/class.pmprogateway_stripe.php
* and replace with this version. Then attempt to checkout and take note.
*/
@ideadude
ideadude / my_load_pmpro_stripe_library_early.php
Created October 9, 2019 19:08
Load the PMPro Stripe Library Earlier
/**
* Load the PMPro Stripe Library Earlier
* Works with PMPro v2.1+
* Use this if you are experiencing errors like Stripe/PaymentMethod not found
* or other errors that might be caused by another Stripe Library loading earlier.
*
* This is not meant as a final solution.
* With this coded enabled, you may notice other Stripe-related plugins breaking.
* When you find the other plugin that is affecting things, you can see if
* that plugin is needed or if there is an update.
@ideadude
ideadude / my_disable_pmpro_cpt_redirect.php
Created October 3, 2019 14:08
Disable the PMPro CPT redirect for non-members.
/**
* Disable the PMPro CPT redirect for non-members.
* The PMPro the_content filters will still run,
* but might not be adequate to protect some CPTs.
*/
function my_disable_pmpro_cpt_redirect() {
remove_action( 'template_redirect', 'pmprocpt_template_redirect' );
}
add_action( 'init', 'my_disable_pmpro_cpt_redirect' );
@ideadude
ideadude / my_icheck_radio_button_fix.php
Last active July 26, 2019 20:30
Get iCheck checkboxes to work with PMPro Add PayPal Express
/**
* Fix iCheck radio buttons with PMPro Add PayPal Express and other
* tweaks that add radio buttons to checkout.
* Add this code into a snippet or customization plugin.
*/
function my_icheck_radio_button_fix() {
?>
<script>
jQuery(window).load(function() {
//click our radio button when icheck is clicked
@ideadude
ideadude / my_init_override_sponsored_members_pricing_update.php
Last active June 14, 2022 13:00
PMPro Sponsored Members Example with custom callback to override seat pricing.
/**
* Sponsored Members setup with child seat costs and child fields at checkout.
*/
global $pmprosm_sponsored_account_levels;
$pmprosm_sponsored_account_levels = array(
1 => array(
'main_level_id' => 1,
'sponsored_level_id' => 2,
'seat_cost' => 35,
'min_seats' => 1,
@ideadude
ideadude / my_pmproec_after_validate_user.php
Last active April 13, 2021 18:25 — forked from strangerstudios/my_pmproec_after_validate_user.php
Redirect to the membership account page instead of the home page after email validation with the PMPro Email Confirmation add on.
/**
* Redirect to the membership account page instead of the home page after email validation with the PMPro Email Confirmation add on.
* Add this code to a custom WordPress plugin. https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmproec_after_validate_user() {
if( is_user_logged_in() ) {
wp_safe_redirect( '/membership-account/' );
} else {
wp_safe_redirect( wp_login_url( '/membership-account/' ) );
}
@ideadude
ideadude / my_redirect_to_last_post_id.php
Last active January 30, 2020 11:09
On WordPress login, redirect to the last post you were viewing.
/**
* On login, redirect to the last post viewed.
* Add this code into a custom plugin.
* Note that many themes and plugins hook into login_redirect.
* Whichever hook has the highest priority will be the last call
* on where to redirect. The priority below is set to 20.
* Note also that some URLs/pages may note be "posts"
* and may not have an ID we can track.
* Note also that some pages are excluded. You may want to exclude other pages.
* Note also that this may override any specific redirect_to passed in
@ideadude
ideadude / tids_transaction_ids.php
Created June 5, 2019 10:38 — forked from strangerstudios/tids_transaction_ids.php
Show and Search By Payment/Subscription Transaction IDs with Paid Memberships Pro
<?php
/*
Payment/Subscription Transaction IDs Code
Add to your active theme's functions.php or a custom plugin.
*/
//Add Transaction IDs to Members List
function tids_pmpro_memberslist_extra_cols_header($theusers)
{
?>