We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    The code below works fine for resources, but when saving a chunk, the replacements are not made and I get a raft of JSON recursion errors in the error log. The code is essentially the same for both events. Do elements require a different method? I’ve tried all the ones I can think of (get(’snippet’) and set(’snippet’, $value) and data[’snippet’] =, $_POST, $scriptProperties) but nothing works.
    <?php
    /* New Code for BadWords Plugin */
    $words = explode(',',$useWords);
    foreach($words as $k => $word) {
        $pattern[$k] = "/\b($word)\b/is";
        $replace[$k] = $replacement;
    }
    unset($word);
    switch ($modx->event->name) {
    
        case 'OnBeforeDocFormSave':
            $resource->setContent(preg_replace($pattern, $replacement, $resource->getContent() ));
            break;
    
        case 'OnBeforeChunkFormSave':
            $chunk->setContent(preg_replace($pattern, $replacement, $chunk->getContent() ));
            break;
    }
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting