Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@kimcoleman
kimcoleman / my_first_last_display_name.php
Last active April 16, 2021 19:05
Set Display Name on Membership Checkout and for BuddyPress Name field.
<?php
/**
* Set Display Name on Membership Checkout and for BuddyPress Name field.
*/
function my_first_last_display_name( $user_id, $morder ) {
// Get user's first and last name.
$first_name = get_user_meta( $user_id, 'first_name', true );
$last_name = get_user_meta( $user_id, 'last_name', true );
@kimcoleman
kimcoleman / my_pmpro_require_canada_level_8.php
Created April 30, 2019 01:00
Require Members to live in Canada to checkout for a specific level.
/**
* Require Members to live in Canada to checkout for a specific level.
*/
function my_pmpro_require_canada_level_8( $value ) {
global $pmpro_level;
$bcountry = $_REQUEST['bcountry'];
if ( ( $pmpro_level->id == '8' ) && ( $bcountry != 'CA' ) ) {
global $pmpro_msg, $pmpro_msgt;
@kimcoleman
kimcoleman / duplicate_require_membership_level_1_to_level_2.sql
Last active March 29, 2021 03:00
Example SQL to duplicate restrictions for level ID 1 to also restrict for level ID 2
#Example SQL to duplicate restrictions for level ID 1 to also restrict for level ID 2
INSERT IGNORE INTO wp_pmpro_memberships_pages (membership_id, page_id)
SELECT '2', page_id FROM wp_pmpro_memberships_pages WHERE membership_id = 1;
@kimcoleman
kimcoleman / restrict_posts_level_2.sql
Last active March 29, 2021 02:59
Example SQL to add restriction to all 'posts' for Level ID 2. Change level ID for your needs.
#Example SQL to add restriction to all 'posts' for Level ID 2. Change level ID for your needs.
INSERT IGNORE INTO wp_pmpro_memberships_pages (membership_id, page_id)
SELECT 2, ID FROM wp_posts WHERE post_type = 'post';
@kimcoleman
kimcoleman / free_level_change_pmpro_level_cost_text.php
Last active April 16, 2021 23:46
Remove or change the level cost for free levels.
<?php
/**
* Remove or change the level cost for free levels.
*/
function free_level_change_pmpro_level_cost_text( $text, $level ) {
if ( pmpro_isLevelFree( $level ) ) {
return '';
} else {
return $text;
}
@kimcoleman
kimcoleman / custom_css_discount_code_cost_text.css
Created May 15, 2019 15:27
Custom css for discount code cost text to avoid class jumbling.
<span class="pricecustomtext">
<span class="standardcoupon">
<span class="pricediscount">
<span class="pricediscounttitle">62% OFF!</span>
<span class="pricediscountcoupon">Groupon Deal</span>
</span><br>
<span class="pricetotal"><span class="priceoriginal">$32</span>$12</span>
<span class="pricerenewal">Renews in 3 months at $32/quarter.<br> Cancel anytime.</span>
</span>
</span>
@kimcoleman
kimcoleman / my_pmpro_email_custom_login_link_text.php
Created May 17, 2019 16:18
Modify the text of the login link in all membership checkout confirmation emails.
@kimcoleman
kimcoleman / hide_post_thumbnail_on_restricted_content.php
Last active May 27, 2019 05:44
Do not return the post thumbnail (featured image) on restricted content when viewed by a non-member.
<?php
/**
* Do not return the post thumbnail (featured image) on restricted content when viewed by a non-member.
*
*/
function hide_post_thumbnail_on_restricted_content( $html, $post_id, $post_image_id ) {
if ( function_exists( 'pmpro_has_membership_access' ) ) {
// Check if the user has access to the post.
$hasaccess = pmpro_has_membership_access( $post_id );
@kimcoleman
kimcoleman / hide_gallery_events_filter_post_types.php
Last active April 7, 2021 03:45
Hide the 'gallery' CPT from searches and archives if membership is required to access.
<?php
/**
* Hide the 'gallery' CPT from searches and archives if membership is required to access.
*
*/
function hide_gallery_events_filter_post_types( $post_types ) {
$post_types[] = 'gallery';
return $post_types;
}
add_filter( 'pmpro_search_filter_post_types', 'hide_gallery_events_filter_post_types' );
@kimcoleman
kimcoleman / pmproc_create_random_orders.php
Created May 29, 2019 00:21
Create random orders across a time period for all active members on your site. Useful for demos.
/**
* Create random orders for all members.
* visit /wp-admin/?create_random_orders=1 to generate orders, then remove this code
* Warning, this can time out or slow your server if you have many members or a long timeframe.
*/
function pmproc_create_random_orders() {
global $wpdb;
if ( empty( $_REQUEST['create_random_orders'] ) ) {
return;