This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

If you have multiple people editing the content of a website, it is often useful to notify a manager or someone responsible for approving content of all changes automatically. This how-to will show you how to set up your site to send email notifications when any of the following happens:

  • a new page is added
  • page content is edited*
  • page attributes are updated
  • a page is moved to another location in the sitemap
  • a page is duplicated
  • a page is deleted

Note: there is a shortcoming in Concrete5.4.1 that prevents notifications of page edits that are saved to "Preview Mode" -- in 5.4.1 you will only be notified of page edits when they are "published". Concrete5.4.2 corrects this shortcoming, so if you are running 5.4.2 or later you will get notifications of all page edits (both "previewed" or "published").

  1. Create a new file in your site's top-level "libraries" directory called "change_notifications.php". Paste the following code into that file:

    <?php defined('C5_EXECUTE') or die("Access Denied.");
    
    define('CHANGE_NOTIFICATION_EMAIL_TO', 'admin1@example.com, admin2@example.com');
    define('CHANGE_NOTIFICATION_EMAIL_FROM', 'fromaddress@example.com');
    define('CHANGE_NOTIFICATION_EMAIL_SUBJECT', 'Website Updated!');
    
    class ChangeNotifications {
    
        function on_page_add($page) {
            ChangeNotifications::send($page, 'A new page has been added to your website.');
        }
    
        function on_page_update($page) {
            ChangeNotifications::send($page, 'A page has been updated on your website.');
        }
    
        function on_page_delete($page) {
            ChangeNotifications::send($page, 'A page has been deleted from your website.');
        }
    
        function on_page_move($page, $old_parent_page, $new_parent_page) {
            ChangeNotifications::send($page, 'A page has been moved on your website.');
        }
    
        function on_page_duplicate($new_page, $current_page) {
            ChangeNotifications::send($new_page, 'A page has been duplicated on your website.');
        }
    
        function on_page_version_add($page) {
            ChangeNotifications::send($page, 'A page update has been made (but not yet approved) on your website.');
        }
    
        function on_page_version_approve($page) {
            ChangeNotifications::send($page, 'A page update has been approved on your website.');
        }
    
        function send($page, $msg) {
            $mh = Loader::helper('mail');
            $mh->to(CHANGE_NOTIFICATION_EMAIL_TO);
            $mh->from(CHANGE_NOTIFICATION_EMAIL_FROM);
            $mh->setSubject(CHANGE_NOTIFICATION_EMAIL_SUBJECT);
            $msg .= "\n\n" . BASE_URL . View::url($page->getCollectionPath());
            $mh->setBody($msg);
            $mh->sendMail();
        }
    }
    
  2. Modify the 3 "define" lines at the top of that code to set the email address(es) you wish to send notifications to, as well as the "from" and "subject" for those notifications.

  3. Create a new file in your site's top-level "config" directory called "site_events.php". Paste the following code into that file:

    <?php defined('C5_EXECUTE') or die("Access Denied.");
    
    Events::extend('on_page_add', 'ChangeNotifications', 'on_page_add', 'libraries/change_notifications.php');
    Events::extend('on_page_update', 'ChangeNotifications', 'on_page_update', 'libraries/change_notifications.php');
    Events::extend('on_page_delete', 'ChangeNotifications', 'on_page_delete', 'libraries/change_notifications.php');
    Events::extend('on_page_move', 'ChangeNotifications', 'on_page_move', 'libraries/change_notifications.php');
    Events::extend('on_page_duplicate', 'ChangeNotifications', 'on_page_duplicate', 'libraries/change_notifications.php');
    Events::extend('on_page_version_add', 'ChangeNotifications', 'on_page_version_add', 'libraries/change_notifications.php');
    Events::extend('on_page_version_approve', 'ChangeNotifications', 'on_page_version_approve', 'libraries/change_notifications.php');
    

That should be it! Note that in order for your website to be able to send these notifications, you must have email sending properly configured on your server (which is outside the scope of this how-to).

Loading Conversation