Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / my_add_select_all_levels.php
Created July 15, 2021 18:30
Add "select all" option inside the PMPro Require Membership box
<?php
/**
* Add "select all" option inside the Require Membership box
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_add_select_all_levels() {
?>
@ideadude
ideadude / pmpro_courses_show_course_content_to_nonmembers.php
Created July 5, 2021 20:35
Hide course content from non-members when using the default module of PMPro Courses.
/**
* Hide course content from non-members.
* By default, PMPro Courses allows non-members to see the "content" of a course.
* Lessons are still hidden. By setting this filter to false, non-members will
* see the restricted view on the single course page.
*/
add_filter( 'pmpro_courses_show_course_content_to_nonmembers', '__return_false' );
@ideadude
ideadude / my_pmpro_checkout_level.php
Last active December 5, 2021 13:07 — forked from strangerstudios/my_pmpro_checkout_level.php
Increase price at checkout if a certain value (e.g. added via PMPro Register Helper) is set.
<?php
/**
* If a user checked option1, then add $100 to the price.
*/
function my_pmpro_checkout_level($level) {
if( ! empty( $_REQUEST['option1'] ) || ! empty( $_SESSION['option1'] ) ) {
$level->initial_payment = $level->initial_payment + 100;
//$level->billing_amount = $level->billing_amount + 100; //to update recurring payments too
}
@ideadude
ideadude / my_get_rh_option_label.php
Created April 5, 2021 19:24
Look up the label of an option for a PMPro Register Helper field.
<?php
/**
* Look up the label of an option for a Register Helper field.
* @param $field_name The name of the field (user meta key)
* @param $option_key The key of the option in the fields options array.
* @returns The label for the field or "N/A" if none found.
*/
function my_get_rh_option_label( $field_name, $option_key ) {
global $pmprorh_registration_fields;
@ideadude
ideadude / my_sort_bp_members_list.php
Created April 5, 2021 15:24
Sort BuddyPress members by PMPro membership level.
/**
* Sort BuddyPress members by PMPro membership level.
* Add this code as a code snippet or in a custom plugin.
* https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/
*/
function my_sort_bp_members_list( $query ) {
global $wpdb;
$query->uid_clauses['select'] .= " LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.user_id = mu.user_id AND mu.status = 'active' ";
$query->uid_clauses['orderby'] = str_replace( 'ORDER BY', 'ORDER BY mu.membership_id DESC, ', $query->uid_clauses['orderby'] );
}
@ideadude
ideadude / my_fix_billing_amount.php
Created April 2, 2021 17:21
Fix the billing amount shown on a user's account with Paid Memberships Pro
<?php
/**
* Change the billing amount and cycle number/period for a user's active membership.
* This is useful if the number is out of alignment with the gateway.
* Change the variables under "change this stuff"
* Then visit /wp-admin/?my_fix_billing_amount=1 as an admin.
* Deactivate this snippet after running.
*/
function my_fix_billing_amount() {
global $wpdb;
@ideadude
ideadude / my_keep_free_members_in_old_members_list.php
Created March 30, 2021 20:29
Keep "old" members who expired or cancelled in the old members lists even if they have a free level now. Paid Memberships Pro.
<?php
/**
* When PMPro users cancel or expire, they are shown on the
* cancelled, expired, and "old" members lists.
* However, if an old user is given a default/free level later,
* then they are not considered old, cancelled, or expired anymore.
*
* You may still want to see those users on the old users lists
* so you can follow up to get them back into paid accounts.
* This code does that.
@ideadude
ideadude / pmpro_roles_exclude_other_pmpro_roles.php
Created March 23, 2021 15:02
Allow admins to set multiple PMPro level roles to one level when using PMPro and the PMPro Roles Add On.
add_filter( 'pmpro_roles_exclude_other_pmpro_roles', '__return_false' );
@ideadude
ideadude / my_pmpro_email_confirmation_text.php
Created March 23, 2021 14:04
Change the confirmation text when using PMPro and the Email Confirmation Add On.
/**
* Change the "IMPORTANT!" confirmation text when using PMPro and the Email Confirmation Add On.
* Add this code into a custom plugin or code snippet.
* Be sure to change the translated lines below to the language and words you want.
* https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/
*/
function my_pmpro_email_confirmation_text( $translated_text, $text, $domain ) {
// Ignore strings for other plugins.
if ( $domain != 'pmpro-email-confirmation' ) {
return $translated_text;
@ideadude
ideadude / my_pmpro_page_templates.php
Created March 22, 2021 19:20
Load your own templates for Paid Memberships Pro using a custom plugin.
/**
* Include this code in your custom WordPress plugin
* to load your own versions of the PMPro page templates.
* To override the cancel.php template, place your own
* cancel.php template in a folder like this:
* ../plugins/yourpluginslug/templates/cancel.php
*
* Using priority 100 will make sure this runs after
* other code using the smae hook. For example,
* it will run later than the Reason for Cancelling Add On