Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / bwawwp_localizing_nonstring_assets_2.php
Created June 10, 2018 15:15
Check for a localized version of an image. (BWAWWP Blog)
<?php
function localize_schoolpress_images_url( $url ) {
$locale = apply_filters( 'plugin_locale', get_locale(), 'schoolpress' );
if ( $locale != 'en_US' )
$url = SCHOOLPRESS_URL . '/languages/' . $locale . '/images/';
return $url;
}
add_filter( 'schoolpress_images_url', 'localize_schoolpress_images_url' );
?>
@ideadude
ideadude / bwawwp_localizing_nonstring_assets_3.php
Created June 10, 2018 15:16
Load localized email templates in a WordPress plugin. (BWAWWP Blog)
<?php
// Gets the full path for an email template given the email filename.
function schoolpress_get_email( $email ) {
$dir = apply_filters(
'schoolpress_emails_path', SCHOOLPRESS_PATH . '/emails/'
);
return $dir . $image;
}
// Filters the schoolpress_emails_path value based on locale.
@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_stripe_checkout_html.php
Created June 13, 2018 13:06
Replace the default payment information HTML for the Stripe class in Paid Memberships Pro
/**
* Replace the default payment information HTML for the Stripe class.
* Add this code into a custom plugin.
* Note that you will need to monitor PMPro updates in case your custom code conflicts with new version of PMPro.
*/
// Disable the defaults and load our own functions.
function my_stripe_checkout_html() {
//disable the defaults
remove_filter('pmpro_include_payment_information_fields', array('PMProGateway_stripe', 'pmpro_include_payment_information_fields'));
@ideadude
ideadude / my_pmprowoo_get_membership_price.php
Last active October 17, 2018 09:48
Use the pmprowoo_get_membership_price filter to set prices for variable products with Paid Memberships Pro and WooCommerce
<?php
/**
* Use the pmprowoo_get_membership_price filter to set prices for variable products.
* Update the $membership_prices array.
* Each item in that array should have a key equal to the membership level id,
* and a value equal to an array of the form array( {variable_product_id} => {member_price} )
*
* Add this code into a custom plugin.
*/
function my_pmprowoo_get_membership_price( $discount_price, $level_id, $original_price, $product ) {
@ideadude
ideadude / my_pmprowoo_woocommerce_product_is_on_sale.php
Created June 15, 2018 19:24
Consider member prices a "sale" so regular price is shown with a strikethrough with WooCommerce and PMPro WooCommerce
/**
* Consider member prices a "sale" so regular price is shown with a strikethrough
* If PMPro WooCommerce is active and setup to discount prices,
* then the calls to $product->get_price() will be filtered to return
* the member price.
*
* Add this code to a custom plugin.
*/
function my_pmprowoo_woocommerce_product_is_on_sale( $on_sale, $product ) {
$regular_price = (float) $product->get_regular_price();
@ideadude
ideadude / disable_pmprowoo_is_purchasble_filter.php
Created June 20, 2018 00:21
Disable the PMPro WooCommerce filter that restricts carts to only 1 membership product at a time.
<?php
/**
* Disable the PMPro WooCommerce filter that restricts carts
* to only 1 membership product at a time.
* Add this code into a custom plugin.
*/
function disable_pmprowoo_is_purchasble_filter() {
remove_filter( 'woocommerce_is_purchasable', 'pmprowoo_is_purchasable', 10, 2 );
}
add_action( 'init', 'disable_pmprowoo_is_purchasble_filter' );
@ideadude
ideadude / test_php_session_vars.php
Last active June 26, 2018 20:20
Test if PHP Session Variables are working.
<?php
/**
* Test if PHP Session Variables are working.
* Step 1: Add this code into a custom plugin or in a PHP file you know is being executed.
* Step 2: Navigate to /?test=123. You should see a blank old value and 123 as the new value.
* Step 3: Navigate to /?test=456. You should see 123 as the old value and 456 as the new value.
* If you see a blank old value again, that means that session variables are not enabled or otherwise broken.
* If the timestamp at the top is not being updated, the page may be cached.
* Step 4: Remove this code.
*/
@ideadude
ideadude / pmpro_cleanup_memberships_users_table.php
Created June 25, 2018 23:26
Force run the pmpro_cleanup_memberships_users_table() function in PMPro.
/**
* This gist will force run the pmpro_cleanup_memberships_users_table()
* function in PMPro. This function sets entries in the pmpro_memberships_users
* table to 'incative' if either (a) the level has been deleted or (b) there is a
* more recent active entry for the same level.
*
* IMPORTANT: Back up your database first.
* NOTE: This script may not fix all issues with the memberships_users table due to bad imports/etc.
* Add this code to a custom plugin, then visit /?cleanup_memberships_users_table=1
* to kick off the script. Then remove the code from the custom plugin.
@ideadude
ideadude / my_pmprorh_init_buddypress_fields.php
Created June 29, 2018 14:07
Example of defining PMPro Register Helper Fields Synchronized to BuddyPress XProfile Fields
/**
* Based on the Register Helper example.
* We've added a "buddypress" option for each field
* set to the XProfile name we used when setting up
* the fields in the BuddyPress extended profile.
* If the PMPro BuddyPress Add On is activated
* then the fields will be synchronized.
* Register Helper: https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
* PMPro BuddyPress: https://www.paidmembershipspro.com/add-ons/buddypress-integration/
*/