Skip to content

Instantly share code, notes, and snippets.

View pbrocks's full-sized avatar

Paul Barthmaier pbrocks

View GitHub Profile
@pbrocks
pbrocks / pmpro-upon-expiration-change-membership-levels.php
Created August 4, 2018 03:37
Determine member's previous level and assign them a new level upon cancellation
<?php
/**
* After expiration, assign them a specific "cancelled" level.
*
* Can be used to downgrade someone to a free level when they cancel.
* Will allow members to the "cancel level" to cancel from that though.
*/
function pmpro_upon_expiration_change_membership_levels( $level_id, $user_id ) {
// set this to the id of the level you want to give members when they cancel
$last_level_5 = 5;
@pbrocks
pbrocks / open-new-posts-to-non-members.php
Last active August 3, 2018 03:01 — forked from strangerstudios/open_new_posts_to_non_members.php
PMPro Customizations to allow non-members to view restricted posts if they are less than 30 days old.
<?php // do not include this line
/**
* Allow non-members to view restricted posts if they are less than 30 days old.
*
* Add this code to a custom plugin.
*
* Change the '-30 Days' below if you'd like to allow access for longer or shorter.
*/
/**
* [open_new_posts_to_non_members description]
@pbrocks
pbrocks / pmpro-after-expiration-change-membership-levels.php
Created August 3, 2018 02:34
Change PMPro membership level upon expiration or cancellation to different respective levels based on member's previous level.
<?php
/**
* When users cancel (are changed to membership level 0) we give them another "cancelled" level.
* Can be used to downgrade someone to a free level when they cancel.
* Will allow members to the "cancel level" to cancel from that though.
*/
function pmpro_after_expiration_change_membership_levels( $level_id, $user_id ) {
// set this to the id of the level you want to give members when they cancel
$last_level_5 = 5;
$last_level_6 = 6;
@pbrocks
pbrocks / pmpro-cancelled-level.php
Last active March 10, 2022 18:36 — forked from strangerstudios/pmpro_cancelled_level.php
Move PMPro members to another level when they cancel.
<?php
/**
* By default cancelled members are changed to level 0. This recipe changes that behavior to give them a "cancelled" level that
* you have created for that purpose. Can be used to downgrade someone to a free level if they cancel.
*/
/**
* [pmpro_after_change_membership_level_default_level description]
*
* @param [type] $level_id [description]
* @param [type] $user_id [description]
@pbrocks
pbrocks / pmpro-email-templates-in-customizations-plugin.php
Last active August 2, 2018 13:27
Paid Memberships Pro allows for custom functionality to be added to the email templates add on by checking for templates in other places. This recipe adds a path to your custom plugin and alerts PMPro to check for the folder you've created in your plugin.
<?php
/**
* Create a folder in your Customizations plugin called 'email'.
* Alert PMPro to check the folder in this plugin for PMPro email templates.
*
* Custom Function to create a new path for PMPro to check for email templates.
*
* @param array $default_templates Pull in existing email templates
*
* @return array Return the list which now includes yours
@pbrocks
pbrocks / pmpro-set-default-country.php
Created August 1, 2018 20:12
Set the default country to United Kingdom/Great Britain using the GB abbreviation. States will be from the GB list. Rename State with a gettext filter.
<?php
/**
* [gettext_pmpro_checkout_city_state_postcode description]
*
* @param [type] $translated_text [description]
* @param [type] $original_text [description]
* @param [type] $domain [description]
*
* @return [type] [description]
*/
@pbrocks
pbrocks / existing code to git repo
Created July 20, 2018 19:03 — forked from zenideas/existing code to git repo
Adding existing source to remote git repo
If you've got local source code you want to add to a new remote new git repository without 'cloning' the remote first, do the following (I often do this - you create your remote empty repository in bitbucket/github, then push up your source)
1. Create the remote repository, and get the URL such as git://github.com/youruser/somename.git
2. If your local GIT repo is already set up, skips steps 2 and 3
3. Locally, at the root directory of your source, git init
4. Locally, add and commit what you want in your initial repo (for everything,
git add .
@pbrocks
pbrocks / show-pmpro-address-fields-on-profile.php
Last active April 13, 2021 18:41 — forked from ideadude/show_pmpro_address_fields_on_edit_profile.php
Use PMPro Register Helper to add PMPro Billing Address fields to the edit user page for admins.
<?php
/**
* Use PMPro Register Helper to add PMPro Billing Address fields to the edit user page for admins.
*/
/**
* show_pmpro_address_fields_on_edit_profile Grabs the values from the billing fields which get filled in during checkout and displays on User Profile.
*
* @return array Array of Register Helper field objects
*/
function show_pmpro_address_fields_on_edit_profile() {
@pbrocks
pbrocks / pmprorh-init-buddypress-fields.php
Last active May 9, 2023 10:49 — forked from ideadude/my_pmprorh_init_buddypress_fields.php
Example of defining PMPro Register Helper Fields Synchronized to BuddyPress XProfile 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/
@pbrocks
pbrocks / pmpro-create-button-for-renew.css
Last active April 7, 2021 03:56
The following CSS code will alter the "Renew" link of your Paid Memberships Pro Account page and make it into a button.
/**
* The following CSS code will alter the "Renew" link of your
* Paid Memberships Pro Account page and make it into a
* button.
*
* If you do not have an expiration date set for
* your membership level and thus no "Renew" link, the first
* link will be affected by the CSS. In most cases, this
* will then be the "Change" membership link.
*