Can I get Pro Reports token data via PHP classes or variables or objects other than the tokens?

I must be missing something in how I’m going about this, so set me straight if it’s wrong.

I have the iThemes extension in MainWP (now Solid Security) and it’s installed on many client websites but not all of them.

In my custom report it has a common method of outputting data.

The problem is that on the sites that don’t have Solid Security installed, these data points still output on the report, showing “0” as the value.

At first I thought the “$plugin_active_itsecurity” check was supposed to hide it if not installed, but then I realized that is only checking if the plugin is installed in MainWP itself, not the client site.

Then I figured the “$showhide_values” stuff was supposed to hide the output if nothing is returned, but this seems to not work at all because it’s still output anyway.

Next I tried to see if I could make my own PHP “if()” block using the token data, but of course I can’t put the tokens inside PHP functions in that way. Likewise, I can’t export the token data to the debug log or do other kinds of tests in PHP. I don’t know how these tokens are processed or if they are treated like normal WordPress shortcodes?

That said, my question is, how do I show the values for the iThemes data only if the client has the plugin installed and there are values to show? In my case, it is showing those data points even when the plugin isn’t installed on the client site at all!
If the plugin is installed on the client, then showing a 0 for the count would be fine if that were actually correct.

My idea was that, if I can pull that token data some other way beside using the shortcode style format, then I could check it with my own PHP tests before outputting.
I know there is an API for Pro Reports but I’m hoping there are PHP functions or classes I can access directly in my templates rather than try to code with cURL calls or something.

I looked in the latest default templates to see how they do it, and it’s basically the same. They do output a new token which is ‘[config-section-extra max-empty=“1” /]’. I have no idea what this is supposed to be doing. The documention and how the tokens work is really lacking. I’m having a hard time customizing or figuring out anything. I can’t work with the tokens since they can’t be used in PHP functions, I can’t output them, check them or debug log them and run my own logic. New tokens like that one above just pop out of nowhere and I didn’t know it existed or what it does and there is no documentation about it.

Go to the tokens documentation here or here and there is no mention of config-section-extra.

I tried using do_shortcode(“[a-token]”) but that just output the plain text token, not the replaced value. So even here I can’t treat them like a standard shortcode.

I just don’t know what to do. All I want is for iThemes data to not output if the client website doesn’t use the plugin. I also want to know if I can output or fetch the token data some other way than just the normal token syntax (to use with PHP) like an object or classe or global variables or something.

Thanks for any ideas!

Hey @zackw

Can you please share the custom code you’ve written for the iThemes data so we can take a closer look and try to replicate it on our Dashboard?

I am unable to post code in the forums. For whatever reason, if I try to post any of the code, using backtics or not or any other formatting, I get a “403 error” and it won’t post.

What I mean is that the output of the token data in PHP template is just the same as the default templates. It checks the $showhide_values and then opens a ‘config-section-data’ and then echos the tag.

Also, what you’re asking for isn’t really relevant. What I’m asking for is if there is any other way to read token data that isn’t just the token tag itself. Can I access the data with global variables or classes or objects or static classes or any other way than the normal token?

Can you share the code on a third-party site like codeshare.io?

The development team will take a look at the code and this specific question as soon they are able.

Hey @zackw I was able to achieve what you were looking for by doing the following:

Within any template paste in this snippet just above the ?> <html> tag:

https://codeshare.io/8pAbV4

Let me explain what’s going on here – This will take the $website['id'] that’s available when each report is first generated, and use the mainwp_fetchurlauthed filter to fire off the “callable function” ithemes() that’s located within the MainWP Child Plugin - mainwp-child/class/class-mainwp-child-callable.php at ce41bc55135f30aa39375b03c25dfee7a52f1f68 · mainwp/mainwp-child · GitHub

This function will return an error of NO_ITHEME if not installed, which we can then check for and set our $ithemes_installed variable to true|false. Since we left mwp_action empty, if iThemes is installed it will simply exit and set our variable to true.

Finally, we can wrap our HTML section in another check so we can hide the output. This was also included in the snippet above…

1 Like

Very clever!
I’ll give it a try as soon as possible.

It makes sense to me for MainWP to add two abilities that don’t seem to be in the templates currently:

  1. Let us grab token data using PHP functions (objects, classes, variables, etc) and not only the token tags themselves.

  2. Have a test for if the plugin is installed on the client site, not just whether it’s installed to MainWP itself, which is only half relevant. It’s good to test if the iThemes plugin is installed in MainWP, but it’s just as relevant to check if it’s also installed on the actual client site. Otherwise, we output something with empty data.

Thanks!

@zackw I hope it solves your use case. I also made a courtesy post for your request so it’s on the feedback board. Feel free to vote on it.

https://feedback.mainwp.com/admin/plugins/pro-reports-template-request-clrntdbia0018px2f36h3kgkd

Keep me posted on the outcome of the snippet.

1 Like

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