MODX Community

Disable plugins running "OnWebPagePrerender" only for specific resources

Is there a way to disable the execution of the OnWebPagePrerender action for a plugin on certain resources or templates? In my case I have an email obfuscator extra running which replaces all emails but also does that for parts where I don’t want this to happen (e. g. in scripts where the are email API credentials involved). Any ideas?

In the code of the Plugin you can access the resource with $modx->resource.
Then based on the parameters of the ressource (like id or template) you can decide to execute the rest of the plugin or just exit with return.

Smart and simple, thanks for the hint, here’s what I came up with:

$resourceId = $modx->resource->get('id');;
$forbiddenResources = array(132,135);

if (!in_array($resourceId, $forbiddenResources)) {
  // Plugin Code

Just to be clear, this code will be overwritten on update though, right?

To be save, you could duplicate the plugin and deactivate the original one.

If you put all the plugin code inside the if-statement, you don’t need the return. Only for this alternative way:

if (in_array($resourceId, $forbiddenResources)) {

 // Plugin Code here
1 Like

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