Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / unpaidmembers.sql
Created October 28, 2023 16:22
MySQL query to get members with paid levels (6, 20, 21) that don't have a paid order within the past 12 months.
# Find members with active paid memberships but their last order was > 12 months ago.
SELECT
m.user_id,
m.membership_id,
u.user_email,
MAX(o.timestamp) as last_order_timestamp
FROM
wp_pmpro_memberships_users m
LEFT JOIN wp_users u ON m.user_id = u.ID
JOIN
@ideadude
ideadude / class-rate-limter.php
Created May 22, 2023 18:35
Generic IP limiter class for WordPress.
<?php
// Check if this class has already been loaded.
if ( class_exists( 'Rate_Limiter' ) ) {
return;
}
/**
* RateLimiter Class
* Limit the number of times a user can perform an action within a given period of time.
*/
@ideadude
ideadude / tighten_pmpro_spam_protections.php
Created March 28, 2023 20:16
Tighten the PMPro Spam Protection so users/IPs with failed payments are locked out more quickly.
<?php
// Add these 2 lines to your wp-config.php
// This will lock IPs that fail checkout 5 times within 30 minutes.
// The default is 10 failures every 15 minutes (900 seconds).
define( 'PMPRO_SPAM_ACTION_NUM_LIMIT', 5 );
define( 'PMPRO_SPAM_ACTION_TIME_LIMIT', 1800 ); // in seconds
@ideadude
ideadude / my_unescaped_pmpro_tos_content.php
Created February 21, 2023 15:18
Update the TOS on the PMPro checkout page to skip the escaping introduced in PMPro 2.10.
<?php
/**
* Update the TOS on the PMPro checkout page to skip the escaping
* introduced in PMPro 2.10. This will work in PMPro 2.10.1 or higher.
*
* 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.
*/
function my_unescaped_pmpro_tos_content( $content, $tospage ) {
return do_shortcode( $tospage->post_content );
@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 / my_upload_size_limit_for_non_admins.php
Created December 9, 2022 15:46
Limit non-admin/editor file uploads to 2mb with WordPress
<?php
/**
* Limit non-admin/editor file uploads to 2mb
* We check the upload_files capability,
* so anyone with access to the Media Library
* can upload files at the PHP/server set max.
*
* 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.
@ideadude
ideadude / my_pmprosp_minimum_password_score_message.php
Created December 5, 2022 21:53
Translate the password suggestions in the PMPro Strong Passwords Add On
<?php
/**
* Swap or translate the password suggestions from the PMPro Strong Password Add On.
* These suggestions come from the bundled password strenght library.
* Until we update the plugin to make these translatable,
* the following code can be used to translate them on your site.
*
* 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.
@ideadude
ideadude / fix-charset-for-pmpro-tables.sql
Created October 21, 2022 13:50
Update some PMPro DB tables to use UTF8 character sets.
# PMPro doesn't set the character set when creating its tables.
# So on install PMPro will use the default character set for your DB.
# In some cases this might be something like latin1, which will not
# work with special characters for non-latin languages, e.g. Hebrew.
# To fix this, you can update the character set on these tables using MySQL.
#
# IMPORTANT: Back up your DB (at least these tables) before running any queries.
ALTER TABLE wp_pmpro_membership_levels CONVERT TO CHARACTER SET utf8;
ALTER TABLE wp_pmpro_membership_levelmeta CONVERT TO CHARACTER SET utf8;
ALTER TABLE wp_pmpro_membership_ordermeta CONVERT TO CHARACTER SET utf8;
@ideadude
ideadude / my_pmpro_additional_categories.php
Created October 19, 2022 09:59 — forked from strangerstudios/my_pmpro_additional_categories.php
Add "Purchase Additional Access" box to Membership Checkout for a la carte category purchase.
<?php
/**
* Require specific category user meta to view posts in designated categories.
* Custom price-adjusting fields are added via user fields.
* The initial payment and billing amount is adjusted based on cat selections.
*
* 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_pmpro_email_custom_data.php
Created October 12, 2022 19:04
Add user_id as a data variable for email templates in PMPro
<?php
/* This code will add user_id as a data variable for email templates in PMPro.
*
* 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/
*/
// begin copying code below here