Skip to content

Instantly share code, notes, and snippets.

View andrewlimaza's full-sized avatar

Andrew Lima andrewlimaza

View GitHub Profile
@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 / keep-pmpro-member-price-manual-renewal.php
Created November 4, 2021 10:33
Keep pre-existing members on their initial checkout price when renewing their membership level.
<?php
/**
* Keep pre-existing members on their initial checkout price when manually renewing. Grandfather 'old' members when their levels pricing changes.
* Note: This is not needed for recurring membership levels and is designed for levels with an expiration date.
*
* 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/
*/
@andrewlimaza
andrewlimaza / add-compatibility-for-sed-and-pmpro-woo.php
Created May 19, 2023 04:56
Add compatibility for PMPro Set Expiration Date Add On and PMPro WooCommerce Add On.
<?php
/**
* Support Set Expiration Date Add On for PMPro WooCommerce Add On.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmprowoo_set_expiration_date( $level_array ) {
// Make sure Set Expiration Date Add On is active.
if ( ! function_exists( 'pmpro_getSetExpirationDate' ) ) {
return $level_array;
@andrewlimaza
andrewlimaza / change-monthly-fee-pmpro.php
Last active April 29, 2024 07:16
Adjust pricing for membership level according to selection of Custom Fields in Paid Memberships Pro.
<?php
/**
* This will allow you to charge additional extras on the user's monthly membership fee.
* Copy the code below into your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
//we have to put everything in a function called on init, so we are sure Register Helper is loaded
function my_pmprorh_init()
{
@andrewlimaza
andrewlimaza / remove-billing-fields-offsite-pmproaffl.php
Last active April 22, 2024 13:27
Remove Billing Fields for Offsite Payment Gateways using the Address For Free Levels Add On. Paid Memberships Pro
<?php
/**
* This code snippet will hide billing fields from certain levels when added using the "Capture Name & Address for Free Levels or for Offsite Gateway"
* Please adjust the level ID's values of the $levels_to_hide array, for which levels you want to hide billing fields from.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_hide_billing_fields_for_levels() {
$levels_to_hide = array(1,3,5); //change level ID's you want to hide billing fields from.
@andrewlimaza
andrewlimaza / sell-series-addon-packages.php
Last active April 22, 2024 12:32
Sell PMPro Series through AddOn Packages
<?php
/**
* Adds the AddOn Package post meta to 'Series' post type.
* Give access if they purchased "Series" parent container.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function add_pmpro_series_to_AP( $types ) {
$types[] = 'pmpro_series';
@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 {