Skip to content

Instantly share code, notes, and snippets.

View xnau's full-sized avatar

Roland Barker xnau

View GitHub Profile
@xnau
xnau / pdb-one-time-use-pid.php
Last active March 25, 2017 18:30
demonstrates how to reset the private ID after it is used to open a record edit page
<?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 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 / 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-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-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 / 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 ?>" >
@xnau
xnau / list-last-week.php
Last active August 8, 2017 18:49
Showing the last week's records in Participants Database
<?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 August 8, 2017 18:53
Showing results from the current month with Participants Database
<?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 September 1, 2017 18:26
demonstrates how to set the default value of a field in the template in Participants Database
<?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