Skip to content

Instantly share code, notes, and snippets.

View ipokkel's full-sized avatar

Theuns Coetzee ipokkel

View GitHub Profile
@kimcoleman
kimcoleman / memberlite_sass_classes.scss
Created April 15, 2019 15:25
Starter move to use Sass for Memberlite in place of header <style> tag.
/* Named colors are accessed from theme mods and selectors from "memberlite_defaults" global */
$bgcolor_site_navigation_elements {
background: $bgcolor_site_navigation;
}
$color_site_navigation_elements {
color: $color_site_navigation;
}
$color_link_color_elements {
@andrewlimaza
andrewlimaza / user-create-dev-tool.php
Last active April 25, 2019 13:51
Generate users and assign a membership level using PHP [Paid Memberships Pro]
<?php
/**
* Use this script to generate users on the fly and assign them a membership level.
* Add ?pmpro_create_users=X where X is how many users you want to create.
* Adjust the $level_id for which level ID you want to give to users.
* Creates a user with username "user1234" for example.
*/
function pmpro_create_my_own_users() {
if ( $_REQUEST['pmpro_create_users'] ) {
@andrewlimaza
andrewlimaza / custom-field-register-helper-checkout-email.php
Last active May 28, 2019 05:30
Add custom field to Paid Memberships Pro Checkout Email using Register Helper
<?php
/**
* This will check for !!company_name!! in the emails body and replace it with the 'company_name' metadata (created by Register Helper).
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_email_body( $body, $email ) {
//only checkout emails
if ( false !== strpos( $email->template, "checkout" ) ) {
@longfeixiang
longfeixiang / isSorted.js
Created June 3, 2019 21:17
[是否是有序数组] #npm
const defaultComparator = (a, b) => a - b
const checkSort = (array, comparator = defaultComparator) => {
if (!Array.isArray(array)) {
throw new TypeError('Expected Array, got ' + (typeof array))
}
return array.length <= 1 || array.some((k, i) => {
return comparator(k, array[i - 1]) > 0
})
}
@andrewlimaza
andrewlimaza / pmpro_days_left_example.php
Last active June 27, 2019 05:52
Add days left to new membership level purchase for Paid Memberships Pro WooCommerce.
<?php
/**
* Calculate days remaining for current membership level and add it to new subscription.
* Only works for PMPro WooCommerce Integration
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* www.paidmembershipspro.com
*/
function pmprowoo_add_days_to_level( $level_array ) {
$level_obj = pmpro_getLevel($level_array['membership_id']);
@messica
messica / my_pmprorh_init.php
Created December 31, 2018 18:26
Register Helper: wp_editor() Field Example
<?php
/**
* Register Helper Fields
*/
function my_pmprorh_init() {
if(!function_exists('pmprorh_add_registration_field')) return;
$fields = array();
@messica
messica / pmpro_remove_trial_for_existing_members.php
Created June 14, 2019 00:30
Remove trial if user has cancelled order for same level.
<?php
/**
* Remove trial if user has cancelled order for same level.
* Add code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function pmpro_remove_trial_for_existing_members( $level ) {
$order = new MemberOrder();
if ( $order->getLastMemberOrder( null, 'cancelled', $level->id ) ) {
$level->trial_limit = 0;
@LMNTL
LMNTL / pmprozapier_email_after_change_level.php
Last active August 27, 2019 07:41
Send WP new user email and PMPro admin change email after registering a member through a PMPro Zapier zap
// send WP new user email and PMPro admin change email after registering a member through a PMPro Zapier zap
// requires Paid Memberships Pro and PMPro Zapier add on
function my_pmpro_zapier_email_after_change_level( $level_id, $user_id ){
if( isset( $_SERVER["REQUEST_URI"] ) && ( strpos( $_SERVER["REQUEST_URI"], "pmpro_zapier_webhook" ) !== false ) ){
$user = get_userdata( $user_id );
$pmpro_email = new PMProEmail();
$pmpro_email->sendAdminChangeEmail( $user );
wp_new_user_notification( $user_id, null, 'both' );
}
@kimcoleman
kimcoleman / redirect_bbpress_no_access_levels_page.php
Created August 30, 2019 18:07
Redirect users without access to a single bbPress forum to the Membership Levels page.
<?php
/**
* Redirect users without access to a single bbPress forum to the Membership Levels page.
*
*/
function redirect_bbpress_no_access_levels_page( $redirect_to, $forum_id ) {
global $pmpro_pages;
$redirect_to = get_permalink( $pmpro_pages['levels'] );
@kimcoleman
kimcoleman / bcc_on_member_email_headers.php
Created December 20, 2018 18:57
Bcc additional email addresses on all PMPro emails sent to the member.
<?php
/*
* Bcc additional email addresses on all PMPro emails sent to the member.
*/
function bcc_on_member_email_headers( $headers, $email ) {
//bcc emails not already going to admin_email
if ( $email->email != get_bloginfo( 'admin_email' ) ) {
//add bcc
$headers[] = "Bcc:" . "otheremail@domain.com,anotheremail@domain.com";
}