Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
andrewlimaza / redirect-non-members-to-content-restricted.php
Last active Jun 9, 2020
Redirect non-members to 'Content Restricted' BuddyPress page for normal content.
View redirect-non-members-to-content-restricted.php
<?php
/**
* Redirect non-members away from 'normal' content to BuddyPress content restricted page.
* Requires the BuddyPress Integration to be installed - https://www.paidmembershipspro.com/add-ons/buddypress-integration/
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_template_redirect_require_membership_access() {
if ( ! pmpro_has_membership_access() && ! bp_current_component() && ! is_archive() && ! is_home() && function_exists( 'pmpro_bp_redirect_to_access_required_page' ) ) {
pmpro_bp_redirect_to_access_required_page();
@andrewlimaza
andrewlimaza / auto-populate-cf7-pmpro-members.php
Created Mar 8, 2019
Auto-populate Contact Form 7 select field with active member names [Paid Memberships Pro]
View auto-populate-cf7-pmpro-members.php
<?php
/**
* Auto-populate user names for active members in a field drop-down.
* This will assume you are using a select field named "membership-list"
* The value of the select is the user's email and the label is set to the user's login name.
* Data Example: <option value="someemail@test.com">Test User</option>
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_auto_populate_members ( $tag, $unused ) {
@andrewlimaza
andrewlimaza / dont-apply-level-for-members-woo.php
Last active Jul 2, 2019
Stop users from changing membership level on checkout on WooCommerce
View dont-apply-level-for-members-woo.php
<?php
/**
* Stop existing members from changing levels when purchasing a product on WooCommerce.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function woo_dont_apply_level_for_existing_members() {
if ( pmpro_hasMembershipLevel( '1' ) ) {
remove_action( 'woocommerce_order_status_completed', 'pmprowoo_add_membership_from_order' );
@andrewlimaza
andrewlimaza / hide-sidebar-from-member.php
Created Dec 11, 2018
Remove custom sidebar based on membership level.
View hide-sidebar-from-member.php
<?php
/**
* Remove custom sidebar based on user's membership level.
* Add this code to your PMPro Customizations Plugin -
*/
function my_pmpro_hide_sidebar_from_members(){
if ( ! pmpro_hasMembershipLevel( 1 ) ) {
unregister_sidebar( 'my-sidebar-id' );
}
@andrewlimaza
andrewlimaza / load-custom-css-level-pmpro.php
Created Oct 19, 2018
Load custom CSS for Membership Checkout for specific level - Paid Memberships Pro
View load-custom-css-level-pmpro.php
<?php
/**
* Load custom CSS on checkoutpage for specific membership level in Paid Memberships Pro.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function load_css_for_level_checkout(){
global $pmpro_pages;
@ideadude
ideadude / autocomplete_virtual_orders.php
Created Aug 17, 2018
Autocomplete WooCommerce orders with only virtual products.
View autocomplete_virtual_orders.php
/**
* Autocomplete orders with only virtual products.
* From the 2nd edition of Building Web Apps with WordPress
* https://bwawwp.org
*/
function autocomplete_virtual_orders($order_id) {
//get the existing order
$order = new WC_Order($order_id);
//assume we will autocomplete
@andrewlimaza
andrewlimaza / redirect-member-away-from-page.php
Created Aug 6, 2018
redirect user away from the page if they do not have a specific membership level.
View redirect-member-away-from-page.php
<?php
/**
* This will redirect members with level 1 from site.com/page-slug to the home page.
* Please adjust accordingly and add to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function redirect_member_from_page_x() {
if ( is_page( 'page-slug' ) && pmpro_hasMembershipLevel( 1 ) ) {
wp_redirect( home_url() ); //redirect to home page. Change home_url() to home_url( '/page-slug' ) to redirect to specific page.
@andrewlimaza
andrewlimaza / show-renewal-link-on-30-days-or-less.php
Last active Jul 1, 2019
Change when to show the renewal link on Paid Memberships Pro account page.
View show-renewal-link-on-30-days-or-less.php
@ideadude
ideadude / my_pmprorh_init_buddypress_fields.php
Created Jun 29, 2018
Example of defining PMPro Register Helper Fields Synchronized to BuddyPress XProfile Fields
View my_pmprorh_init_buddypress_fields.php
/**
* Based on the Register Helper example.
* We've added a "buddypress" option for each field
* set to the XProfile name we used when setting up
* the fields in the BuddyPress extended profile.
* If the PMPro BuddyPress Add On is activated
* then the fields will be synchronized.
* Register Helper: https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
* PMPro BuddyPress: https://www.paidmembershipspro.com/add-ons/buddypress-integration/
*/
@andrewlimaza
andrewlimaza / set-membership-based-on-variation-product.php
Last active Jun 30, 2019
Assign membership level based on variation product purchase.
View set-membership-based-on-variation-product.php
<?php
/**
* Assign a membership level based on product ID variation purchase.
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function add_membership_for_variation_pricing( $order_id ) {
global $wpdb, $pmprowoo_product_levels;
// quitely exit if PMPro isn't active