Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / my_bp_activity_filter.php
Created October 12, 2020 20:31
Only let certain members post BuddyPress activity when using PMPro and PMPro BuddyPress.
/**
* Only let certain members post BuddyPress activity.
* This code works with BuddyPress and BuddyBoss.
* This code only filters the main activity page.
* Posting to groups you are a member of still works.
*
* Make sure BuddyPress (or BuddyBoss), PMPro, and PMPro BuddyPress are all active.
* Copy this code into a custom plugin or Code Snippet.
*/
@ideadude
ideadude / pmpro_ad_code.php
Created October 2, 2020 19:43
Some examples of showing AdSense code for certain members only.
<?php
// show ads to non-members and level 3
if( pmpro_hasMembershipLevel( array(0,3) ) ) {
?>
<script>//...</script>
<?php
}
// use the pmpro_displayAds function
// https://www.paidmembershipspro.com/documentation/content-controls/hide-ads/
@ideadude
ideadude / my_update_pmpro_stripe_statement_descriptor.php
Last active November 27, 2023 12:37
Change the statement descriptor for Stripe charges and subscriptions.
<?php
/**
* Change the statement descriptor for Stripe charges and subscriptions.
* This is the message shown on the customer's credit card statement.
* Must contain at least one letter, 22 characters max.
*
* Requires PMPro 2.4.1+
*
* Note: If your descriptor includes invalid characters or
* more than 22 chacters, checkout will fail.
@ideadude
ideadude / my_pmpro_show_cvv.php
Created July 13, 2020 23:31
Remove CVV from the checkout page and don't require it.
<?php
/**
* Remove CVV from the checkout page and don't require it.
*/
// Removes the field from the checkout page.
function my_pmpro_show_cvv( $show ) {
return false;
}
add_filter( 'pmpro_show_cvv', 'my_pmpro_show_cvv' );
@ideadude
ideadude / my_pmpro_member_number_field.php
Last active July 13, 2020 19:15
Add a "member_number" field that only admins can edit using PMPro and Register Helper.
<?php
/**
* Add a "member_number" field that only admins can edit.
* Make sure PMPro and the Register Helper Add On are active.
* Copy this code into a Code Snippet or custom plugin.
*/
function my_pmpro_member_number_field() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
@ideadude
ideadude / shareasale_pmpro_affiliates.html
Created July 13, 2020 18:15
Share a Sale Tracking Code to use with PMPro Affiliates.
<img id='_SHRSL_img_1' src='https://www.shareasale.com/sale.cfm?tracking=!!ORDER_ID!!&amount=!!ORDER_AMOUNT!!&merchantID=XXXXX&transtype=sale' width='1' height='1'>
<script src='https://www.dwin1.com/19038.js' type='text/javascript' defer='defer'></script>
@ideadude
ideadude / pmprorh-init-buddypress-fields.php
Created July 2, 2020 12:14 — forked from pbrocks/pmprorh-init-buddypress-fields.php
Example of defining PMPro Register Helper Fields Synchronized to BuddyPress XProfile Fields
<?php
/**
* Based on the Register Helper example.
* We've added a "buddypress" option for each field
* set to the XProfile name we used when setting up
* the fields in the BuddyPress extended profile.
* If the PMPro BuddyPress Add On is activated
* then the fields will be synchronized.
* Register Helper: https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
* PMPro BuddyPress: https://www.paidmembershipspro.com/add-ons/buddypress-integration/
@ideadude
ideadude / my_pmprowoo_is_purchasable.php
Created July 1, 2020 22:39
Change the default PMPro WooCommerce bahavior and make membership products not purchasable if a user already has any other membership level.
<?php
/**
* Change the default PMPro WooCommerce bahavior
* and make membership products not purchasable
* if a user already has any other membership level.
*/
// First disable the core PMPro WC callaback and set up our own.
function my_pmprowoo_init() {
remove_filter( 'woocommerce_is_purchasable', 'pmprowoo_is_purchasable', 10, 2 );
add_filter( 'woocommerce_is_purchasable', 'my_pmprowoo_is_purchasable', 5, 2 );
@ideadude
ideadude / my_fix_wpelogin.php
Created June 29, 2020 20:40
Make sure to add the wpe-login parameter to the lostpassword URL.
<?php
/**
* Make sure to add the wpe-login parameter to the lostpassword URL.
*/
function my_fix_wpelogin( $url ) {
$url = add_query_arg( 'wpe-login', true, $url );
return $url;
}
add_filter( 'lostpassword_url', 'my_fix_wpelogin' );
@ideadude
ideadude / my_amlbofat_save_function.php
Last active March 27, 2021 00:14
Assign additional membership levels based on fields at checkout.
<?php
/**
* Assign additional membership levels based on fields at checkout.
* Requires PMPro, PMPro MMPU, and PMPro Register Helper.
* This is just an example. Be sure to change the field settings,
* field meta name, and membership levels to fit your needs.
*/
// Add a checkbox via Register Helper
function my_amlbofat_add_fields() {