This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Some example code of how to create a PMPro membership level. | |
* Uses the PMPro_Membership_Level class and save() method. | |
*/ | |
// Copy a level. | |
$level = new PMPro_Membership_Level( 1 ); // Pass the ID of the level to copy. | |
$level->id = $level->ID = null; // Clear out the ID, triggers insert on save. | |
$level->name = 'NewName'; // Update any property you want. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT p.ID | |
FROM wp_posts p | |
LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id | |
AND pm.meta_key = '_thumbnail_id' | |
WHERE p.post_type = 'attachment' | |
AND post_status = 'publish' | |
AND pm.meta_id IS NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* This will add billing fields to Add Member and the user's profile page. | |
*/ | |
function add_billing_fields_to_add_member_profile() { | |
//check for register helper | |
if(!function_exists("pmpro_add_user_field")) // pmprorh_add_registration_field | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Update a PMPro User Field with Code. | |
* Requires PMPro 2.9.3+ | |
*/ | |
function my_update_location_options( $field ) { | |
global $pmpro_countries; | |
// This filter runs early, so need to load this. | |
require_once( PMPRO_DIR . '/includes/countries.php' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Update a PMPro User Field with Code. | |
* We find the home_country field and update the options. | |
* User fields are loaded into the pmpro_user_fields globals | |
* during the init hook, priority 1. So we just need to run after that. | |
*/ | |
function my_update_location_options() { | |
global $pmpro_user_fields, $pmpro_countries; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* If a user was approved for any other level, consider them approved for every level. | |
* Requires the PMPro Approval Process for Membership Add On - https://www.paidmembershipspro.com/add-ons/approval-process-membership/ | |
* Must be using PMPro Approvals version 1.4.2 or higher. | |
* Add this code to your site following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_approve_user_if_already_approved( $approved, $user_id, $level_id, $user_approval ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* We can use the pmpro_membership_content_filter filter in | |
* the pmpro_membership_content_filter() function to debug | |
* and see what the $content and $hasaccess vars are set to | |
* at the time of running. | |
* | |
* IMPORTANT: This code will effectively break your site with | |
* the debug info. Only use this for a moment, then deactivate it. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This gist updates the "cancel all memberships" link on the cancel page | |
* to pass the level ids into the page instead of "all". | |
* This will ensure that all the levels are cancelled one by one. | |
* In addition to sending a separate email for each cancellation, | |
* this also ensures the $old_level parameter is sent to the | |
* pmpro_cancelMembershipLevel() function so Add Ons like the | |
* Cancel on Next Payment Date one continue to work. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Prevent non-members from adding member products to their cart. | |
* This requires the PMPro CPT Add On be installed and | |
* each product should be checked for which levels are required. | |
*/ | |
function my_keep_members_only_products_out_of_carts( $is_purchasable, $product ) { | |
// Not purchasable for some other reason. | |
if( ! $is_purchasable ) { | |
return $is_purchasable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Also hide members-only "products" CPT from archives. | |
* You must use the PMPro CPT Add On and then check a produc to require membership. | |
* And also set the "Filter searches and archives?" option to Yes in the PMPro advanced settings. | |
*/ | |
function my_hide_members_only_products_from_archives( $post_types ) { | |
if ( ! in_array( 'product', $post_types ) ) { | |
$post_types[] = 'product'; | |
} |