Skip to content

Instantly share code, notes, and snippets.

View ronalfy's full-sized avatar
🏠
Working from home

Ronald Huereca ronalfy

🏠
Working from home
View GitHub Profile
@ronalfy
ronalfy / pmpro-add-user-capability-only.php
Created March 31, 2020 16:49
Paid Memberships Pro - Add User Capability Only
<?php
/**
* Remove capabilities from membership manager role.
*
* @param array $caps Array of capabilities.
*
* @return array new array of capabilities.
*/
function pmpromm_remove_caps( $caps ) {
$caps = array(
@ronalfy
ronalfy / pmpro-redirect-membership-account.php
Created March 30, 2020 17:46
Paid Memberships Pro - Redirect Membership Account
<?php
function pmpro_redirect_account_page_to_login() {
if ( ! is_user_logged_in() ) {
if ( is_page( 'membership-account' ) ) {
$referer = get_permalink( get_queried_object_id() );
$redirect_url = add_query_arg(
array(
'redirect_to' => $referer,
'reauth' => 1,
),
@ronalfy
ronalfy / pmpro-exclude-post-limit-addon.php
Created March 27, 2020 01:03
Paid Memberships Pro Exclude Post from Limit
<?php
function pmpro_levels_exclude_page() {
if ( is_single( 'hello-world' ) ) {
remove_action( 'wp', 'pmpro_lpv_wp' );
add_filter( 'pmpro_has_membership_access_filter', '__return_true' );
}
}
add_action( 'wp', 'pmpro_levels_exclude_page', 9 );
@ronalfy
ronalfy / pmpro-limit-discount-code-url-logged-in-status.php
Created March 24, 2020 19:00
Paid Memberships Pro - Limit Discount Code by URL and Logged In Status
<?php
function my_pmpro_show_discount_code( $show ) {
if ( empty( $_REQUEST['discount_code'] ) || is_user_logged_in() ) {
$show = false;
}
return $show;
}
add_filter( 'pmpro_show_discount_code', 'my_pmpro_show_discount_code' );
@ronalfy
ronalfy / pmpro-switch-themes-per-level.php
Created March 23, 2020 14:02
Paid Memberships Pro - Switch Theme Per Level
<?php
function pmpro_change_theme_per_level( $theme ) {
if ( ! function_exists( 'pmpro_hasMembershipLevel' ) ) {
return $theme;
}
if ( pmpro_hasMembershipLevel( 1 ) ) {
return 'twentyeleven';
} elseif ( pmpro_hasMembershipLevel( 2 ) ) {
return 'twentyfourteen';
}
@ronalfy
ronalfy / pmpro-add-discount-code-mailchimp-export.php
Last active June 24, 2020 15:52
Paid Memberships Pro - Add Discount Code to MailChimp Export
<?php
/**
* This recipe merges any discount codes that a user has used to the MailChimp export.
*
* 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/
*/
function my_pmpro_mailchimp_listsubscribe_fields( $fields, $user ) {
@ronalfy
ronalfy / pmpro-add-on-learn-dash.php
Last active September 15, 2023 12:26
Paid Memberships Pro - Add On Packages Plus LearnDash
<?php
global $pmpro_addon_pages_for_courses;
// 28 is the page ID; 24 is the course ID.
// 30 is the page ID; 26 is the course ID.
$pmpro_addon_pages_for_courses = array(
28 => 24,
30 => 26,
);
function pmproap_learndash_template_redirect()
{
@ronalfy
ronalfy / pmpro-lock-down-url.php
Last active March 16, 2020 18:44
Paid Membership Pro - Lock Down URL
<?php
/**
* This recipe will redirect non members away from a page
* according to the current URL address
*
* 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/
*/
@ronalfy
ronalfy / pmpro-pending-approval-confirmation-logout.php
Last active March 13, 2020 15:16
Paid Memberships Pro Log Out User After Confirmation Pending Approval
<?php
function pmpro_custom_pages_shortcode_confirmation( $content ) {
if ( is_user_logged_in() ) {
if ( class_exists( 'PMPro_Approvals' ) ) {
global $current_user;
$approval_levels = PMPro_Approvals::getApprovalLevels();
foreach ( $approval_levels as $level ) {
if ( ! PMPro_Approvals::isApproved( $current_user->ID, $level ) ) {
wp_logout();
break;
@ronalfy
ronalfy / pmpro-invite-codes-custom-account-page.php
Created March 12, 2020 15:12
Paid Memberships Pro - Invite Codes On Custom Account Page
<?php
/*
Show an invite code on the account page.
*/
function pmproio_custom_the_content_account_page($content)
{
global $current_user, $pmpro_pages, $post;
// First check if PMPro is active.
if ( ! function_exists( 'pmpro_hasMembershipLevel' ) ) {
return $content;