Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active April 12, 2023 23:22
Show Gist options
  • Select an option

  • Save andrewlimaza/563be9bf3a0b369fa3747ec78cad1513 to your computer and use it in GitHub Desktop.

Select an option

Save andrewlimaza/563be9bf3a0b369fa3747ec78cad1513 to your computer and use it in GitHub Desktop.

Revisions

  1. andrewlimaza revised this gist Nov 14, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pmpro-level-register-example.php
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ function my_pmpro_default_registration_level($user_id) {

    $custom_level = array(
    'user_id' => $user_id,
    'membership_id' => $level_id,
    'membership_id' => 2,
    'code_id' => '',
    'initial_payment' => $level->initial_payment,
    'billing_amount' => $level->billing_amount,
  2. andrewlimaza created this gist Nov 14, 2018.
    30 changes: 30 additions & 0 deletions pmpro-level-register-example.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    <?php

    // Adjusted from https://www.paidmembershipspro.com/give-users-a-default-membership-level-at-registration/

    //Disables the pmpro redirect to levels page when user tries to register
    add_filter("pmpro_login_redirect", "__return_false");

    function my_pmpro_default_registration_level($user_id) {

    $level = pmpro_getLevel( 2 );

    $custom_level = array(
    'user_id' => $user_id,
    'membership_id' => $level_id,
    'code_id' => '',
    'initial_payment' => $level->initial_payment,
    'billing_amount' => $level->billing_amount,
    'cycle_number' => $level->cycle_number,
    'cycle_period' => $level->cycle_period,
    'billing_limit' => $level->billing_limit,
    'trial_amount' => $level->trial_amount,
    'trial_limit' => $level->trial_limit,
    'startdate' => "'" . current_time('mysql') . "'",
    'enddate' => date("Y-m-d", strtotime("+" . $level->expiration_number . " " . $level->expiration_period)),
    );

    pmpro_changeMembershipLevel($custom_level, $user_id);

    }
    add_action('user_register', 'my_pmpro_default_registration_level');