Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save planetahuevo/158743157baf19e3a741358d266f58e3 to your computer and use it in GitHub Desktop.
Save planetahuevo/158743157baf19e3a741358d266f58e3 to your computer and use it in GitHub Desktop.
Custom code snippet for creating custom tokens for the Client Reports Extension
<?php
// Add the following code snippet to the functions.php file of the MainWP Customisations plugin
// Download MainWP Customisations here: https://github.com/mainwp/mainwp-customisations
// More about the plugin: https://mainwp.com/mainwp-customisations/
// Create Custom Client Report tokens
add_filter( 'mainwp_client_reports_tokens_groups', 'mycustom_reports_tokens_groups' );
function mycustom_reports_tokens_groups( $tokens ) {
// examples
$tokens['plugins']['sections'][] = array( 'name' => 'section.plugins.custompluginsection', 'desc' => 'Custom plugin section descriptions' );
$tokens['plugins']['nav_group_tokens']['custompluginsection'] = 'Custom plugin section';
$tokens['custompluginsection'][] = array( 'name' => 'plugin.custompluginsection.tokenname1', 'desc' => 'Token1 name descriptions' );
$tokens['custompluginsection'][] = array( 'name' => 'plugin.custompluginsection.tokenname2', 'desc' => 'Token2 name descriptions' );
return $tokens;
}
// tokens navigation
add_filter('mainwp_client_reports_tokens_nav_top', 'mycustom_reports_tokens_nav_top');
function mycustom_reports_tokens_groups( $tokens_group ) {
$tokens_group['my_new_group_token'] = 'My new group tokens';
return $tokens_group;
}
// token values
add_filter('mainwp_client_reports_custom_tokens', 'mycustom_reports_custom_tokens');
function mycustom_reports_custom_tokens($tokens_values, $report) {
$tokens_values['[plugin.custompluginsection.tokenname1]'] = 'Value for custom token name1';
$tokens_values['[plugin.custompluginsection.tokenname2]'] = 'Value for custom token name2';
return $tokens_values;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment