Count tokens return nothing when count is zero

When using the count tokens (eg. [plugin.updated.count]) within a PDF template for the Pro Reports, nothing seems to be returned when the count is zero. I would like to have the count return zero in this instance and am pretty sure this is a bug and should not be considered expected behavior.

I am aware of the Report Data that can restrict to Hide if Empty, but don’t think this is related. If I toggle that to any setting, I still see no change in this token. Thanks for looking into this.

Hi @uamv, thanks for reporting this. Just to be 100% sure, are you referring to the “Overview” section of the report?

Here’s what I’m seeing in the PDF of my custom report.

Here’s the code that renders this portion of the report.

<table id="report-overview" style="width: 210mm; border-collapse: separate; border-spacing: 25px; padding: 0 15px;">
   <tbody>
      <tr>
         <td colspan="5" style="width: 33%;" valign="top"><span style="font-size: 175%;">[aum.uptime30]</span><br /><span>Uptime</span></td>
         <td colspan="5" style="width: 33%;" valign="top"><span style="font-size: 175%;">[ga.visits]</span><br /><span>Site Visitors</span></td>
         <td colspan="5" style="width: 33%;" valign="top"><span style="font-size: 175%;">[ga.new.visits]</span><br /><span>New Visits</span></td>
         <td colspan="5" style="width: 33%;" valign="top"><span style="font-size: 175%;">[ga.pageviews]</span><br /><span>Page Views</span></td>
      </tr>
      <tr>
         <td colspan="4" style="width: 25%;" valign="top"><span style="font-size: 175%;">[wordpress.updated.count]</span><br /><span>WP Updates</span></td>
         <td colspan="4" style="width: 25%;" valign="top"><span style="font-size: 175%;">[theme.updated.count]</span><br /><span>Theme Updates</span></td>
         <td colspan="4" style="width: 25%;" valign="top"><span style="font-size: 175%;">[plugin.updated.count]</span><br /><span>Plugin Updates</span></td>
         <td colspan="4" style="width: 25%;" valign="top"><span style="font-size: 175%;">[backup.created.count]</span><br /><span>Backups</span></td>
         <td colspan="4" style="width: 25%;" valign="top"><span style="font-size: 175%;">[sucuri.checks.count]</span><br /><span>Security Scans</span></td>
      </tr>
   </tbody>
</table>

It does look like I’m including these in a bit different way than the included reports do within their overview in that I am not wrapping the in the config-section-data and remove-if-empty delimiters. I would still think this should work, though. If I should be using these differently, please advise. Thanks!

1 Like

I ran into this issue too.

I tried to get the values in PHP-variables, to try to solve it in PHP:

$nr_of_wp_updates 		= do_shortcode('[wordpress.updated.count]') ;
$nr_of_theme_updates 	= do_shortcode('[theme.updated.count]') ;
$nr_of_plugin_updates 	= do_shortcode('[plugin.updated.count]') ;
$nr_of_backups 			= do_shortcode('[backup.created.count]') ;

But instead of PHP-variables that I can work with, I get strings that do not react to PHP functions in a way I would expect. The values of the variables are correct. In this example, there are 32 backups and 21 plugin updates. Every other value, like the string length, is not correct, though:

Var_dump of nr_of_wp_updates:
string(25) “”

Var_dump of nr_of_theme_updates :
string(21) “”

Var_dump of nr_of_plugin_updates :
string(22) “21”

Var_dump of nr_of_backups :
string(22) “32”

I would expect the length of the contents of variable $nr_of_wp_updates to be 0, but it is 25. It seems to be the length of the token itself ([wordpress.updated.count]).

I don’t think the tokens are rendered as shortcodes, so the do_shortcode functions just returns whatever was passed to it (the token itself), then MainWP does a replace. I thought of trying some similar approach using ob_start and ob_get_clean, but figured there should be a better way to handle this natively.

Hey guys, just to let you know that I have reached out to the dev team and they will review this. I will update here as soon as possible.

1 Like

Yeah, makes complete sense. I don’t know why I just didn’t see this yesterday.

Guess working on a Sunday wasn’t such a good idea after all.

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

My apologies for forgetting to update this thread. The reported problem has been fixed in the MainWP Child 4.0.7.1