Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@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 / pmpro_start_session.php
Created August 9, 2018 15:51
Tell PMPro to start the PHP session earlier.
/**
* Add this code into a custom plugin.
* You could also add a direct call to session_start() in your wp-config.php
* or another piece of code that runs early.
*/
add_action('plugins_loaded', 'pmpro_start_session');
@ideadude
ideadude / autocomplete_virtual_orders.php
Created August 17, 2018 13:58
Autocomplete WooCommerce orders with only virtual products.
/**
* Autocomplete orders with only virtual products.
* From the 2nd edition of Building Web Apps with WordPress
* https://bwawwp.org
*/
function autocomplete_virtual_orders($order_id) {
//get the existing order
$order = new WC_Order($order_id);
//assume we will autocomplete
@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() {
@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 / 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_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_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 / 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/
*/