Skip to content

Instantly share code, notes, and snippets.

View lubyagin's full-sized avatar

Александр lubyagin

View GitHub Profile
@andrewlimaza
andrewlimaza / my-template-redirect-example.php
Last active January 10, 2023 14:03
Redirect non-members to homepage but allow access to PMPro checkout pages.
<?php
/**
* Redirect non-members (including logged-in non-members) away from restricted pages and to home page.
* This allows non-members to access Paid Memberships Pro checkout/levels pages as well as the default WordPress login page.
*
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_redirect_non_members_example() {
global $pmpro_pages;
@andrewlimaza
andrewlimaza / change-membership-level-on-rh-selection.php
Created November 30, 2018 06:17
Change Membership Level Checked Out According to Register Helper Input
<?php
/**
* This will change the user's membership level if the user selects 'lessthan2000' on th custom field.
* Adjust this code to match your needs. Please note that if the initial level checking out is free,
* and you want to assign to a paid level depending on field selected, you may need to adjust the new level's price to $0 or ensure both levels are free or paid.
*
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmprorh_init()
@andrewlimaza
andrewlimaza / pmpro-series-all-access.php
Created November 23, 2018 09:31
Give access to specific membership level for PMPro Series posts.
<?php
/**
* Give "All Access" to PMPro Series for specific membership level.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function open_series_to_specific_level($hasaccess, $thepost, $theuser, $post_membership_levels) {
// Bail if the user already has access to a post/page.
if ( $hasaccess ) {
@andrewlimaza
andrewlimaza / hide-free-levels-for-members.php
Last active April 6, 2021 22:08
hide free level from members and premium level from non-members.
<?php
// Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
function adjusting_the_pmpro_levels_array( $levels ) {
if( !pmpro_hasMembershipLevel() ) {
unset( $levels[1] ); // hide premium level for non-members.
}else{
unset( $levels[2] ); // hide free level for members.
@andrewlimaza
andrewlimaza / redirect-members-from-page-pmpro.php
Last active June 11, 2020 20:15
redirect members away from a specific page for PMPro.
<?php
/**
* This will redirect members from Page A to Page B. Non-members will be able to access Page A.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_template_redirect_members() {
if ( is_page('join') && pmpro_hasMembershipLevel() ) {
wp_redirect(home_url( '/my-page-slug' ) );
exit;
}
@andrewlimaza
andrewlimaza / pmpro-level-register-example.php
Last active April 12, 2023 23:22
Give user default membership level when registering
<?php
// Adjusted from https://www.paidmembershipspro.com/give-users-a-default-membership-level-at-registration/
//Disables the pmpro redirect to levels page when user tries to register
add_filter("pmpro_login_redirect", "__return_false");
function my_pmpro_default_registration_level($user_id) {
$level = pmpro_getLevel( 2 );
@andrewlimaza
andrewlimaza / register-helper.php
Created October 29, 2018 08:29
Register Helper Example For Paid Memberships Pro.
<?php
/**
* Copy this code (below) into your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmprorh_init()
{
//don't break if Register Helper is not loaded
if(!function_exists( 'pmprorh_add_registration_field' )) {
return false;
@andrewlimaza
andrewlimaza / my_pmpro_pre_handle_404.php
Created September 4, 2018 14:34 — forked from strangerstudios/my_pmpro_pre_handle_404.php
If we 404, and the slug matches a pmpro discount code, redirect
/*
If we 404, and the slug matches a discount code, redirect
Add this code to a custom plugin
*/
function my_pmpro_pre_handle_404($preempt, $wp_query) {
global $wpdb;
//bail if PMPro is not installed
if(empty($wpdb->pmpro_discount_codes_levels))
@andrewlimaza
andrewlimaza / my-show-user-enddate.php
Last active March 23, 2021 08:02
Custom shortcode to show member expiration dates or recurring.
<?php
/**
* Show the user's expiration date, or their next payment date.
* Show the user's previously expired date if they were cancelled, expired or cancelled by an admin.
* If none of thhe above is found, the string 'nothing found' will be returned.
*/
function my_show_user_enddate(){
if ( is_user_logged_in() && function_exists( 'pmpro_hasMembershipLevel' ) && pmpro_hasMembershipLevel() ){
@andrewlimaza
andrewlimaza / hide-logo-and-footer-on-wp-pages.php
Created August 30, 2018 09:24
Hide logo and footer from certain pages from WordPress.