Last active
February 10, 2018 18:45
-
-
Save xnau/afcab5f1cc4f0d9f0a5b59124d2e4060 to your computer and use it in GitHub Desktop.
demonstrates how to control the display of some fields in a Participants Database record list based on the value of another field
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 | |
/* | |
* | |
* template for participants list shortcode output | |
* | |
* demonstrates how to control the display of some fields based on the value of another field | |
* | |
*/ | |
// these are the fields that we are controlling the display of | |
$skip_fields = array( 'phone', 'email' ); | |
// this is the checkbox field that determines whether the fields should be shown or not | |
// it must be configured to save a value of 1 when checked | |
$skip_control = 'ok_to_show'; | |
?> | |
<div class="wrap <?php echo $this->wrap_class ?>" id="<?php echo $this->list_anchor ?>"> | |
<?php | |
/* | |
* SEARCH/SORT FORM | |
* | |
* the search/sort form is only presented when enabled in the shortcode. | |
* | |
*/ | |
$this->show_search_sort_form(); | |
/* LIST DISPLAY */ | |
/* | |
* NOTE: the container for the list itself (excluding search and pagination | |
* controls) must have a class of "list-container" for AJAX search/sort to | |
* function | |
*/ | |
?> | |
<table class="wp-list-table widefat fixed pages list-container" > | |
<?php | |
// print the count if enabled in the shortcode | |
$this->print_list_count($wrap_tag = false); | |
?> | |
<?php if ( $record_count > 0 ) : // print only if there are records to show ?> | |
<thead> | |
<tr> | |
<?php /* | |
* this function prints headers for all the fields | |
* replacement codes: | |
* %2$s is the form element type identifier | |
* %1$s is the title of the field | |
*/ | |
$this->print_header_row( '<th class="%2$s" scope="col">%1$s</th>' ); | |
?> | |
</tr> | |
</thead> | |
<tbody> | |
<?php while ( $this->have_records() ) : $this->the_record(); // each record is one row ?> | |
<?php | |
// set up the template object | |
$record = new PDb_Template($this) ?> | |
<tr> | |
<?php while( $this->have_fields() ) : $this->the_field(); // each field is one cell ?> | |
<?php | |
$show = true; // by default, we show all the fields | |
if ( in_array( $this->field->name, $skip_fields ) && $record->values[$skip_control] != '1' ) { | |
// we'll be skipping these fields | |
$show = false; | |
} | |
?> | |
<td class="<?php echo $this->field->name ?>-field"> | |
<?php if ( $show ) : ?> | |
<?php $this->field->print_value() ?> | |
<?php endif ?> | |
</td> | |
<?php endwhile; // each field ?> | |
</tr> | |
<?php endwhile; // each record ?> | |
</tbody> | |
<?php else : // if there are no records ?> | |
<tbody> | |
<tr> | |
<td><?php if ($this->is_search_result) echo Participants_Db::$plugin_options['no_records_message'] ?></td> | |
</tr> | |
</tbody> | |
<?php endif; // $record_count > 0 ?> | |
</table> | |
<?php | |
/* | |
* this shortcut function presents a pagination control with default layout | |
*/ | |
$this->show_pagination_control(); | |
?> | |
</div> |
This plugin assumes that you have a checkbox field (named "ok_to_show" in this example) that is for the user to select if they are allowing their info to display. It should be set with a "values" parameter of 1,0
You can default it to 1 if you want the info to show by default.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can download this file as a zip, then unpack it and upload it to your custom template location.
Please read this page if you don't know where to upload or how to use a custom template:
Using Participants Database Custom Templates