Skip to content

Instantly share code, notes, and snippets.

View dparker1005's full-sized avatar

David Parker dparker1005

  • Stranger Studios
View GitHub Profile
#lang racket
(define const? number?)
(define var? symbol?)
(define (ev σ θ e)
(match e
[(? const? e) (cons σ e)]
[(? var? e) (cons σ (hash-ref θ e))]
; Comma here matches any var
[
{
"name": "Checker Me Up",
"description": "Pawns Start in a Checker Board Formation",
"newBoard": "RNBQKNBRP*P*P*P**P*P*P*PP*P*P*P*p*p*p*p**p*p*p*pp*p*p*p*rnbqknbr"
},
{
"name": "Horse Spies",
"description": "Sneaky Horsies",
"newBoard": "nNBQKBNnPPPPPPPP********************************ppppppppNnbqkbnN"
@dparker1005
dparker1005 / discount_with_check.php
Last active June 12, 2019 19:19
Discounts the price of a membership by $50 when a user pays by check using Paid Memberships Pro and PMPro Pay by Check Add-On. For use in PMPro Customizations Plugin.
<?php
/**
* If a user paid by check, give them a $50 discount.
*/
function my_pmpro_discount_with_check( $level ) {
if ( 'check' === $_REQUEST['gateway'] ) {
$level->initial_payment = $level->initial_payment - 50;
// $level->billing_amount = $level->billing_amount - 50; //to update recurring payments too
@dparker1005
dparker1005 / change_account_management_text.php
Created June 13, 2019 12:59
Updated snippet from user which changes 'Account Management' to 'Password Management' on a user's WordPress profile in addition to the snippet's original functionality.
<?php
function my_gettext_membership( $output_text, $input_text, $domain ) {
global $pagenow;
if ( ! is_admin() && 'pmproarc' === $domain ) {
$output_text = preg_replace( '/Yes, renew at.+$/', 'Allow recurring payments using PayPal', $output_text );
}
if ( 'profile.php' === $pagenow ) {
$output_text = str_replace( 'Account Management', 'Password Management', $output_text );
}
@dparker1005
dparker1005 / disable_redirect_to_page.php
Created June 14, 2019 13:36
Prevents wp_redirect to redirect to a specified page.
<?php
/**
* Disable Redirection to Specific Page
*/
function my_wp_redirect($location) {
// TODO: Change '10' to the page id that should not be redirected to
$page_id = 10;
@dparker1005
dparker1005 / pmproama_send_invoice.php
Last active June 14, 2019 16:05
Send 'invoice' email notification when user is added using Add Member Admin Add on.
<?php
// Add this function to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
function pmproama_send_invoice( $user_id ) {
$order = new MemberOrder();
$order->getLastMemberOrder( $user_id );
$pmproemail = new PMProEmail();
$pmproemail->sendInvoiceEmail( get_userdata( $user_id ), $order );
@dparker1005
dparker1005 / cancel_to_free_membership.php
Created June 14, 2019 17:24
When a user's level is changed to not have a membership, instead give them the free level
<?php
function my_pmpro_after_change_membership_level( $level_id, $user_id ) {
// TODO: Replace '1' with level id of free level
$free_level = 1;
if ( $level_id == 0 && empty( $_REQUEST['delete_account'] ) ) {
//cancelling, give them level 1 instead
pmpro_changeMembershipLevel( $free_level, $user_id );
}
@dparker1005
dparker1005 / change_stripe_description.php
Created June 17, 2019 18:38
Changes the order description sent to Stripe from PMPro checkout.
<?php
function my_pmpro_change_stripe_description( $description, $MemberOrder ) {
return 'This is my new description.';
}
add_filter("pmpro_stripe_order_description", "my_pmpro_change_stripe_description", 10, 2);
@dparker1005
dparker1005 / add_personal_data_fields.php
Last active June 21, 2019 19:37
Adds user meta fields to 'Export Personal Data' and 'Delete Personal Data' for GDPR compliance, particularly with Register Helper add-on
<?php
function my_pmpro_add_personal_data_fields( $fields ) {
$fields['meta_name'] = 'Pretty Meta Name';
// Copy the above line for each field you want to include.
return $fields;
}
add_filter( 'pmpro_get_personal_user_meta_fields', 'my_pmpro_add_personal_data_fields' );
function my_pmpro_add_personal_data_fields_to_erase( $fields ) {
@dparker1005
dparker1005 / only_one_discount_code.php
Last active January 22, 2020 13:39
Only allows each user to use one discount code.
<?php
/*
Each user can only use one discount code.
Add this to your active theme's functions.php or a custom plugin.
*/
function my_pmpro_check_discount_code($okay, $dbcode, $level_id, $code)
{
global $wpdb, $current_user;
$codes_used = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->pmpro_discount_codes_uses WHERE user_id = '" . $current_user->ID . "'" );