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_getfile.php
Last active May 7, 2024 09:39 — 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_category_filter.php
Last active April 14, 2024 16:18 — forked from strangerstudios/my_pmpro_category_filter.php
Add specific members-only categories back to main loop when filtering searches and archives.
<?php
/**
* Add specific members-only categories back to main loop
* when filtering searches and archives.
* Updated for PMPro 3.0+.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
@ideadude
ideadude / my_add_extra_expiration_warning_templates.php
Last active March 26, 2024 06:44
Send extra expiration warning emails with individual templates when using PMPro and the Extra Expiration Warning Emails add on.
<?php
/**
* Send extra expiration warning emails with individual templates.
* Make sure the Extra Expiration Warning Emails Add On is also active.
* https://www.paidmembershipspro.com/add-ons/extra-expiration-warning-emails-add-on/
*
* Then add this code into a custom plugin or code snippet.
* https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/
*/
// Tell the expiration warnings add on to use our templates.
@ideadude
ideadude / wordpress_colon_searches.php
Last active January 23, 2024 02:58
If a colon is in a user search query in the WP Users dashboard or the PMPro Members List, try to speed up the query.
<?php
/**
* Functions affecting admins and the admin dashboard.
*/
/**
* Return array of fields found in the wp_users table.
* This function used in the others below to determine if a key entered in a search like "email:address@domain.com"
* is referencing the user_email column of the wp_users table or a unique meta key.
*/
function my_pmpro_get_user_table_columns() {
@ideadude
ideadude / my_pmpro_registration_checks_stop_free_checkouts.php
Created January 13, 2024 16:37
Don't let existing members checkout for a free level. [Paid Memberships Pro]
/**
* Don't let existing members checkout for a free level.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_registration_checks_stop_free_checkouts( $okay ) {
global $pmpro_level;
@ideadude
ideadude / cleanlog.sh
Last active January 10, 2024 22:14
Scrub emails out of an access log and note affected emails in scrubbed_text.txt
##
# Clean passwords out of access logs.
# Be sure to update the LOG_FILE line to match the location of your log file.
# This will edit your log files. You can back it up and then delete the backup if this works.
# This will also create a file scrubbed_emails.txt with a list of affected emails.
# This requires that both the password and password2 fields be in the logs.
# If you don't have password2 fields, edit the script to use the field that comes after password in your logs.
##
#!/bin/bash
@ideadude
ideadude / my_pmpro_user_field_swap_to_checkbox_grouped.php
Created December 28, 2023 18:34
Swap a PMPro user field to the checkbox_grouped type.
<?php
/**
* Currently, the PMPro user fields GUI does not allow you to choose
* the checkbox_grouped field type.
*
* These fields can be added via custom code though. If you want to manage some
* aspects of the field in the GUI, you can create a multiselect field,
* then swap it to the checkbox group using this code.
*
* You can add this recipe to your site by creating a custom plugin
@ideadude
ideadude / Affiliate_WP_PMP.php
Created November 5, 2023 14:17
Jason Fixed the PMP integration for AffiliateWP 2 years ago and they never updated it. Here's the old code.
<?php
/**
* Integrations: Paid Memberships Pro
*
* @package AffiliateWP
* @subpackage Integrations
* @copyright Copyright (c) 2016, Sandhills Development, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.8
*/
@ideadude
ideadude / my_login_redirect.php
Created February 9, 2023 19:24
Redirect all WordPress users to a very specific page on login.
<?php
/**
* Redirect all users to a very specific page on login.
* This should work no matter what login form/etc you are using.
* If it doesn't work, maybe the 999 priority needs to be higher.
* If you want to respect the redirect_to param or earlier callbacks
* that overwrite it, uncomment the section at the top of the function.
*
* You can add this code to your site using the Code Snippets plugin or by
* placing the code into a custom plugin or your theme's functions.php.
@ideadude
ideadude / pmprosm_sponsored_account_levels.php
Last active November 27, 2023 15:02
Example global settings for the PMPro Sponsored Members Add On
/*
Define the global array below for your main accounts and sponsored levels.
Array keys should be the main account level.
*/
global $pmprosm_sponsored_account_levels;
$pmprosm_sponsored_account_levels = array(
//set 5 seats at checkout
1 => array(
'main_level_id' => 1, //redundant but useful
'sponsored_level_id' => array(2,3), //array or single id