Skip to content

Instantly share code, notes, and snippets.

@bogdan-mainwp
Last active October 1, 2020 06:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bogdan-mainwp/95d9b2019c2c3292268097d1f5190f25 to your computer and use it in GitHub Desktop.
Save bogdan-mainwp/95d9b2019c2c3292268097d1f5190f25 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;
}
@planetahuevo
Copy link

Thank you for the code!
Is it possible to get dynamic values for the tokens from the child sites installing another script on the child site that get the info from the database?
I have some data on the child database from a third party plugin, I just need to be able to transfer that to the mainwp dashboard and use this snippet to put it into the reports, but I am struggling to do the connection.
I will keep investigating. Thanks again!

@rhoekman
Copy link

rhoekman commented Oct 1, 2020

Thank you for the code!
Is it possible to get dynamic values for the tokens from the child sites installing another script on the child site that get the info from the database?
I have some data on the child database from a third party plugin, I just need to be able to transfer that to the mainwp dashboard and use this snippet to put it into the reports, but I am struggling to do the connection.
I will keep investigating. Thanks again!

I know it's been a while. But did you have any luck figuring this out?

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