Skip to content

Instantly share code, notes, and snippets.

View KristaButler's full-sized avatar

Krista Butler KristaButler

View GitHub Profile
@KristaButler
KristaButler / mp_wpx_cache.txt
Created August 9, 2023 20:17
MemberPress WPX Cloud CDN Caching Exclusions for .htaccess
<IfModule mod_rewrite.c>
RewriteEngine OnRewriteBase
/RewriteCond %{REQUEST_URI} "/thank-you/"
[NC,OR]RewriteCond %{REQUEST_URI} "/login/"
[NC,OR]RewriteCond %{REQUEST_URI} "/account/"
[NC,OR]RewriteCond %{REQUEST_URI} "/register/"
[NC,OR]RewriteCond %{REQUEST_URI} "/mepr/"
[NC,OR]RewriteCond %{REQUEST_URI} "/unauthorized/"
[NC,OR]RewriteRule ^ - [E=nocache:true]Header always set Cache-Control "no-cache" env=nocacheWordPressProtect captcha, 2
</IfModule>
@KristaButler
KristaButler / mepr_return_to_page
Created July 13, 2023 19:10
Return to Same Page after Registration
function mepr_cust_registration_input($product_id) {
global $post;
$input_str = "<input type='hidden' name='mepr_cust_current_page_id' id='mepr_cust_current_page_id' value='{$post->ID}'/>";
echo $input_str;
}
add_action('mepr-checkout-before-submit', 'mepr_cust_registration_input');
function mper_cust_thankyou_url_params($url, $args) {
if (isset($_REQUEST['mepr_cust_current_page_id']) && $_REQUEST['mepr_cust_current_page_id']) {
$param_str = http_build_query($args);
@KristaButler
KristaButler / mepr_proration.php
Last active June 8, 2023 21:19
Mepr Proration Tweaks
<?php
add_filter('mepr-allow-multiple-upgrades-downgrades', function($allow, $user, $sub_in_group, $product) {
return true;
}, 10, 4);
add_filter( 'mepr-proration', function ( $prorations, $old_amount, $new_amount, $old_period, $new_period, $old_days_left, $old_sub, $new_sub, $reset_period ) {
//This only works for recurring to recurring upgrades during a prorate trial,
//so if that's not the case - just return the usual proration and skip all this.
//NOTE: If the old sub had a trial that the proration was applied to - this won't work
@KristaButler
KristaButler / printscripts.php
Last active June 2, 2023 01:42
Print Scripts
add_action('wp_enqueue_scripts', function () {
mper_print_scripts();
}, 99999);
function mper_print_scripts() {
$list = '';
//Print all loaded Styles (CSS)
global $wp_styles;
foreach( $wp_styles->queue as $style ) :
@KristaButler
KristaButler / easf_noecommerce.php
Created December 1, 2022 20:51
Allow no ecommerce integration in EA Options
<?php
add_filter('esaf_validate_options', function($errors) {
$return_errors = [];
$ecommerce_message = __('You must enable at least one eCommerce Payment Integration.', 'easy-affiliate');
foreach($errors as $error_msg) {
if ($error_msg != $ecommerce_message) {
$return_errors[] = $error_msg;
}
}
@KristaButler
KristaButler / ExportPrettyLinksWStats.txt
Created September 21, 2022 14:51
Export Pretty Links with Total and Unique clicks
SELECT l.id, l.url, l.slug, l.name, l.redirect_type,
l.track_me, l.nofollow, l.sponsored, l.param_forwarding,
gt.meta_value AS google_tracking, d.meta_value AS delay,
l.created_at AS created_at, l.updated_at AS last_updated_at ,
(SELECT GROUP_CONCAT(DISTINCT t.slug ORDER BY t.slug ASC SEPARATOR ',')
FROM wp_terms AS t
JOIN wp_term_taxonomy AS tt
ON t.term_id = tt.term_id
AND tt.taxonomy = 'pretty-link-category'
JOIN wp_term_relationships AS tr
@KristaButler
KristaButler / QuickLatexInMemberPressQuizzes
Created September 15, 2022 19:32
Use QuickLatex in MemberPress Quizzes
<?php
//You must include [latexpage] at the beginning of each question (inside the input box in the quiz builder)
//in order for the parser to work properly.
add_filter('mepr_view_get_string_/quizzes/questions/essay', 'mpcs_run_quicklatex', 10, 2);
add_filter('mepr_view_get_string_/quizzes/questions/multiple-answer', 'mpcs_run_quicklatex', 10, 2);
add_filter('mepr_view_get_string_/quizzes/questions/multiple-choice', 'mpcs_run_quicklatex', 10, 2);
add_filter('mepr_view_get_string_/quizzes/questions/short-answer', 'mpcs_run_quicklatex', 10, 2);
add_filter('mepr_view_get_string_/quizzes/questions/true-false', 'mpcs_run_quicklatex', 10, 2);
@KristaButler
KristaButler / MembershipExpirationDateShortcode.php
Created September 15, 2022 15:41
Membership Expiration Date Shortcode
<?php
//Shortcode Example: [mepr-sub-expiration membership='123']
function mepr_sub_expiration_shortcode($atts = [], $content = null, $tag = '') {
$sub_expire_html = '';
if($atts['membership'] && is_numeric($atts['membership'])) {
$date_str = MeprUser::get_user_product_expires_at_date(get_current_user_id(), $atts['membership']);
if ($date_str) {
$date = date_create($date_str);
@KristaButler
KristaButler / CustomRoleRules.php
Created August 30, 2022 02:56
Custom Role Rules
<?php
function mepr_remove_subscriber_role($roles_to_remove, $wp_user) {
$mepr_user = new MeprUser($wp_user->ID);
if (mepr_is_member_inactive($mepr_user)) {
$roles_to_remove[] = 'subscriber';
} else {
$active_memberships = $mepr_user->active_product_subscriptions('ids', true);
if (!empty($active_memberships)) {
$roles_to_remove[] = 'ex-subscriber';
@KristaButler
KristaButler / invoicenumontransactionscreen.php
Created July 19, 2022 18:26
Add Invoice Number to Transactions Table
add_filter('mepr-admin-transactions-cols', function ($cols) {
$cols['col_txn_invoice'] = __('Invoice No.', 'memberpress-pdf-invoice');
return $cols;
});
add_action('mepr-admin-transactions-cell', function ($column_name, $rec, $attributes) {
if ($column_name === 'col_txn_invoice') {
?>
<td <?php echo $attributes; ?>>