Skip to content

Instantly share code, notes, and snippets.

Avatar

Roland Barker xnau

View GitHub Profile
@xnau
xnau / pdb-one-time-use-pid.php
Last active Mar 25, 2017
demonstrates how to reset the private ID after it is used to open a record edit page
View pdb-one-time-use-pid.php
<?php
/*
* 3-20-17 updated to run on pdb-before_submit_update filer
*
*/
add_filter( 'pdb-before_submit_update', 'pdb_otu_regenerate_pid' );
/**
* regenerates the private id for the current record
*
@xnau
xnau / pdb-shortcode-user-groups.php
Last active Apr 19, 2017
illustrates how to set up the record edit shortcode based on the current user
View pdb-shortcode-user-groups.php
<?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 / multisearch_state_multicheckbox.php
Last active May 13, 2017
Demonstrates setting the search element type for the Participants Database Combo Multi-Search add-on
View multisearch_state_multicheckbox.php
<?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
example of a single template with tabs and excluded groups
View pdb-single-tabs-groups.php
<?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-single-show-age.php
Last active May 20, 2017
A single record template that shows a person's age.
View pdb-single-show-age.php
<?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-list-directory.php
Last active Jun 24, 2017
Shows how to use the PDb_Template class in a custom list template
View pdb-list-directory.php
<?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 / pdb-signup-ipfield.php
Created Jul 5, 2017
demonstrates how to place a dynamic value in a text field in the Participants Database signup form
View pdb-signup-ipfield.php
<?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 ?>" >
@xnau
xnau / list-last-week.php
Last active Aug 8, 2017
Showing the last week's records in Participants Database
View list-last-week.php
<?php
// determine the range of dates to show
$start = date( 'M j,Y', strtotime(  '-7 days' )  ); // the date 7 days ago
$end = date( 'M j,Y' ); // today's date
// now build the shortcode with the date range filter
echo do_shortcode( '[pdb_list filter="date_recorded>=' . $start . '&date_recorded<=' . $end . '" ]' );
?>
@xnau
xnau / list-this-month.php
Last active Aug 8, 2017
Showing results from the current month with Participants Database
View list-this-month.php
<?php
// determine the range of dates to show
$start = date( 'M 01,Y' ); // first day of the current month
$end = date( 'M t,Y' ); // last day of the current month
// now build the shortcode with the date range filter
echo do_shortcode( '[pdb_list filter="date_recorded>=' . $start . '&date_recorded<=' . $end . '" ]' );
?>
@xnau
xnau / pdb-signup-change-default.php
Last active Sep 1, 2017
demonstrates how to set the default value of a field in the template in Participants Database
View pdb-signup-change-default.php
<?php
/**
* bootstrap template for signup form
*
* this demonstrates how to set the default value of a field in the template
*
* outputs a Twitter Bootstrap-compatible form
* http://twitter.github.com/bootstrap/index.html
*
* @version 0.3