Skip to content

Instantly share code, notes, and snippets.

@messica
messica / membership-card.php
Created October 4, 2019 20:20 — forked from ipokkel/membership-card.php
Sample custom membership card template to display values of Register Helper Fields on card
<?php
/**
* Custom membership-card template
* Place this directly in your theme/child-theme's root directory
* e.g.: example.com/wp-content/themes/{your active theme}/membership-card.php
*
* Use the function my_pmpro_member_card_usermeta to retrieve meta values from the usermeta table
*
*/
@messica
messica / my_login_redirect.php
Created October 3, 2019 20:34
Respect redirect_to query parameter when logging in with Member Homepages
<?php
function my_login_redirect( $redirect, $request, $user ) {
if ( ! empty( $request ) ) {
remove_filter('login_redirect', 'pmpromh_login_redirect', 10, 3);
remove_filter('login_redirect','pmpro_login_redirect', 10, 3);
return $redirect;
}
}
add_action( 'login_redirect', 'my_login_redirect', 5, 3 );
@messica
messica / my_pmpro_email_attachments.php
Created October 3, 2019 01:29
Attachments fix for Email Log plugin.
<?php
// Attachments fix for Email Log plugin.
function my_pmpro_email_attachments( $attachments, $email ) {
if ( null === $attachments ) {
return array();
}
return $attachments;
}
add_filter( 'pmpro_email_attachments', 'my_pmpro_email_attachments', 10, 2 );
@messica
messica / pmpro_valid_gateways.php
Created October 1, 2019 02:58
Randomly choose a gateway from valid gateways.
<?php
// Add "authorizenet" to valid gateways.
function my_pmpro_valid_gateways( $gateways ) {
global $gateway, $pmpro_valid_gateways;
$gateways[] = 'authorizenet';
$pmpro_valid_gateways = $gateways;
return $gateways;
}
add_filter( 'pmpro_valid_gateways', 'my_pmpro_valid_gateways' );
@messica
messica / my_woocommerce_api_request_redirect_pmpro.php
Last active September 27, 2019 01:30
Redirect PMPro related webhooks to PMPro webhook handler.
<?php
/**
* Redirect PMPro related webhooks to PMPro webhook handler.
*/
function my_woocommerce_api_request_redirect_pmpro( $request ) {
global $wpdb;
// Only continue if PMPro is loaded.
@messica
messica / pmpro_require_tos.php
Created September 25, 2019 01:32
Disable membership unless users have agreed to Terms of Service (requires Register Helper).
<?php
/**
* Disable membership unless users have agreed to Terms of Service (requires Register Helper).
*
* - Adds a ToS checkbox and link to the user's profile page.
* - Overrides membership if users haven't agreed to updated ToS.
* - Filters non-member text if users haven't agreed to ToS.
* - Resets ToS user meta when ToS page is updated.
*/
@messica
messica / my_pmpro_memberslist_expires_column.php
Last active September 20, 2019 15:05
Use most recent expiration date in Expired column in Members List.
<?php
/**
* Use most recent expiration date in Expired column in Members List.
*/
function my_pmpro_memberslist_expires_column( $enddate, $user ) {
global $wpdb;
$filter = sanitize_text_field( $_REQUEST['l'] );
@messica
messica / my_pmpro_states_init.php
Created September 13, 2019 23:28
Use Australian States in dropdown.
<?php
function my_pmpro_states_init() {
add_filter( 'pmpro_state_dropdowns', '__return_true' );
add_filter( 'pmpro_states', 'my_pmpro_states' );
}
add_action( 'init', 'my_pmpro_states_init' );
function my_pmpro_states( $states ) {
@messica
messica / my_pmpro_checkout_level_fix_prices_for_stripe.php
Created August 12, 2019 18:57
Fix for PMPro Proration Add On, Japanese Yen, and Stripe (make sure level costs are integers)
<?php
/**
* Fix for PMPro Proration Add On, Japanese Yen, and Stripe
*/
function my_pmpro_checkout_level( $level ) {
// Make sure level costs are always integers.
$level->initial_payment = intval( $level->initial_payment );
$level->billing_amount = intval( $level->billing_amount );
return $level;
@messica
messica / my_pmpro_checkout_level.php
Created July 9, 2019 18:47
Simple Proration for Upgrades Example
<?php
/**
* Simple Proration for Upgrades Example
*/
function my_pmpro_checkout_level( $checkout_level ) {
// Get user's current level.
$user_level = pmpro_getMembershipLevelForUser();