Skip to content

Instantly share code, notes, and snippets.

@xnau
Created February 26, 2022 20:46
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/2dd81f85758094bd1028bb412b94f2bd to your computer and use it in GitHub Desktop.
Save xnau/2dd81f85758094bd1028bb412b94f2bd to your computer and use it in GitHub Desktop.
Sows how to add a custom summary tag to a Participants Database log
<?php
/**
* Plugin Name: PDB Custom Summary Tag
* Description: provides a custom tag to the "cars" log
*/
add_filter( 'pdblog-summary_tags', 'xnau_add_custom_summary_tag', 10, 2 );
/**
* adds a custom summary tag to the "cars" log
*
* @param array $tags
* @param string $log_name
*/
function xnau_add_custom_summary_tag( $tags, $log_name )
{
if ( $log_name === 'cars' )
{
$tags['average_score'] = $tags['sum'] / $tags['count'];
}
return $tags;
}
@xnau
Copy link
Author

xnau commented Feb 26, 2022

This filter adds an [average_score] tag that can be used in the summary template for the selected log.

This assumes that the log sum is configured as the sum of all scores. The tag makes it possible to display the average score in the summary display.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment