Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active May 22, 2018 18:39
Show Gist options
  • Save xnau/230371e3d71d2506b1a84acec436de09 to your computer and use it in GitHub Desktop.
Save xnau/230371e3d71d2506b1a84acec436de09 to your computer and use it in GitHub Desktop.
Shows how to limit the number of Participants Database signups
<?php
/**
* Plugin Name: PDB Limit Signups
* Description: Adds a count of the number of Participants Database signups, and prevents new signups
* once a number of registrations has been reached
*/
add_filter( 'pdb-signup_shortcode_output', 'xnau_limit_signups' );
/**
* adds a display of the number of signups and prevents signups once a limit is reached
*
* @param string $output the shourtcode output HTML
* @return string the output HTML
*/
function xnau_limit_signups( $output )
{
// set the signup limit here
$signup_limit = 100;
/*
* get the current count
*
* note: you can add a "filter" attribute to this shortcode if you only want to count a certain kind
* of record: see https://xnau.com/list-shortcode-filters/
*/
$signup_count = do_shortcode('[pdb_total]');
// this is added to the display to show the count
$count_display = '<h3>Current Count: ' . $signup_count . ' Registrations</h3>';
// this is shown once the limit is reached
$overlimit_message = '<h3>' . $signup_count . ' Registrations Have Been Submitted, Registration is Now Closed</h3>';
if ( $signup_count < $signup_limit ) {
// still under the limit, show the count and the signup form
return $count_display . $output;
} else {
// we've hit the limit, show the message without the form
return $overlimit_message;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment