Skip to content

Instantly share code, notes, and snippets.

View andrewlimaza's full-sized avatar

Andrew Lima andrewlimaza

View GitHub Profile
@andrewlimaza
andrewlimaza / load-legacy-pmpro-content-message.php
Last active July 19, 2024 13:46
Add the option to load legacy content message.
<?php
/**
* Run this code _once_ and then remove it from your site. To run this code visit any page of the admin area.
* After visiting any admin page, you may delete this script from your site.
* This will add legacy logic to the content message for non-members.
*/
function my_pmpro_legacy_content_message() {
// Only logged-in admins can run this.
if ( ! current_user_can( 'manage_options' ) || ! empty( get_option( 'pmpro_nonmembertext' ) ) ) {
return;
@andrewlimaza
andrewlimaza / pmpro-give-access-to-posts-override-membership-restriction.php
Created May 8, 2024 07:40
Give non-members or visitors access to posts/shortcodes/blocks for specific post ID's
<?php
/**
* Bypasses all content restriction for posts, pages, blocks and shortcodes that are on certain pages.
* Tweak this code further for your needs.
* To add this code to your site, please follow this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_allowed_posts() {
$open_post_ids = array( 118 ); // Add all the POST ID's that you want to bypass here.
return $open_post_ids;
@andrewlimaza
andrewlimaza / pmpro-variable-pricing-recurring-text.php
Created May 8, 2024 01:51
Adjust Variable Pricing Add On Text for recurring levels.
<?php
/**
* Add recurring text after Variable Pricing text.
* Tweak the wording for your needs.
*
* To add this code to your site please visit - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_vp_text_adjustment( $text ) {
$level = pmpro_getLevelAtCheckout();
@andrewlimaza
andrewlimaza / pmpro-redirect-login-special.php
Created April 22, 2024 07:40
Redirect to a default page, unless redirecting to content [Paid Memberships Pro]
<?php
/**
* Redirect to a default "members" page unless redirecting back to referrer.
* Adjust the URLS for $skip_redirects which it bypasses.
*
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_login_redirect_url( $redirect_to, $request, $user ) {
// Skip certain redirect_tos always
$skip_redirects = array(
@andrewlimaza
andrewlimaza / change-wp-login-in-email.php
Created April 16, 2024 06:53
Replace wp-login.php in WordPress emails to a custom login page via it's slug/permalink.
<?php
/**
* Replace wp-login.php with a custom slug in all WordPress emails where it's generated.
* Add this code to a custom plugin or a child theme's functions.php
*/
function my_replace_wp_login_in_emails($args) {
// Check if the message contains 'wp-login.php'
if (strpos($args['message'], 'wp-login.php') !== false) {
// Replace 'wp-login.php' with 'my-login'
$args['message'] = str_replace('wp-login.php', 'my-login', $args['message']); // change my-login to the slug of your choice
@andrewlimaza
andrewlimaza / enqueue-print-css-pmpro-theme-or-plugin.php
Created April 9, 2024 12:55
Enqueue custom print.css file for Paid Memberships Pro.
<?php
/**
* If anyone created a custom print.css file, add this code to a custom plugin to re-enqueue it in your theme or template directory.
*/
function my_enqueue_print_style() {
if ( file_exists( get_stylesheet_directory() . '/paid-memberships-pro/css/print.css' ) ) {
$print_css = get_stylesheet_directory_uri() . '/paid-memberships-pro/css/print.css';
} elseif ( file_exists( get_template_directory() . '/paid-memberships-pro/print.css' ) ) {
$print_css = get_template_directory_uri() . '/paid-memberships-pro/print.css';
} else {
@andrewlimaza
andrewlimaza / pmpro-customizations.php
Created March 22, 2024 08:24 — forked from indigetal/pmpro-spacesengine.php
Monetize SpacesEngine using Paid Memberships Pro and Selection of Addons. See link to accompanying tutorial in comments.
<?php
/*
Plugin Name: PMPro SpacesEngine Integration
Plugin URI: https://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: Customizations for integrating Paid Memberships Pro with SpacesEngine
Version: 1.0
Author: Brandon Meyer
Author URI: https://collabanthnetwork.org
*/
@andrewlimaza
andrewlimaza / pmpro-approvals-added-to-members-list.php
Created March 20, 2024 14:02
Add approval status to members list of Paid Memberships Pro
<?php
/**
* Adds approval status column to the members list.
*
* @param [type] $columns
* @return void
*/
function my_pmpro_add_memberslist_col_approval( $columns ) {
$columns['approval'] = 'Approval Status';
return $columns;
@andrewlimaza
andrewlimaza / pmpro-non-approved-members-discount.php
Created March 20, 2024 09:58
PMPro remove discount for non-approved members and Woo
<?php
/**
* Adjust the Woo membership discount only if the member is approved.
* This won't discount for pending or denied members.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmprowoo_price_adjust_approvals( $discount_price, $lowest_price_level, $price, $product ) {
if ( ! class_exists( 'PMPro_Approvals' ) ) {
return $discount_price;
}
@andrewlimaza
andrewlimaza / pmpro-redirect-logged-in-people.php
Created March 18, 2024 13:48
Redirect logged-in people away from the login page of PMPro.
<?php
/**
* Redirect logged-in users away from the login page if already logged-in.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_login_page_redirect() {
global $pmpro_pages;
if ( is_page( $pmpro_pages['login'] ) && is_user_logged_in() ) {
wp_redirect( home_url( '/page-slug/' ) );