Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active July 19, 2022 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/4457a42e49ba66a920875dcc549c8b53 to your computer and use it in GitHub Desktop.
Save xnau/4457a42e49ba66a920875dcc549c8b53 to your computer and use it in GitHub Desktop.
Demonstrates how to define a custom template component set for the Participant Log add-on
<?php
/**
* Plugin Name: PDB Custom Log Template
* Description: provides a customized template for the Participant Log display
*/
/**
* demonstrates how to provide a custom template for a Participant Log display
*
* @package WordPress
* @subpackage Participants Database Plugin
* @author Roland Barker <webdesign@xnau.com>
* @copyright 2022 xnau webdesign
* @license GPL3
* @version 0.1
* @link http://xnau.com/wordpress-plugins/
* @depends
*/
class pdb_custom_log_template {
/**
* @var string defines the identifier for the custom template
*/
const identifier = 'custom';
/**
* sets up the filters
*/
public function __construct()
{
add_filter( 'pdblog-template_options', array( $this, 'add_template_name' ) );
add_filter( 'pdblog-html_templates', array( $this, 'add_custom_template' ) );
}
/**
* adds the custom template's name
*
* @param array $template_names
* @return array
*/
public function add_template_name( $template_names )
{
// this defines the display name of the template
$template_names[self::identifier] = 'Custom';
return $template_names;
}
/**
* adds the custom template components
*
* @param array $templates
* @return array
*/
public function add_custom_template( $templates )
{
$templates[self::identifier] = $this->custom_template();
return $templates;
}
/**
* provides the custom template components
*
* this is simply a copy of the "responsive" template from the Participant Log
* plugin, which can be modified for the custom template
*
* @return array
*/
private function custom_template()
{
return array(
'display_base' => 'block',
'record_entry_list_wrap' => '<div class="pdb-record-log">%s</div>',
'record_entry_input_wrap' => '<div id="%s" class="pdb-record-log-input pdblog-template-responsive" data-log="%s" data-record_id="%s" style="display:none" >%s<form enctype="multipart/form-data" method="post">%s</form></div>',
'entry_wrap' => '<div class="pdblog-entry" >%s</div>',
'entry_input_wrap' => '<div class="pdblog-entry-input" >%s</div>',
'entry_item_wrap' => '<span class="entry-item %s">%s</span>',
'entry_check' => '<span class="entry-checkbox">%s</span>',
'entry_input_item_wrap' => '<span class="entry-input-item item-field-%2$s"><label for="%4$s">%3$s</label><span id="%4$s">%1$s</span>%5$s</span>',
'input_submit' => '<div class="entry-input-item entry-input-submit">%s</div>',
'title_row' => '<div class="entry-item-titles">%s</div>',
'item_title' => '<span class="item-title %s" %s>%s</span>',
'entry_controls' => '<div class="entry-controls" >%s</div>',
'no_entries' => '<span class="no-entries"><span class="entry-item-hidden">0</span>%s</span>',
'entry_error' => '<p class="entry-input-error"></p>',
'log_display' => '<div id="%1$s" class="pdblog log-display-%2$s pdblog-template-responsive pdblog-template-{$mode} %4$s" data-log="%1$s" data-record-id="%5$s" data-nonce="%6$s" %7$s >%3$s</div>',
'log_summary' => '<div class="pdblog log-display-%2$s pdblog-template-{$mode}" >%3$s</div>',
'log_entry_name' => '<h3 class="log-entry-name">%s</h3>',
'add_button' => '<button type="button" class="button button-primary" value="%s" >%s</button>',
'csv_button' => '<button type="button" class="button button-secondary csv-button" value="%s" >%s</button>',
'entry_id' => '<span class="%s pdb-entry-id" >%s</span>',
'search_sort_row' => '<div class="log-sort-header log-header">%s</div>',
'sum_row' => '<div class="log-sum-header log-header">%s</div>',
'item_value' => '<span class="item-value %s" %s>%s</span>',
'search_input' => '<input type="text" class="%1$s" placeholder="%2$s" %3$s />',
'pagination' => '<ul class="%s-pagination pdb-pagination"></ul>',
'helptext' => '<span class="entry-item-helptext helptext">%s</span>',
);
}
}
new pdb_custom_log_template();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment