Skip to content

Instantly share code, notes, and snippets.

View greathmaster's full-sized avatar
🧐

Hersha Venkatesh greathmaster

🧐
  • San Francisco, Bay Area
View GitHub Profile
@greathmaster
greathmaster / pmpro-save-ip-and-country-after-checkout.php
Created May 7, 2019 00:08
Save IP address and country to user meta on checkout in PMPro. Requires the Geo IP Detect plugin to be installed and activated
/*
Save IP address and country to user meta on checkout in PMPro.
Requires the Geo IP Detect plugin (https://wordpress.org/plugins/geoip-detect/)
to be installed and activated
*/
function save_ip_and_country_after_checkout($user_id, $morder)
{
$country = '';
$ip = '';
@greathmaster
greathmaster / pmpro-display-membership-levels-for-posts.php
Created April 23, 2019 19:23
PMPro Display membership levels for posts and pages
function pmprobe_manage_posts_columns( $columns, $post_type)
{
$post_types = apply_filters('pmprobe_post_type_columns', array('post'));
if (in_array($post_type, $post_types))
{
$columns[ 'pmpro_membership_levels' ] = 'Membership Levels';
}
return $columns;
@greathmaster
greathmaster / pmpro-confirmation-url-redirect-with-discount-code.php
Created April 9, 2019 20:32
PMPro confirmation URL redirection based on discount code AND membership level
function my_pmpro_confirmation_url($rurl, $user_id, $pmpro_level)
{
global $wpdb;
$code = $wpdb->get_row("SELECT * FROM $wpdb->pmpro_discount_codes WHERE id = $pmpro_level->code_id LIMIT 1");
/*
Example of $code content:
object(stdClass) {
public 'id' => string '7' (length=1)
public 'code' => string 'SC916E8F9CC' (length=11)
@greathmaster
greathmaster / pmpro-sponsored-members-workaround-for-expiring-discount-code.php
Created April 8, 2019 18:15
PMPro Sponsored Members workaround for expiring discount code.
/*
If a parent account checks out and distributes the discount code to 3/10 of its child accounts,
the parent account should still have 7 remaining. This 7 remaining uses should persist after a
renewal by the parent account.
By default the discount codes have an expiration period of one year.
Even if they renew, the discount code expiration date is not updated.
We are hard coding the start and end date of the discount code itself in the function pmprosm_createSponsorCode()
@greathmaster
greathmaster / pmpro-advanced-levels-shortcode-highlight-level.css
Created March 19, 2019 22:07
PMPro Advanced Levels Shortcode CSS to highlight a particular level in "compare table" mode.
.pmpro_level-highlight{
background-color:#ADD8E6 !important
}
.pmpro_level-current{
background-color:#ADD8E6 !important
}
/*
Remove "Membership Level" on the BuddyPress profile page, and instead only show the membership level name
*/
function my_pmpro_bp_show_level_on_bp_profile() {
if ( !function_exists('pmpro_getMembershipLevelForUser') ) {
return;
}
@greathmaster
greathmaster / directory.php
Created February 17, 2019 03:46
Custom PMPro Member Directory templates which truncate profile and directory titles
<?php
/*
This shortcode will display the members list and additional content based on the defined attributes.
*/
function pmpromd_shortcode($atts, $content=null, $code="")
{
// $atts ::= array of attributes
// $content ::= text within enclosing form of shortcode element
// $code ::= the shortcode found, when == callback name
// examples: [pmpro_member_directory show_avatar="false" show_email="false" levels="1,2"]
@greathmaster
greathmaster / pmpro-restrict-posts-based-on-parent-category.php
Created February 14, 2019 21:59
Restrict membership access based on parent category
/*
Restrict membership access based on parent category
*/
function category_restrictions($hasaccess, $mypost, $myuser, $post_membership_levels)
{
global $post, $current_user;
$categories = wp_get_post_categories($mypost->ID);
$restrict = false;
@greathmaster
greathmaster / pmpro-restrict-posts-based-on-parent-category.php
Created February 14, 2019 21:59
Restrict membership access based on parent category
/*
Restrict membership access based on parent category
*/
function category_restrictions($hasaccess, $mypost, $myuser, $post_membership_levels)
{
global $post, $current_user;
$categories = wp_get_post_categories($mypost->ID);
$restrict = false;
/*
Add a "How did you hear about us?" field Membership Checkout for new members only.
Display the field for admins-only in the profile and in the Members List CSV export.
*/
function my_pmpro_how_hear_fields() {
global $current_user;
if(class_exists( 'PMProRH_Field' ) && (!pmpro_hasMembershipLevel() || current_user_can( 'edit_users' ) ) ) {
pmprorh_add_checkout_box( 'additional', 'Additional Information' );