Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / my_pmpro_pre_handle_404.php
Last active November 22, 2017 13:05 — forked from strangerstudios/my_pmpro_pre_handle_404.php
If we 404, and the slug matches a pmpro discount code, redirect
/*
If we 404, and the slug matches a discount code, redirect
Add this code to a custom plugin
*/
function my_pmpro_pre_handle_404($preempt, $wp_query) {
global $wpdb;
//make sure we're 404ing
if(!is_404())
@ideadude
ideadude / my_pmpro_emails_custom_template_path.php
Last active April 3, 2021 04:07 — forked from strangerstudios/my_pmpro_emails_custom_template_path.php
Tell PMPro to look in the pages directory of this plugin for PMPro email templates.
<?php
/*
Tell PMPro to look in the pages directory of this plugin for PMPro email templates.
Add this code to a custom plugin.
Make sure that there is a /email/ directory in the plugin directory with your templates in it.
*/
function my_pmpro_email_custom_template_path($default_templates, $page_name) {
$default_templates[] = dirname(__FILE__) . '/email/' . $page_name . '.html';
return $default_templates;
@ideadude
ideadude / directory.php
Last active March 10, 2018 18:38 — forked from strangerstudios/directory.php
PMPro Member Directory Template Code with pk user meta filtering back in.
<?php
/*
Save this file to /themes/{active theme}/paid-memberships-pro/member-directory/tempaltes/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
@ideadude
ideadude / affiliate_discount_codes.php
Last active January 5, 2022 20:51 — forked from strangerstudios/pmpro_ld2aff.php
Link Paid Memberships Pro discount codes to affiliate accounts from another plugin/service.
<?php
/*
Link discount codes to affiliates.
*/
//this is the parameter we're looking for to find affiliates... based on which plugin/etc you are using
define('PMPRO_LDC2AFF_KEY', 'wpam_id'); //Affiliates Manager Plugin
//define('PMPRO_LDC2AFF_KEY', 'pa'); //WordPress Lightweight Affiliates
//define('PMPRO_LDC2AFF_KEY', 'ref'); //AffiliateWP
//helper function to get the values from options and make sure they are an array
@ideadude
ideadude / show_pmpro_address_fields_on_edit_profile.php
Last active July 21, 2021 19:08 — forked from strangerstudios/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.
/*
Use PMPro Register Helper to add PMPro Billing Address fields to the edit user page for admins.
*/
function show_pmpro_address_fields_on_edit_profile()
{
//require PMPro and PMPro Register Helper
if(!defined('PMPRO_VERSION') || !defined('PMPRORH_VERSION'))
return;
$address_fields = array(
@ideadude
ideadude / my_pmprorh_init.php
Last active August 19, 2022 17:01 — forked from strangerstudios/my_pmprorh_init.php
Register Helper Example
<?php
/*
* Example Register Helper fields for Company, Referral Code, and Budget.
*
*/
// We have to put everything in a function called on init, so we are sure Register Helper is loaded.
function my_pmprorh_init() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
@ideadude
ideadude / my_pmpro_getfile.php
Last active July 25, 2021 10:14 — forked from strangerstudios/my_pmpro_getfile.php
How to protect non-WordPress files in a subdirectory of your site using Paid Memberships Pro.
<?php
/*
This code handles loading a file from the /protected-directory/ directory.
(!) Be sure to change line 19 below to point to your protected directory if something other than /protected/
(!) Be sure to change line 66 below to the level ID or array of level IDs to check for the levels you need.
(!) Add this code to your active theme's functions.php or a custom plugin.
(!) You should have a corresponding bit of code in your Apache .htaccess file to redirect files to this script. e.g.
###
@ideadude
ideadude / my_pmpro_pages_custom_template_path.php
Last active January 7, 2020 16:16 — forked from strangerstudios/my_pmpro_pages_custom_template_path.php
Tell PMPro to look in the pages folder of this plugin for PMPro page templates.
<?php
/*
Tell PMPro to look in the pages directory of this plugin for PMPro page templates.
Add this code to a custom plugin.
Make sure that there is a /pages/ directory in the plugin directory with your templates in it.
*/
function my_pmpro_pages_custom_template_path( $default_templates, $page_name, $type, $where, $ext ) {
$default_templates[] = dirname(__FILE__) . '/pages/' . $page_name . '.' . $ext;
return $default_templates;
@ideadude
ideadude / pmpro_loadTemplate_example.php
Last active April 3, 2021 04:07 — forked from strangerstudios/pmpro_loadTemplate_example.php
Example of a shortcode that uses pmpro_loadTemplate to grab it's template file.
<?php
/*
[my_pmpro_addon] shortcode.
*/
function my_pmpro_addon_shortcode() {
//load template
$content = pmpro_loadTemplate( 'my_pmpro_addon' ); //will look for /wp-content/themes/your-theme/paid-memberships-pro/pages/my_pmpro_addon.php
//maybe tweak the content a bit
@ideadude
ideadude / pmpro-cpt.php
Last active June 19, 2023 22:43 — forked from strangerstudios/pmpro-cpt.php
Add the PMPro meta box to a CPT. Add this to your plugin/etc.
<?php
/**
* Add the PMPro meta box to a CPT
*/
function my_add_pmpro_meta_box_to_cpts() {
// Duplicate this row for each CPT. This one adds the meta boxes to 'product' CPTs.
add_meta_box('pmpro_page_meta', 'Require Membership', 'pmpro_page_meta', 'product', 'side' );
}
add_action( 'admin_menu', 'my_add_pmpro_meta_box_to_cpts', 20 );