Skip to content

Instantly share code, notes, and snippets.

Avatar

Roland Barker xnau

View GitHub Profile
@xnau
xnau / pdb-list-special.php
Last active Sep 12, 2017
Demonstrates how to use the PDb_Template class in a custom list template for Participants Database
View pdb-list-special.php
<?php
/*
template for participants list shortcode output
this template demonstrates a "table-less" reponsive layout for the list of records
using the PDb_Template class for each record
*/
?>
@xnau
xnau / pdb-list-detail-link.php
Created Sep 23, 2017
Demonstrates how to add the detail link to several fields in the Participants Database list display
View pdb-list-detail-link.php
@xnau
xnau / set_private_id_length.php
Last active Sep 30, 2017
shows how to change the Participants Database private id length
View set_private_id_length.php
<?php
/**
* Plugin Name: Participants Database Set Private ID Length
* Description: sets a custom length for the private ID
*/
// set the private ID length to 9
add_filter( 'pdb-private_id_length', function ( $length ) { return 9; } );
@xnau
xnau / pdb-iframe-element.php
Last active Oct 5, 2017
Demonstrates how to create a Participants Database form element that displays an iframe
View pdb-iframe-element.php
<?php
/**
* Plugin Name: PDB Iframe Form Element
* Description: Demonstrates how to create a Participants Database form element that displays an iframe
*
*/
add_filter( 'pdb-set_form_element_types', 'pdb_iframe_register_element' );
add_action( 'pdb-form_element_build_iframe','pdb_iframe_element_building_function');
add_filter( 'pdb-before_display_form_element','pdb_iframe_element_value_display_function', 10, 2);
@xnau
xnau / pdb-record-last-user.php
Last active Oct 14, 2017
Shows how to record the user ID of the person editing a Participants Database record
View pdb-record-last-user.php
<?php
add_action( 'pdb-after_submit_update', 'xnau_record_last_user' );
/**
* record the user who created or edited a record in the backend
*
* @see https://codex.wordpress.org/Function_Reference/wp_get_current_user
*
* @param array $record the record data
*/
function xnau_record_last_user( $record )
@xnau
xnau / pdb-prevent-unapproved-record-edit.php
Created Oct 14, 2017
shows how to use the "approved" field in a Participants Database record to prevent a record from being edited
View pdb-prevent-unapproved-record-edit.php
<?php
// if the record is not approved, they cannot edit the record.
// you can easily adapt this to any other checkbox field so you can use that field to prevent editing
add_filter( 'pdb-check_submission', function() {
if ( !is_admin() && $_POST['action'] === 'update' ) {
$record = Participants_Db::get_participant( $_POST['id']);
// if the field has a value of "yes" allow editing
// if it is any other value, editing will not be allowed
return $record['approved'] === 'yes';
}
@xnau
xnau / pdb-access_filter.php
Last active Oct 28, 2017
Demonstrates how to alter a specific access capability in Participants Database
View pdb-access_filter.php
<?php
add_filter( 'pdb-access_capability', 'set_pdb_access_controls', 10, 2 );
/*
* @param string $cap the current capability level that gives access to the function named in $context
* @param string $context the specific action that is being tested
* @return string the capability that is allowed to access the function named in $context
*/
function set_pdb_access_controls( $cap, $context )
{
// set the access capability for a specific action
@xnau
xnau / pdb-list-single-search.php
Created Nov 2, 2017
Demonstrates how to set up a Participants Database list search that only searches on a single field
View pdb-list-single-search.php
<?php
/*
this template demonstrates how to set up a simple search that only searches on a single field: city
to change which field is searched on, look at line 50, change the "value" of that hidden field
*/
?>
<div class="wrap <?php echo $this->wrap_class ?>" id="<?php echo $this->list_anchor ?>">
@xnau
xnau / pdb-single-gmap.php
Last active Nov 3, 2017
Demontrates a single record template for Participants Database that includes a location map for the listing
View pdb-single-gmap.php
<?php
/*
* template for showing a google map in a single record template
*
*/
/*
* this is the name of the group the address fields are in
*
* change this to match the name of the group that contains your address fields
*/
@xnau
xnau / pdb-audio-element.php
Created Nov 19, 2017
Demonstrates how to show a uploaded audio file in an audio element
View pdb-audio-element.php
<?php
/**
* Plugin Name: PDB Audio Element
* Description: Demonstrates how to show an uploaded audio file in an audio element
*
*/
add_filter( 'pdb-before_display_form_element','pdb_audio_element_display_function', 10, 2);
/**
* displays the audio element