Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
strangerstudios / heartbeat-api-demo.php
Last active Aug 23, 2019
Minimal example demonstrating the WordPress Heartbeat API being added in WP version 3.6.
View heartbeat-api-demo.php
<?php
/*
Plugin Name: Heartbeat API Demo
Plugin URI: http://www.strangerstudios.com/wp/heartbeat-api-demo
Description: Minimal example demonstrating the WordPress Heartbeat API being added in WP version 3.6.
Version: .1
Author: strangerstudios
If logged in as a user and viewing the frontend of your website,
every 15 seconds you should see the following in your Javascript console:
@strangerstudios
strangerstudios / custom_addon_package_prices.php
Created Mar 22, 2016
Charge different prices for different membership levels with PMPro and PMPro Addon Packages.
View custom_addon_package_prices.php
/*
Charge different prices for different membership levels.
*/
//global var to store the price configurations
global $custom_addon_package_prices;
$custom_addon_package_prices = array(
//post_id => array(level_id => price, level_id => price, ...)
353 => array(1 => 1500, 2 => 1000, 3 => 500)
);
@strangerstudios
strangerstudios / pmpro-address-for-free-levels.php
Last active Jul 27, 2019
Show address fields for free levels also with Paid Memberships Pro.
View pmpro-address-for-free-levels.php
<?php
/*
Plugin Name: PMPro Address For Free Levels
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-address-for-free-levels/
Description: Show address fields for free levels also with Paid Memberships Pro
Version: .2
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
@strangerstudios
strangerstudios / gist:5573829
Last active Jul 27, 2019
Paid Memberships Pro customization to only let members of a certain level checkout if a discount code was used.
View gist:5573829
/*
Only let level 1 members sign up if they use a discount code.
Place this code in your active theme's functions.php or a custom plugin.
*/
function my_pmpro_registration_checks_require_code_to_register($pmpro_continue_registration)
{
//only bother if things are okay so far
if(!$pmpro_continue_registration)
return $pmpro_continue_registration;
View pmpro-mailchimp-merge-with-address-field.php
<?php
//Address merge types must be handled in a very specific format
function my_pmpro_mailchimp_listsubscribe_fields($fields, $user)
{
$user_info = get_userdata($user->ID);
$new_fields = array(
"FNAME" => $user->first_name,
"EMAIL" => $user->email,
"LNAME" => $user->last_name,
@strangerstudios
strangerstudios / pmpro_cancel_on_next_payments_date.php
Last active Jul 15, 2019
Change PMPro membership cancellation to set expiration date for next payment instead of cancelling immediately.
View pmpro_cancel_on_next_payments_date.php
/*
Change cancellation to set expiration date for next payment instead of cancelling immediately.
Assumes orders are generated for each payment (i.e. your webhooks/etc are setup correctly).
Since 2015-09-21 and PMPro v1.8.5.6 contains code to look up next payment dates via Stripe and PayPal Express APIs.
*/
//before cancelling, save the next_payment_timestamp to a global for later use. (Requires PMPro 1.8.5.6 or higher.)
function my_pmpro_before_change_membership_level($level_id, $user_id) {
//are we on the cancel page?
@strangerstudios
strangerstudios / pmprobuddy_update_user_meta.php
Last active Jul 10, 2019
Sync WordPress user meta fields (e.g. those added by PMPro Register Helper) with BuddyPress profile fields.
View pmprobuddy_update_user_meta.php
/*
Sync PMPro fields to BuddyPress profile fields.
*/
function pmprobuddy_update_user_meta($meta_id, $object_id, $meta_key, $meta_value)
{
//make sure buddypress is loaded
do_action('bp_init');
//array of user meta to mirror
$um = array(
@strangerstudios
strangerstudios / my_pmpro_members_list_csv_extra_columns.php
Last active Jul 8, 2019
Add columns to the Members List CSV Export.
View my_pmpro_members_list_csv_extra_columns.php
<?php
/*
Add data from the wp_users, wp_user_meta, or BuddyPress xProfile fields tables to the Members List CSV Export.
The pmpro_members_list_csv_extra_columns passes an array of columns.
The keys of the array are the column headings. The values are callback functions to get the value for that row.
*/
//add the column to the export
function my_pmpro_members_list_csv_extra_columns ( $columns ) {
@strangerstudios
strangerstudios / my_gettext_pay_by_check.php
Created Jun 29, 2015
Update Pay by Check wording in pmpro-pay-by-check to something else.
View my_gettext_pay_by_check.php
<?php
/*
Change "Pay by Check" language to "Pay by Wire Transfer"
Add this code to your active theme's functions.php
or a custom plugin.
*/
function my_gettext_pay_by_check($translated_text, $text, $domain)
{
if($domain == "pmpropbc" && $text == "Pay by Check")
@strangerstudios
strangerstudios / my_pmpro_email_attachments.php
Created Sep 4, 2014
Add an attachment to confirmation emails in Paid Memberships Pro
View my_pmpro_email_attachments.php
/*
Add an attachment to confirmation emails.
Requires PMPro v1.7.14+
*/
function my_pmpro_email_attachments($attachments, $email)
{
//make sure it's a checkout email (but not the admin one)
if(strpos($email->template, "checkout_") !== false && strpos($email->template, "admin") === false)
{
You can’t perform that action at this time.