Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / set_request_level_on_sitewide_sales_pages.php
Last active November 5, 2018 13:28
Set the $_REQUEST['level'] var early on specific URLs to help other PMPro Customizations
/**
* We need to set $_REQUEST['level'] early on our
* sitewide sales pages to support other customizations.
* We can't use is_page because WP isn't fully setup yet.
* Update the $sitewide_sales_pages and $default_level_id as needed.
* Add to a custom plugin.
*/
function set_request_level_on_sitewide_sales_pages() {
$sitewide_sales_pages = array(
'blackfriday',
@ideadude
ideadude / pmpro_btc_currency_format.php
Created November 2, 2018 00:35
Add a BTC currency to Paid Memberships Pro
/**
* Add a BTC currency to Paid Memberships Pro
* Add this code into a custom plugin. https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function pmpro_btc_currency_format( $pmpro_currencies ) {
$pmpro_currencies['BTC'] = array(
'name' => __( 'Bitcoin', 'paid-memberships-pro' ),
'decimals' => '8',
'thousands_separator' => '',
'decimal_separator' => '.',
@ideadude
ideadude / my_gettext_pmprowc_changes.php
Created September 25, 2018 18:51
Change the default text for the one-membership-product-per-cart warning in PMPro WooCommerce.
<?php
/**
* Change the default text for the one-membership-product-per-cart warning in PMPro WooCommerce.
* Add this code to a custom plugin. https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_gettext_pmprowc_changes( $translated_text, $text, $domain ) {
if( $domain == "pmpro-woocommerce" && $text == "You may only add one membership to your %scart%s." ) {
$translated_text = "Include the %stwo percent-s strings%s, which will add the start and end a tags.";
}
@ideadude
ideadude / my_pmpro_membership_post_membership_expiry.php
Last active May 11, 2021 19:14
When users expire (and the system changes them to membership level 0) we give them another downgraded level.
<?php
/**
* When users expire (and the system changes them to membership level 0) we give them another downgraded level.
* This gist is setup to specifically downgrade level 6 to level 3 with an expiration set to 305 days out and
* downgrade level 5 to level 2 with an expiration set to 150 days out.
* Note that this code is using the pmpro_membership_post_membership_expiry hook which only fires when a user is expired
* by the PMPro cron job. If an admin changes the user's level or they cancel, they will not receive the downgraded level.
* Adjust the gist to meet your needs.
* Add this code to a custom plugin. https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
@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 / 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 / my_pmpro_getfile_before_readfile.php
Created September 13, 2018 15:33
Checking for PMPro membership when accessing non-WP pages.
/**
* Checking for membership when accessing non-WP pages.
* This code will work with the htaccess rewrite rules shared here:
* https://www.paidmembershipspro.com/locking-non-wordpress-files-folders-paid-memberships-pro/
*/
function my_pmpro_getfile_before_readfile( $filename, $file_mimetype ) {
if(is_dir($filename)) {
$filename .= "index.html";
$mimetype = new pmpro_mimetype();
$file_mimetype = $mimetype->getType($filename);
@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 / htaccess.txt
Last active August 12, 2023 06:51
htaccess rules to use unix password but allow Stripe and PayPal webhooks/IPNs to go through
# Stripe Webhook IPs via https://stripe.com/docs/ips#webhook-notifications
# v create a user/pass in this folder using htpasswd v
AuthUserFile /var/www/vhosts/domain.com/conf/.htpasswd
# ^^
AuthType Basic
AuthName "Authentication Required"
Require valid-user
Order allow,deny
Allow from 3.18.12.63
Allow from 3.130.192.231
@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:[email protected]"
* is referencing the user_email column of the wp_users table or a unique meta key.
*/
function my_pmpro_get_user_table_columns() {