How can I permanently delete a resource without moving it to the trash?

Hello everyone! I’m trying to write a plugin that perfectly deletes directories after deleting the resource itself, but at the end I also want to permanently delete the resource without moving it to the trash, how can I do it?

Below is the code that is great for deleting resource directories, but after I select the resource in the resource panel and click “Delete” it turns red and just moves to the trash, and I need it to be permanently deleted immediately…

 * Plugin to delete associated folders of a resource when the resource is deleted.

$deleteFolderFiles = $modx->event->name;
switch($deleteFolderFiles) {
    case 'OnDocFormDelete':
// Define the paths of the folders to check and delete
$foldersToDelete = array(
    '../assets/AdditionalPhotos/' . $resource->get('id') . '/',
    '../upload/' . $resource->get('id') . '/'

// Loop through the folders and delete them
foreach ($foldersToDelete as $folder) {
    if (is_dir($folder)) {
        // Delete all files and subdirectories within the folder
        $files = glob($folder . '/*');
        foreach ($files as $file) {
            if (is_dir($file)) {
                // Delete subdirectory and its contents
                $subFiles = glob($file . '/*');
                foreach ($subFiles as $subFile) {
            } else {
                // Delete file
        // Delete the folder itself

    // Delete resource

This particular line does not work

    // Delete resource

did you try just


Yes) Now it really deletes the page, but in order to see it, you need to reload the page yourself, and only then the deleted page disappears and no longer turns red(


Is it possible to add some kind of reload after $resource->remove();?

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.