Forked from ipokkel/my-pmproio-codes-per-level.php
Last active
February 22, 2023 13:14
-
-
Save kimwhite/43d098f8649d68a7b97d989106c30e23 to your computer and use it in GitHub Desktop.
Experimental code to change number of invite codes uses per level.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is an experimental workaround for PMPro Invite Only | |
* to assign a different number of invite codes depending on | |
* the level a user checks out for. | |
* | |
* This experimental code has not be thoroughly tested and is | |
* considered as a "use-at-your-own-risk" code snippet that | |
* is NOT suitable for a live/production environment. | |
* | |
* This workaround uses switching between cases of | |
* the constant and requires the third parameter for | |
* the PMPROIO_CODES constant to be set to true if | |
* and when defining the constant. | |
* | |
* If the constant is not set beforehand it will be defined | |
* in the my_pmproio_codes_per_level function. | |
* | |
* Only levels that are set in the array of the | |
* global variable $pmproio_invite_given_levels will be | |
* given a custom number of invite codes as set in the | |
* $invite_codes_per_level array. | |
* | |
* Usage: | |
* 1. [Optional] define PMPROIO_CODES with the third parameter set to true. | |
* 2. [Required] set the levels that will be given invite codes in $pmproio_invite_given_levels | |
* 3. [Required] Set number of invite codes per level in $invite_codes_per_level | |
*/ | |
// [Optional] Set default value, third parameter must be true. | |
// define( 'PMPROIO_CODES_USES', 1, true ); | |
global $pmproio_invite_required_levels; | |
$pmproio_invite_required_levels = array( 14 ); // Level 14 requires invite code | |
global $pmproio_invite_given_levels; | |
// REQUIRED: Set the levels that will be given invite codes. | |
$pmproio_invite_given_levels = array( 4, 5 ); // Members of these levels are given invite codes | |
function my_pmproio_codes_uses_per_level() { | |
if ( isset( $_REQUEST['level'] ) ) { | |
$level = intval( $_REQUEST['level'] ); | |
global $pmproio_invite_given_levels; | |
if ( ! in_array( $level, $pmproio_invite_given_levels ) ) { | |
return; | |
} | |
if ( ! defined( 'PMPROIO_CODES_USES' ) ) { | |
// Set default value, third parameter must be true. | |
define( 'PMPROIO_CODES_USES', 1, true ); | |
} | |
// REQUIRED: Set number of invite codes per level here. | |
$invite_codes_per_level = array( | |
4 => 2, // Level 4 receives 2 invite codes | |
5 => 3, // Level 5 receives 3 invite codes | |
); | |
foreach ( $invite_codes_per_level as $level_id => $level_codes ) { | |
if ( $level === $level_id ) { | |
/* | |
This will only work if the constant was | |
previously defined once-only with the | |
third parameter set to true | |
*/ | |
define( 'PMPROIO_CODES_USES', $level_codes ); | |
} | |
} | |
} | |
} | |
add_action( 'init', 'my_pmproio_codes_uses_per_level' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment