Skip to content

Instantly share code, notes, and snippets.

View pbrocks's full-sized avatar

Paul Barthmaier pbrocks

View GitHub Profile
@pbrocks
pbrocks / pmpro-second-name.php
Created September 19, 2018 01:26
Add second name and email to PMPro Checkout page and/or Profile
<?php
/**
* Plugin Name: PMPro Register Helper Examples
* Description: Add this to your PMPro Customizations folder and then activate the plugin from your dashboard.
* Author: pbrocks
* Version: 1.3
* Author URI: https://github.com/pbrocks
* Add this to a Customizations Plugin and customize to suit your needs
*/
function initialize_pmprorh_fields1() {
@pbrocks
pbrocks / directory.php
Created September 14, 2018 21:50
This code allows you to customize the PMPro Member Directory to safely add code that won't be lost during an update.
<?php
/**
* In your active theme create the folder `/paid-memberships-pro/pmpro-member-directory/` and save the code from this gist in a file called `directory.php`.
* This shortcode will display the members list and additional content based on the defined attributes.
*/
function pmpromd_shortcode( $atts, $content = null, $code = '' ) {
// $atts ::= array of attributes
// $content ::= text within enclosing form of shortcode element
// $code ::= the shortcode found, when == callback name
// examples: [pmpro_member_directory show_avatar="false" show_email="false" levels="1,2"]
@pbrocks
pbrocks / pmpro-getfile-before-error.php
Last active September 21, 2018 20:28 — forked from strangerstudios/my_pmpro_getfile_before_error.php
Use pmpro_getfile_before_error to tell PMPro to do something else besides send a 503 when accessing a member file. Requires PMPro 1.7.15+
<?php // do not include in Customizations plugin
/**
* Redirect to the levels page when users try to access protected files in PMPro.
*
* Add this code to your customizations plugin file.
*
* Learn about protecting files with PMPro here:
* https://www.paidmembershipspro.com/locking-down-protecting-files-with-pmpro/
*/
function my_pmpro_getfile_before_error( $filename ) {
@pbrocks
pbrocks / pmpro-login-memberslist-addtion.php
Created September 9, 2018 02:38
Recipe to add login information to PMPro Memberslist and CSV exports
<?php // Do not include in Customizations plugin
/**
* Code creates new column for Memberslist and Memberlist CSV export
*
* Add to a PMPro Customizations plugin
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function pmpro_memberslist_extra_col_header() { ?>
<th><?php _e( 'Last Login', 'pmpro' ); ?></th>
@pbrocks
pbrocks / date-check.js
Created September 8, 2018 14:17
Add hidden PMPro registration field that shows a message when a checkbox is ticked.
jQuery(document).ready(function($) {
var label = $('label[for=hidden_check]');
$(label).hide();
$('#date_check').click(function() {
if($('#date_check').is(':checked')) {
$(label).css('color','salmon').show();
$('input[name=hidden_check]').val('1');
} else {
$(label).hide();
$('input[name=hidden_check]').val('0');
@pbrocks
pbrocks / pmpro-register-helper-conditional-field.php
Created September 8, 2018 13:54
Add a PMPro Register Helper conditional field to your checkout and profile screens.
<?php // Do not include in PMPro Customizations plugin
/**
* Add a conditional Register Helper field with a checkbox that needs to be checked in order to show a Date field.
*/
function initialize_conditional_dob() {
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
// define the fields
$fields = array();
@pbrocks
pbrocks / pmpro-register-helper-example-fields.php
Last active September 5, 2019 22:29
These examples show the range of possibilities, including the 'niche' options, for fields used in Paid Memberships Pro's Register Helper Add-On.
<?php // Do not include this or the doc block if adding to a Customizations plugin
/**
* Add this to its own folder in your plugins directory or copy the code below this doc block to a Customizations Plugin and customize to suit your needs.
*
* Plugin Name: PMPro Register Helper Examples
* Description: Create a folder name in your plugins' folder with the same name as this filename, but without the .php extension. Save this file in that folder and then you can activate this plugin in your WordPress dashboard,
* Author: pbrocks
* Author URI: https://github.com/pbrocks
*/
@pbrocks
pbrocks / pmpro-register-helper-fields-examples.php
Last active September 6, 2018 18:48 — forked from andrewlimaza/rh_fields_example.php
Paid Memberships Pro Register Helper field type examples shows an example of every possible field in Register Helper
<?php
/**
* This example is to show you the 'niche' options each Paid Memberships Pro - Register Helper Add-on field can take and how to use it.
*
* Add this to a Customizations Plugin and customize to suit your needs
*/
function initialize_pmprorh_fields() {
// don't break if Register Helper is not loaded
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
@pbrocks
pbrocks / pmpro-membership-level-shortcode.php
Created September 5, 2018 14:52
Create a PMPro [membership-level] shortcode to display the user's current membership level.
<?php // Do not copy this tag.
/**
* Use the shortcode [membership-level] to display the user's current membership level.
*
* Copy the function below into your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
/**
* pmpro_membership_level_shortcode Function to create the new [membership-level] shortcode
*
@pbrocks
pbrocks / assign-bbpress-role.php
Created September 3, 2018 20:31
Check the default bbPress role associated with a level and then assign it to a new member during PMPro checkout.
<?php // Do not include in your Customizations Plugin
/**
* Check the default bbPress role associated with a level and then assign it to a new member during PMPro checkout.
*/
add_action( 'pmpro_after_checkout', 'pmpro_add_forum_role', 11 );
function pmpro_add_forum_role( $user_id ) {
// $member_data = get_userdata( $user_object->ID );
$member_object = pmpro_getMembershipLevelForUser( $user_id );
$level_id = $member_object->id;