Created
October 23, 2014 02:31
-
-
Save spivurno/73ad5599740a20521165 to your computer and use it in GitHub Desktop.
(Admin-only) Display how many spots are left in the choice label when using the GP Limit Choices perk
This file contains 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 | |
/** | |
* (Admin-only) Display how many spots are left in the choice label when using the GP Limit Choices perk | |
* http://gravitywiz.com/gravity-perks/ | |
*/ | |
add_filter( 'gplc_pre_render_choice', 'my_add_how_many_left_message', 10, 4 ); | |
function my_add_how_many_left_message( $choice, $exceeded_limit, $field, $form ) { | |
if( ! current_user_can( 'administrator' ) ) { | |
return $choice; | |
} | |
$choice_counts = GWLimitChoices::get_choice_counts( $form['id'], $field ); | |
$count = rgar( $choice_counts, $choice['value'] ) ? rgar( $choice_counts, $choice['value'] ) : 0; | |
$limit = rgar($choice, 'limit'); | |
$how_many_left = $limit - $count; | |
$message = "($how_many_left spots left)"; | |
$choice['text'] = $choice['text'] . " $message"; | |
return $choice; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, I was referring to http://snippi.com/s/s7e4mz2 rather than https://gist.github.com/spivurno/7858140