Skip to content

Instantly share code, notes, and snippets.

View xnau's full-sized avatar

Roland Barker xnau

View GitHub Profile
@xnau
xnau / pdb-shortcode-user-groups.php
Last active April 19, 2017 19:54
illustrates how to set up the record edit shortcode based on the current user
<?php
/*
* this code assumes that there is some value in the participant's record that
* determines what groups they will have access to
*/
$pid = filter_input( INPUT_GET, 'pid', FILTER_SANITIZE_STRING );
$id = Participants_Db::get_participant_id( $pid );
if ( $id ) :
$user_record = Participants_Db::get_participant( $id );
// change this to use whatever value it is you need to determine what groups to show
@xnau
xnau / pdb-list-directory.php
Last active June 24, 2017 02:11
Shows how to use the PDb_Template class in a custom list template
<?php
/*
template for participants list shortcode output demonstrating a directory-style responsive layout
this template demonstrates a "table-less" reponsive layout for the list of records
*/
?>
<div class="wrap <?php echo $this->wrap_class ?>" id="<?php echo $this->list_anchor ?>">
@xnau
xnau / random_number_id.php
Last active June 8, 2018 18:03
shows how to replace the normal private ID generation with a 6-digit number
<?php
// filter the private id generation to supply a numeric private ID
add_filter( 'pdb-generate_private_id', 'generate_random_number_id');
function generate_random_number_id( $private_id )
{
// get a 6-digit random number
$numeric_id = rand( 100000, 999999 );
// send it back tot he plugin
return $numeric_id;
}
@xnau
xnau / multisearch_state_multicheckbox.php
Last active May 13, 2017 08:33
Demonstrates setting the search element type for the Participants Database Combo Multi-Search add-on
<?php
// this sets the type of control to use when building the multi search control
add_filter( 'pdb-combo-multisearch-search_control_type', 'xnau_set_search_control_type', 10, 2 );
// this sets the field type for the purpose of adding the search as a query filter
add_filter( 'pdbmps-field-filter', 'xnau_set_search_control_type', 10, 2 );
function xnau_set_search_control_type( $form_element, $field )
{
if ( $field->name === 'state' ) {
$form_element = 'multi-checkbox';
}
@xnau
xnau / pdb-single-tabs-groups.php
Last active May 15, 2017 18:07
example of a single template with tabs and excluded groups
<?php
/*
* example of a single template with tabs and excluded groups
*
*
*/
// first establish the set og group to show for this record type
if ( $this->participant_values['type'] == 'customer' ) {
$allowed_groups = array( 'main', 'address', 'personal' );
@xnau
xnau / pdb-record-typeselect.php
Last active March 22, 2021 04:25
Demonstrates how to show a different Participants Database record edit form depending on a value in the record.
<?php
// determine the approval status of the record and show the appropriate shortcode
switch ( $this->participant_values['approved'] ) {
case 'yes' :
echo do_shortcode( '[pdb_record groups="main,address,personal"]' );
break;
case 'no':
echo do_shortcode( '[pdb_record groups="main"]' );
@xnau
xnau / pdb-list-csv.php
Last active December 8, 2020 18:55
Demonstrates how to add a CSV download form to a Participants database List template
<?php
/*
*
* template for participants list shortcode output including a CSV download form
*
*/
?>
<div class="wrap <?php echo $this->wrap_class ?>" id="<?php echo $this->list_anchor ?>">
<?php
/*
@xnau
xnau / pdb-single-show-age.php
Last active May 20, 2017 18:20
A single record template that shows a person's age.
<?php
/*
* default template for displaying a single record
*
* This one calculates a person's age from a field named "birthdate" and shows it in a field named "age"
*/
$record = new PDb_Template( $this );
$date_field = 'birthdate';
$age_field = 'age';
?>
@xnau
xnau / pdb-single-edit-link.php
Last active March 24, 2021 09:57
demonstrates how to add a record edit link to a single record template
@xnau
xnau / pdb-signup-ipfield.php
Created July 5, 2017 18:21
demonstrates how to place a dynamic value in a text field in the Participants Database signup form
<?php
/*
* custom template for signup form
*
*/
// this is the name of the field you want to insert the value into
$ip_field = 'user_ip';
?>
<div class="wrap <?php echo $this->wrap_class ?>" >