OnWebPageComplete and OnLoadWebDocument events - does one block the other?

I’ve created next plugin and appointed two events - OnWebPageComplete and OnLoadWebDocument:

<?php
if ($modx->context->key == 'mgr') {return;}
$eventName = $modx->event->name;
switch($eventName) {
    case 'OnWebPageComplete':
        $modx->log(modX::LOG_LEVEL_ERROR, 'testPlugin - OnWebPageComplete event');
        break;
    case 'OnLoadWebDocument':
        $modx->log(modX::LOG_LEVEL_ERROR, 'testPlugin - OnLoadWebDocument event');
        break;
}

This is what I get in the error log:
[2021-09-01 13:04:39] (ERROR @ *****/core/cache/includes/elements/modplugin/41.include.cache.php : 9) testPlugin - OnLoadWebDocument event

Yes, I know that these events are executed one after the other, but why doesn’t the plugin catch the second event(OnWebPageComplete)? I’ve tried different priorities for events inside the plugin, it doesn’t help. I also tried to split these two events into different plugins - let each one handle a different event. In the end, I only see OnLoadWebDocument processing.

Is this a bug or an undocumented feature? If the latter, I would be happy to update MODX documentation.

MODX 2.8.3 on MODXcloud.

I tested your plugin with MODX 2.8.3 on a local installation and I can’t reproduce the behaviour.
I got both messages in the error log.

Thanks @halftrainedharry !
I agree with you, this is how it should be … but it does not happen that way. What can influence this? Probably I need to turn off all possible (extra, plugins) … nothing specific(ContentBlocks, Commerce, pdoTools etc.) and retest again.

It’s seems unlikely that another extra or plugin would influence your plugin.

Maybe there is a problem with register_shutdown_function on your installation.

1 Like

Make sure that every path through your plugin leads to a return statement.