Skip to content

Instantly share code, notes, and snippets.

@messica
messica / my_pmpro_bp_approvals_directory_init.php
Last active May 13, 2020 11:41
Hide pending/denied members from BuddyPress member directory.
<?php
// Exclude pending and denied members from BuddyPress directory.
function my_pmpro_bp_bp_pre_user_query_construct( $query_array ) {
// Only apply this to the directory.
if ( 'members' != bp_current_component() ) {
return;
}
@messica
messica / my_pmpro_paypal_level_description.php
Last active July 1, 2019 16:35
Change to change PayPal order description to "billing_name - level_name".
<?php
/**
* Change PayPal order description to "billing_name - level_name".
*/
function my_pmpro_paypal_level_description( $description, $level_name, $order, $site_name ) {
// Get name from billing address.
$name = $order->billing->name;
$description = "{$name} - {$level_name}";
@messica
messica / my_pmpro_registration_checks.php
Created June 28, 2019 23:30
Don't allow renewal for same level if user has an active subscription.
<?php
/**
* Don't allow renewal for same level if user has an active subscription.
*/
// Hide the Renew link.
function hide_renewal_links_for_some_levels($r, $level) {
// Get user's last order.
@messica
messica / hide_old_posts_from_members.php
Last active June 18, 2019 21:04 — forked from strangerstudios/hide_old_posts_from_members.php
Paid Memberships Pro: Hide Old Posts From New Members except specific categories.
<?php
/**
* Hide old posts from new members, except for specific categories.
*/
add_filter( 'pmpro_has_membership_access_filter', 'hide_old_posts_from_members', 10, 4 );
function hide_old_posts_from_members( $hasaccess, $thepost, $theuser, $post_membership_levels ) {
global $wpdb;
// if PMPro says false already, return false
@messica
messica / my_http_api_debug.php
Last active June 18, 2019 02:23
Save PayPal payer email in usermeta.
<?php
/**
* Save PayPal payer email in usermeta.
*/
function my_http_api_debug( $response, $context, $class, $r, $url ) {
global $current_user;
// Only continue for PayPal requests.
@messica
messica / pmpro_remove_trial_for_existing_members.php
Created June 14, 2019 00:30
Remove trial if user has cancelled order for same level.
<?php
/**
* Remove trial if user has cancelled order for same level.
* Add code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function pmpro_remove_trial_for_existing_members( $level ) {
$order = new MemberOrder();
if ( $order->getLastMemberOrder( null, 'cancelled', $level->id ) ) {
$level->trial_limit = 0;
@messica
messica / my_pmpro_member_directory_sql.php
Created May 31, 2019 19:03
Search member directory for custom user meta passed in via query parameters.
<?php
/*
* Search member directory for custom user meta passed in via query parameters.
*
* (e.g. www.example.com/directory?company=abc+company)
*/
function my_pmpro_member_directory_sql( $sqlQuery ) {
// usermeta key to search.
@messica
messica / pay-by-check-no-access.php
Last active May 31, 2019 15:53 — forked from LMNTL/pay-by-check-no-access.php
Force user's with pending orders from Pay By Check Add On and PMPro to not have access to any member content.
<?php
/**
* This checks to see if the user has a 'pending' check order and will deny access whever member content is called.
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function pmpro_deny_if_user_is_pending( $hasaccess, $post, $user, $levels ) {
// Only continue if post or page already requires access.
if ( empty( $levels ) ) {
return $hasaccess;
@messica
messica / my_pmpro_checkout_level.php
Created May 28, 2019 18:11
Don't apply set expiration date if renewing.
<?php
// Don't apply set expiration date if renewing.
function my_pmpro_checkout_level( $checkout_level ) {
// Get current level.
$user_level = pmpro_getMembershipLevelForUser();
if ( ! empty( $user_level ) && $user_level->id == $checkout_level->id ) {
// Remove Set Expiration Date filters.
remove_filter("pmpro_checkout_level", "pmprosed_pmpro_checkout_level");
remove_filter('pmpro_discount_code_level', 'pmprosed_pmpro_checkout_level', 10, 2);
@messica
messica / my_pmpro_checkout_level.php
Created May 23, 2019 18:12
Prorate initial payment based on subscription delay.
<?php
/**
* Prorate initial payment based on subscription delay.
*
* Requires Subscription Delay and Proration Add Ons.
*/
function my_pmpro_checkout_level( $level ) {
// Only continue if Subscription Delays and Proration Add Ons are activated.