Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@kimcoleman
kimcoleman / atlas_foundation_gettext_membership.php
Last active December 20, 2018 17:53
Example of using str_replace for AtlasFoundation ticket
<?php
/**
* This filter will search your codebase for translatable strings and replace when an exact match is found.
*
* Add this code to your PMPro Customizations Plugin
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*
* @param string $output_text this represents the end result
* @param string $input_text what is written in the code that we want to change
* @param string $domain text-domain of the plugin/theme that contains the code
@kimcoleman
kimcoleman / my_pmpro_getresponse_custom_fields.php
Last active December 20, 2018 17:03 — forked from strangerstudios/my_pmpro_getresponse_custom_fields.php
Sync user fields with GetResponse with PMPro GetResponse
<?php
/**
* This filter will send additional user meta fields to contacts in GetResponse.
*
* Add this code to your PMPro Customizations Plugin
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*
* @param array $fields the array of fields to send
* @param object $user what is written in the code that we want to change
*/
@kimcoleman
kimcoleman / studiotogo_hide_old_pages_from_members.php
Created December 20, 2018 18:49
This code will create a content filter for pages to remove access to posts that were published before a member's join date, including a 15 day grace period.
<?php
/*
* This code will create a content filter for pages to remove access to posts that were published before a member's join date.
* It includes a 15 day "grace period" so that members can see posts published up to 15 days prior to their join date.
*
* The params passed are:
* $hasaccess - (bool) what PMPro thinks about whether the user has access
* $thepost - (post object) the post being checked, usually the current post
* $theuser - (user object) the user being checked, usually the current user
* $post_membership_levels - (array of levels) the levels this post requires (if any)
@kimcoleman
kimcoleman / bcc_on_member_email_headers.php
Created December 20, 2018 18:57
Bcc additional email addresses on all PMPro emails sent to the member.
<?php
/*
* Bcc additional email addresses on all PMPro emails sent to the member.
*/
function bcc_on_member_email_headers( $headers, $email ) {
//bcc emails not already going to admin_email
if ( $email->email != get_bloginfo( 'admin_email' ) ) {
//add bcc
$headers[] = "Bcc:" . "[email protected],[email protected]";
}
<?php
function my_pmpro_getresponse_custom_fields( $fields, $user ) {
// Get fields from Register Helper user meta
$phone = get_user_meta($user->ID, 'mytheme_phone', true);
$fullname = get_user_meta($user->ID, 'mytheme_fullname', true);
$fields = array(
'telephone' => $phone,
'full_name' => $fullname,
);
return $fields;
@kimcoleman
kimcoleman / my_pmpro_has_membership_access.php
Created December 27, 2018 18:52
Execute custom code if the user does not have access to the content.
<?php
/*
* Execute custom code if the user does not have access to the content.
*/
$queried_object = get_queried_object();
if (
function_exists( 'pmpro_has_membership_access' ) &&
! empty( $queried_object ) &&
empty( pmpro_has_membership_access( $queried_object->ID, NULL, false ) )
@kimcoleman
kimcoleman / hide_noaccess_posts_pmpro_series.php
Last active January 16, 2019 14:59
Filter the output of the Series post list to exclude posts the current user cannot access.
<?php
/*
* Filter the output of the Series post list to exclude posts the current user cannot access.
*/
function hide_noaccess_posts_pmpro_series( $post_list_posts, $series ) {
if ( function_exists( 'pmpro_has_membership_access' ) ) {
foreach ( $post_list_posts as $key => $sp ) {
$hasaccess = pmpro_has_membership_access( $sp->id, NULL, false );
if ( empty( $hasaccess ) ) {
@kimcoleman
kimcoleman / my_pmpro_membership_level_gadwp_analytics.php
Created January 16, 2019 17:52
Track membership level as Custom Dimension 1 (dimension1) in your Google Analytics tracking code.
<?php
/**
* Track membership level as Custom Dimension 1 (dimension1) in your Google Analytics tracking code.
*
* Requires Paid Memberships Pro and the Google Analytics Dashboard for WP by ExactMetrics (formerly GADWP) plugin.
*/
function my_pmpro_membership_level_gadwp_analytics( $gadwp ) {
$commands = $gadwp->get(); // Get commands array
@kimcoleman
kimcoleman / dynamic_pmpro_levels_array.php
Last active April 8, 2021 18:20
Dynamically display certain levels on the Membership Levels page based on the current user's active level
<?php
/**
* Dynamically display certain levels on the Membership Levels page based on the current user's active level
* This example allows you to show/hide specific levels on the Membership Levels page.
*/
function dynamic_pmpro_levels_array( $levels ) {
// Get all the levels
$levels = pmpro_getAllLevels( false, true );
// remove levels 1, 5, 6, and 7 user has level 1.
@kimcoleman
kimcoleman / sample_pmprorh_init.php
Created March 6, 2019 17:04
Adds a Register Helper "My Extra Field" input after billing fields.
<?php
/**
* Adds a Register Helper "My Extra Field" input after billing fields.
*/
function sample_pmprorh_init() {
//don't break if Register Helper is not loaded
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}