- Code: Select all
<?php
// - Extension: The saved entry/page notification hook
// - Version: 0.3
// - Author: PivotX Team
// - Email: admin@pivotx.net
// - Site: http://www.pivotx.net
// - Description: This hook will send an e-mail notification each time an entry or page is saved.
// - Date: 2012-08-02
// NB! Edit the email address...
global $saved_notification_recipient;
$saved_notification_recipient = "you@example.org";
$this->addHook(
'entry_edit_beforesave',
'callback',
'beforeSaveNotification'
);
$this->addHook(
'page_edit_beforesave',
'callback',
'beforeSaveNotification'
);
function beforeSaveNotification(&$item) {
global $PIVOTX, $saved_notification_recipient;
// Do nothing if the item isn't published.
if ($item['status']!="publish") {
return;
}
$text = "The item '{$item['title']}' was ";
$subject = "item ";
if (!empty($item['code']) && $PIVOTX['db']->entry_exists($item['code'])) {
$text .= "updated.";
$subject .= "updated";
} else {
$text .= "created.";
$subject .= "created";
}
// Uncomment the line below if you want all details about the entry/page
// $text .= "\n\n" . var_export($item, TRUE);
pivotxMail($saved_notification_recipient, $subject, $text);
}
PS! There is one drawback using the "before save" hook: The email is sent even if the saving fails...