Report Tokens + use token in php

Afternoon All,

I am trying to do some work with pro-reports explicitly :
I need to in my email-body.php extract the following so I can access them, specifically the following items

  • Site Url (as i need it to access a custom API)
  • Date Range (So I can separate the start and finish dates for the api)

I would also like to read in:

  1. [plugin.updated.count]
  2. [theme.updated.count]
  3. [wordpress.updated.count]

So I can add them all together than issue as a [total_update-count]
I can’t find a way to read them into a variable to be able to do this or begin this;

Can anyone tell me how do to this and share a code snippet so I can understand please?

Thanks in advance

Hey @stingray82

I’ll check with the development team for more info and update you as soon as possible.

Unfortunately, this is not currently supported.

The team will look into the feasibility of adding it in the future, but we don’t have an exact ETA at this time.

So if I can’t do it in the template can I do it in a plugin? and if so how do I access that specific data? I am trying to get Independant Analytics stats into mainwp I can do it for a single site by manually setting the data

$from_date_obj = “2024-08-01”;
$to_date_obj = “2024-08-27”;
$site_url = “https://site.ul”;

But how can I do this for all child installs?

Thanks Bojan, I wonder if there is a way I can hook into the PHP that generates these stats directly then?

  1. [plugin.updated.count]
  2. [theme.updated.count]
  3. [wordpress.updated.count]

The other relates to a support ticket I submitted so I am going to leave that to your reply there, so I can give more specifics without having to hide api test points etc.

Hi @stingray82

The dev team has added support for custom Pro Reports tokens.

I have sent you a pre-release version of Pro Reports that includes this via a private message.

For example, for custom token token [custom.update.total], you would use a hook like this:

add_filter( 'mainwp_pro_reports_addition_custom_tokens', 'mycustom_mainwp_pro_reports_addition_custom_tokens', 10, 3 );
function mycustom_mainwp_pro_reports_addition_custom_tokens( $tokens, $site_id, $data ) {
    if(is_array($data) && isset($data[$site_id])){
         $total = 0;
         $total += isset($data[$site_id]['other_tokens_data']['body']['[plugin.updated.count]']) ? intval( $data[$site_id]['other_tokens_data']['body']['[plugin.updated.count]'] ) : 0;
         $total += isset($data[$site_id]['other_tokens_data']['body']['[theme.updated.count]']) ? intval( $data[$site_id]['other_tokens_data']['body']['[theme.updated.count]'] ) : 0;
         $total += isset($data[$site_id]['other_tokens_data']['body']['[wordpress.updated.count]']) ? intval( $data[$site_id]['other_tokens_data']['body']['[wordpress.updated.count]'] ) : 0;
         
         $tokens['[custom.update.total]'] = $total;
    }
    
    return $tokens;
}
1 Like

Thank You I can confirm this works perfectly

1 Like