Jump to main content Jump to doc navigation

Event: OnDocUnPublished

Called when a Resource is unpublished via the Unpublish context menu.

  • Service: 5 - Template Service Events
  • Group: None

Event Parameters

Name Description
docid The ID of the resource being unpublished. (deprecated)
id The ID of the resource being unpublished.
resource A reference to the modResource object being unpublished.

Important! Before using this event, you need to know

The event fires only when the resource is unpublished via the document context menu in the resource tree. If you uncheck the published checkbox while editing a document on the document page itself, nothing happens.

Example

Such a plugin will display an array of the unpublished resource in the "Error log", and a success message on the screen:

<?php
$eventName = $modx->event->name;
switch($eventName) {
    case 'OnDocUnPublished':
        $response = array(
        	'success' => false,
        	'message' => 'Resource removed from publication!',
        	'data' => array(),
        );
        echo $modx->toJSON($response);
        exit; 
        $modx->log(modX::LOG_LEVEL_ERROR, print_r($resource->toArray(),true));
        break;
}

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • eydolan
  • Following Sea
  • Lefthandmedia
  • Murray Wood
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$311 per month—let's make that $500!

Learn more