# Report Tokens + use token in php

**URL:** <https://community.mainwp.com/t/report-tokens-use-token-in-php/9283>\
**Category:** Dev\
**Created:** [August 27, 2024, 3:53pm UTC](https://community.mainwp.com/t/report-tokens-use-token-in-php/9283 "2024-08-27T15:53:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![stingray82](https://community.mainwp.com/user_avatar/community.mainwp.com/stingray82/32/6232_2.png) [@stingray82](https://community.mainwp.com/u/stingray82)\
**Post date:** [August 27, 2024, 3:53pm UTC](https://community.mainwp.com/t/report-tokens-use-token-in-php/9283/1 "2024-08-27T15:53:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bojan](https://community.mainwp.com/user_avatar/community.mainwp.com/bojan/32/3059_2.png) [@bojan](https://community.mainwp.com/u/bojan)\
**Post date:** [August 27, 2024, 5:06pm UTC](https://community.mainwp.com/t/report-tokens-use-token-in-php/9283/2 "2024-08-27T17:06:59Z")

</div>

Hey @stingray82

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

---

<div class="post-metadata">

**Author:** ![bojan](https://community.mainwp.com/user_avatar/community.mainwp.com/bojan/32/3059_2.png) [@bojan](https://community.mainwp.com/u/bojan)\
**Post date:** [August 27, 2024, 5:35pm UTC](https://community.mainwp.com/t/report-tokens-use-token-in-php/9283/3 "2024-08-27T17:35:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stingray82](https://community.mainwp.com/user_avatar/community.mainwp.com/stingray82/32/6232_2.png) [@stingray82](https://community.mainwp.com/u/stingray82)\
**Post date:** [August 27, 2024, 5:47pm UTC](https://community.mainwp.com/t/report-tokens-use-token-in-php/9283/4 "2024-08-27T17:47:48Z")

</div>

> [@stingray82](#):
>
> 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

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](https://site.ul)”;

But how can I do this for all child installs?

---

<div class="post-metadata">

**Author:** ![stingray82](https://community.mainwp.com/user_avatar/community.mainwp.com/stingray82/32/6232_2.png) [@stingray82](https://community.mainwp.com/u/stingray82)\
**Post date:** [August 27, 2024, 6:36pm UTC](https://community.mainwp.com/t/report-tokens-use-token-in-php/9283/5 "2024-08-27T18:36:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bojan](https://community.mainwp.com/user_avatar/community.mainwp.com/bojan/32/3059_2.png) [@bojan](https://community.mainwp.com/u/bojan)\
**Post date:** [August 29, 2024, 11:46am UTC](https://community.mainwp.com/t/report-tokens-use-token-in-php/9283/6 "2024-08-29T11:46:34Z")

</div>

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:

```auto
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;
}

```

---

<div class="post-metadata">

**Author:** ![stingray82](https://community.mainwp.com/user_avatar/community.mainwp.com/stingray82/32/6232_2.png) [@stingray82](https://community.mainwp.com/u/stingray82)\
**Post date:** [August 29, 2024, 2:17pm UTC](https://community.mainwp.com/t/report-tokens-use-token-in-php/9283/7 "2024-08-29T14:17:13Z")

</div>

Thank You I can confirm this works perfectly

---

<div class="post-metadata">

**Author:** ![system](https://community.mainwp.com/uploads/default/original/2X/4/4cfc87ac67e4ebdbfa0bbf0b19c8657f35a29a5b.png) [@system](https://community.mainwp.com/u/system)\
**Post date:** [September 28, 2024, 2:17pm UTC](https://community.mainwp.com/t/report-tokens-use-token-in-php/9283/8 "2024-09-28T14:17:51Z")

</div>

Closed on September 28, 2024, 2:17pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
