Skip to content

Instantly share code, notes, and snippets.

View xnau's full-sized avatar

Roland Barker xnau

View GitHub Profile
@xnau
xnau / pdb-month-sort.php
Last active January 15, 2018 03:27
Demonstrates how to sort by a Participants Database list of month values...or any arbitrary list of values.
<?php
/**
* Plugin Name: PDB Sort By Month
* Description: Demonstrates how to set up an arbitrary list sort in Participants Database
*/
/*
* Important: this assumes that the column you want to put the arbitrary sort on is already
* present in the sort as defined in the shortcode. For instance, in this example, the shortcode
* should have the sort set up like this: [pdb_list orderby="month" order="ASC"] then that sort
* gets replaced by the one we are setting up in this filter.
@xnau
xnau / pdb-record-last-user.php
Last active October 14, 2017 18:30
Shows how to record the user ID of the person editing a Participants Database record
<?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 October 14, 2017 18:41
shows how to use the "approved" field in a Participants Database record to prevent a record from being edited
<?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 October 28, 2017 20:46
Demonstrates how to alter a specific access capability in Participants Database
<?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 November 2, 2017 20:07
Demonstrates how to set up a Participants Database list search that only searches on a single field
<?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-audio-element.php
Created November 19, 2017 20:05
Demonstrates how to show a uploaded audio file in an audio element
<?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
@xnau
xnau / pdb-recipient-list-filter.php
Last active November 30, 2017 03:04
Demonstrates the use of a filter to set up a contact list dropdown in Participants Database Email Extension Kit
<?php
add_filter( 'pdbcptet-recipient_tags', 'xnau_filter_recipients' );
/**
* filters the recipient list
*
* @param array $tag_list all the tags and their values
* @return array
*/
function xnau_filter_recipients( $tag_list )
{
@xnau
xnau / pdb-auto-unapprove.php
Last active December 4, 2017 04:40
Shows how to trigger an automatic unapproval when the account goes past due in Participants Database Member Payments
<?php
add_action( 'pdbmps-status_change_to_past_due', 'xnau_unapprove_record', 10, 2 );
function xnau_unapprove_record ( $status, $data )
{
// this is so we can access a function in the plugin
global $PDb_Member_Payments;
// now set the record to not approved (2nd argument)
$PDb_Member_Payments->approve_record( $data['id'], false );
}
@xnau
xnau / pdb-record-usertype.php
Last active March 22, 2021 04:22
Custom template demonstrating how to show a Participants Database record edit form depending on a value in the record
<?php
/*
* first, check for the value that determines what kind of
* record edit form to show
*/
$type = $this->participant_values['type'];
/*
* now, show the record edit form for that type
*/
@xnau
xnau / pdb-allow-editor-delete.php
Last active December 13, 2017 19:16
Demonstrates the use of a filter to allow Participants Database editors to delete records
<?php
add_filter( 'pdb-access_capability', 'allow_editor_list_delete', 10, 2 );
/**
* alters access privileges
*
* @see https://codex.wordpress.org/Roles_and_Capabilities
*
* @param string $cap current WP capability for the privilege
* @param string $context the privilege requested
* @return string the WP capability to use for the privilege