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 / Update-Category-Membership-Level-Restrictions-or-Foreign-Languages-In-PMPro
Created July 1, 2015 18:09
Update Category Membership Level Restrictions for Foreign Languages In PMPro
/**
*
* @param int $save_id
* Updates equivalent membership category in other languages when saving levels.
* Not suitable for large number of languages.
*/
function update_level_categories_for_all_languages($save_id)
{
$level_cat_ids = pmpro_getMembershipCategories($save_id);
$updated_level_cat_ids = $level_cat_ids;
@greathmaster
greathmaster / email_inactive_users.php
Last active June 28, 2016 15:44
Email Inactive Users
add_action( 'init', 'register_daily_email_inactive_members_email');
// Function which will register the event
function register_daily_email_inactive_members_email()
{
// Make sure this event hasn't been scheduled
if( !wp_next_scheduled( 'email_inactive_members' ) ) {
// Schedule the event
wp_schedule_event( time(), 'daily', 'email_inactive_members' );
}
@greathmaster
greathmaster / pmpro-email-password.php
Created September 25, 2015 23:47
Send password through email after checkout
/*
* Send members password through email after checkout.
* Use PMPro Email Templates shortcode !!password!! in checkout emails.
* Remove password fields using custom checkout template to auto generate password.
*/
function my_generate_passwords()
{
if(!empty($_REQUEST['username']) && empty($_REQUEST['password']))
{
$_REQUEST['password'] = pmpro_getDiscountCode() . pmpro_getDiscountCode(); //using two random discount codes
@greathmaster
greathmaster / pmpro-restrict-levels.php
Created October 13, 2015 00:36
Only show levels on levels page which the original referral page belonged to.
/*
Only show levels on level page which the original content belonged to. For example if a site has 3 levels: Bronze, Silver, Gold and
a post is restricted to Silver and Gold, clicking on the "Register" button will lead them to the levels page showing only Silver and Gold levels.
To use: employ the shortcode [my_level_link] under Memberships >> Advanced >> Message for Logged-out Users (or Message for Logged-in Non-members)
Ex:
This content is for !!levels!! members only.<br /><a href="http://example.com/wp-login.php">Log In</a> <a href="[my_level_link]">Register</a>
*/
@greathmaster
greathmaster / pmpro-wpml-email-template-shortcode.php
Created October 14, 2015 16:44
Add PMPro email shortcode !!wpml_pmpro_custom_email_template!! to change email content based on language
function my_pmpro_email_data($data, $email)
{
if(ICL_LANGUAGE_CODE == "fr")
$data['wpml_pmpro_custom_email_template'] = "This is French";
elseif(ICL_LANGUAGE_CODE == "en")
$data['wpml_pmpro_custom_email_template'] = "This is English";
return $data;
}
@greathmaster
greathmaster / pmpro-assign-cancellation-level-on-status.php
Last active March 12, 2019 10:31
Assign different levels to members if cancelling or expiring
/*
* When users cancel, assign them a level based on their status. See list of available status':
* http://www.paidmembershipspro.com/2015/03/statuses-available-in-the-pmpro_memberships_users-table-updated-member-history-add-on/
*/
function my_pmpro_after_change_membership_level($level_id, $user_id)
{
global $wpdb;
if($level_id == 0)
{
@greathmaster
greathmaster / pmpro-pre-select-paypal-express.php
Created October 30, 2015 16:52
Pre select the PayPal Express payment option (vs credit card) when using PayPal Website Payments Pro
/*
* Pre select the PayPal Express payment option (vs credit card) when using PayPal Website Payments Pro
*/
function pre_select_paypal()
{?>
<script>
jQuery(document).ready(function(){jQuery("input[name=gateway][value='paypalexpress']").click();});
</script><?php
}
@greathmaster
greathmaster / pmpro-set-custom-paypal-cancel-url.php
Last active November 19, 2020 07:36
Sets a custom Cancel URL for PayPal transactions
//From: http://www.paidmembershipspro.com/forums/topic/paypal-express-change-the-cancel-and-return-url/
//Created by user @ultione
add_filter( "pmpro_set_express_checkout_nvpstr", "custom_set_paypal_express_cancel_url", 10, 2 );
function custom_set_paypal_express_cancel_url ( $nvpStr, $order ) {
parse_str( $nvpStr, $payment_arr );
$level_id = pmpro_getLevel( 'membership_level_name' );
if ( ! empty( $level_id ) ) {
@greathmaster
greathmaster / pmpro-display-membership-level-for-posts.php
Created November 5, 2015 16:18
Displays membership level ids a post is assigned to under the manage posts page.
function my_pmpro_post_membership_levels_header($defaults)
{
$defaults['membership_levels'] = 'Membership Levels';
return $defaults;
}
function my_pmpro_post_membership_levels($column_name, $post_ID)
{
if ($column_name == 'membership_levels')
{
@greathmaster
greathmaster / pmpro-show-next-payment-date.php
Created November 5, 2015 17:24
Echo the next payment date for a member.
function my_pmpro_show_next_payment_date()
{
$next_date = pmpro_next_payment(NULL, "success", "date_format");
if($next_date)
echo $next_date;
else
echo "---";
}