Skip to content

Instantly share code, notes, and snippets.

@messica
Created October 20, 2015 15:58
Show Gist options
  • Select an option

  • Save messica/b60bffab6db97a4f0d8c to your computer and use it in GitHub Desktop.

Select an option

Save messica/b60bffab6db97a4f0d8c to your computer and use it in GitHub Desktop.
Generate invite codes for all users with a certain membership level.
<?php
/*
* Generate invite codes for all users with a certain membership level.
*/
function my_init() {
if ( ! empty( $_REQUEST['create_invites'] ) && current_user_can( 'manage_options' ) ) {
global $wpdb;
// change level here
$level_id = 1;
// get all users with specific membership level
$sql = "SELECT user_id FROM $wpdb->pmpro_memberships_users WHERE membership_id=" . $level_id . " AND status='active'";
$users = $wpdb->get_col($sql);
// create codes for them
foreach($users as $user_id)
pmproio_createInviteCodes($user_id);
}
}
add_filter( 'init', 'my_init' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment