Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / my_pmpro_pages_custom_template_path.php
Last active April 3, 2021 04:07
Tell PMPro to look for templates in this plugin's templates/ folder.
<?php
/**
* Tell PMPro to look for templates in this plugin's templates/ folder.
*/
function my_pmpro_pages_custom_template_path( $templates, $page_name ) {
$templates[] = plugin_dir_path(__FILE__) . 'templates/' . $page_name . '.php';
return $templates;
}
add_filter( 'pmpro_pages_custom_template_path', 'my_pmpro_pages_custom_template_path', 10, 2 );
@ideadude
ideadude / pmpro_set_enddates.sql
Created December 2, 2019 05:38
Set an enddate for active subscriptions with PMPro
# BACKUP FIRST
# This SQL query will set the expiration date
# to 2020-01-01 for any active membership with
# a different current enddate.
# BACKUP FIRST
UPDATE wp_pmpro_memberships_users
SET enddate = '2020-01-01 00:00:00'
WHERE status = 'active'
AND enddate IS NOT NULL
AND enddate <> '0000-00-00 00:00:00'
@ideadude
ideadude / my_init_membership_level_translate.php
Last active November 3, 2021 13:55 — forked from strangerstudios/my_init_membership_level_translate.php
Translate Membership Level Names and Descriptions with Paid Memberships Pro
<?php
/*
* Filter membership level names and descriptions for translating.
*
* Add this code to a custom plugin or your active theme's functions.php file.
* Be sure to update the $pmpro_translated_levels array. Add a sub array for each locale.
* The sub array keys should be the membership level ids,
* and values should be an array with the name and description to translate to.
*
*/
@ideadude
ideadude / my_pmprodon_donation_notes.php
Created November 21, 2019 18:28
Donation notes field example for PMPro Donations.
<?php
/**
* Donation notes.
* Edit the copy below.
* Add to a custom plugin.
* Notes are saved into the notes field of the order.
*/
// show the notes field at checkout.
function my_pmprodon_donation_notes() {
global $pmpro_level;
@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