All add-ons currently require PHP 7.4 or greater.

On July 4th 2024 PHP 8.2 will be the new minimum requirement for all add-ons. Expect any add-on released after that date to require 8.2 or greater. Some releases may not immediately take advantage of 8.x specific features in PHP, which means you might, be able to continue using new releases in PHP 7.4, however, if you experience an error the first thing you should do is update to PHP 8.2 then create a support ticket if the error persists.

Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Send email notification when a draft has been approved

Status Resolved
Add-on / Version Publisher
Severity Trivial
EE Version

Timothy Kelty

May 24, 2013

Client was asking to send an email to arbitrary address when entries in a particular channel have been approved (a draft has been published, or new version published).

Anything like that planned? I haven’t looked at the code yet, does Publisher have a hook I might be able to use if I need to do a custom extension?

#1

BoldMinded (Brian)

There is actually a new hook in the email method, in Publisher_email.php, you can use that one. Its not documented yet, but it should be pretty clear on what it does if you look at the code.

#2

Timothy Kelty

I see the hook, but wasn’t sure how I could use it, as I don’t believe the current logic ever calls an email when something is “approved” (a draft becomes published).

Here’s my ghetto-fied way of hacking it in for now: In publisher/models/publisher_entry.php, around line 142 in Publisher_entry->save

if ($publisher_save_status == PUBLISHER_STATUS_OPEN)
        {

            // CHANGED: Fusionary Hack
            // Send email when an entry goes from draft to published
            ee()->load->library('api');
            ee()->api->instantiate('channel_structure');
            $channel_id = $this->post_data['channel_id'];
            $entry_id = $this->post_data['entry_id'];
            $channel_title = ee()->api_channel_structure->get_channel_info($channel_id)->row_data['channel_title'];
            $url = ee()->publisher_site_pages->get_url($entry_id, $channel_id, ee()->publisher_lib->lang_code);

            if (in_array($channel_id, array(10, 20, 23)) &&
                $this->post_data['publisher_view_status'] == PUBLISHER_STATUS_DRAFT) {
                $to = array(
                    'xxx@fusionary.com',
                    'xxx@fusionary.com',
                    'xxx@fusionary.com',
                );
                $template = 'The Telx website has been updated. The following ' . $channel_title . ' entry is new or has been modified:' . "\n" . $url;
                $data = array(
                    'to'        => implode("\n", $to),
                    'reply_to'  => ee()->session->userdata['email'],
                    'reply_name'=> ee()->session->userdata['screen_name'],
                    'subject'   => ee()->input->post('title', TRUE) .' was published by '. ee()->session->userdata['screen_name'],
                    'template'  => $template,
                );

                // Send the email
                ee()->publisher_email->send($data);

            }

            // If option is enabled, and saving as open, update the draft versions too so they are in sync.
            if (ee()->publisher_setting->get('sync_drafts') AND !ee()->publisher_setting->get('disable_drafts'))
            {
                // Delete an the approval if it exists, b/c we just saved as open, thus whatever was pending approval is now live.
                ee()->publisher_approval_entry->delete(ee()->publisher_lib->entry_id);

                $this->where['publisher_status'] = PUBLISHER_STATUS_DRAFT;
                $this->data_columns['publisher_status'] = PUBLISHER_STATUS_DRAFT;
                $this->title_columns['publisher_status'] = PUBLISHER_STATUS_DRAFT;

                $this->insert_or_update('publisher_titles', $this->title_columns, $this->where);
                $this->insert_or_update('publisher_data', $this->data_columns, $this->where);
            }
        }
#3

Timothy Kelty

Not sure if that’s necessarily the proper place for it, but it seems to do the job for now.

#4

BoldMinded (Brian)

The publisher_approval_entry.php file might be a better spot?

Does the hook not work? It should be sending a load of data to you to use.

#5

Timothy Kelty

Oh yeah…hmmm Publisher_approval_entry->save calls send….seems like I should indeed be able to use that.

Thanks, I’ll re-investigate.

#6

BoldMinded (Brian)

Going to close this since you’re heading in the right direction.

Login to reply