Skip to main content

What You’ll Learn

  • Understanding why raw PHP conditions don’t work in templates
  • Using Pro Reports filter hooks for conditional output
  • Creating custom placeholder tokens
  • Building conditional messages based on data values

Extension Add-on - This add-on provides standalone functionality within MainWP Dashboard. No third-party plugins required.
Pro Reports renders the PHP template file before it replaces report tokens. That means conditional checks against token placeholders in the template do not evaluate the final token values. To change output based on the parsed report data, modify the parsed token arrays with filters and output the result into your own placeholder token. Two filters are available for this purpose:
  • mainwp_pro_reports_parsed_section_tokens
  • mainwp_pro_reports_parsed_other_tokens
    Use mainwp_pro_reports_parsed_section_tokens when your condition depends on section rows, and mainwp_pro_reports_parsed_other_tokens when you want to update non-section tokens or set a custom placeholder token. Keep the expected sections_data and other_tokens_data structure intact, but you can add or update token keys inside the relevant body or header array.
If your condition relies on a “count” token (e.g., [plugin.updated.count]), remember those must be placed outside section tags in the template. A full token reference is here: Available Pro Reports Tokens

How to use it

  1. In your report template, insert a custom placeholder where the message should appear, e.g. [my.custom.message]. For the example below, place that placeholder outside any section tags so Pro Reports treats it as an “other” token.
  2. Add your code on the Dashboard, either in your Dashboard theme’s functions.php or in a PHP snippet through the Custom Dashboard extension.
  3. In your filter, read the parsed token you care about (for example [plugin.updated.count]) and set the value for your placeholder token. Keep the top-level parsed array structure intact and add or update the token key in the relevant body or header array.
  4. (General setup reminder) Pro Reports pulls activity from the free MainWP Child Reports plugin so new installs may need some time to record data.

Example: one message for 0, 1, or many updates

Goal
  • 0 → “No updates needed this month.”
  • 1 → “We performed 1 update during this period.”
  • ≥2 → “We performed X updates during this period.”
Template
Place [my.custom.message] where the text should appear, outside any section tags. If you also show a count like [plugin.updated.count], keep that outside any section token as well.
add_filter( 'mainwp_pro_reports_parsed_other_tokens', 'my_custom_parsed_other_tokens_messages', 10, 3 );
function my_custom_parsed_other_tokens_messages( $parsed_other_tokens, $report, $website ) {

// Read the parsed count token that Pro Reports provides.
if ( is_array( $parsed_other_tokens )
     && isset( $parsed_other_tokens['other_tokens_data']['body']['[plugin.updated.count]'] ) ) {

    $count = (int) $parsed_other_tokens['other_tokens_data']['body']['[plugin.updated.count]'];

    if ( $count === 0 ) {
        $msg = 'No updates needed this month.';
    } elseif ( $count === 1 ) {
        $msg = 'We performed 1 update during this period.';
    } else {
        $msg = sprintf( 'We performed %d updates during this period.', $count );
    }

    // Output into your custom placeholder token.
    $parsed_other_tokens['other_tokens_data']['body']['[my.custom.message]'] = $msg;
}

return $parsed_other_tokens;
}
Why this works
  • The condition runs after Pro Reports has built the token array, so [plugin.updated.count] is a real integer, not a placeholder string.
  • You preserve the expected parsed array shape and add the [my.custom.message] token value inside other_tokens_data['body'], which Pro Reports later replaces in the template.
If you want different drivers (themes, WordPress core, etc.), swap [plugin.updated.count] for the relevant token from the tokens list.