0

Is there a hook that could be used to check what status was before submission, and what status is submitted (changed to) whilst editing an entry?

I want to check to see if a status is changed to 'x2' from 'x1' for example.

Thanks

1 Answer 1

2

I would use the

entry_submission_ready

extension hook, and write a mini-extension that looks at the meta array in the api for the entry status value, and compares it to the previous value for that entry (if it exists). Quick example hook function that could work for your situation:

function entry_submission_ready_my_hook($meta, $data, $autosave)
{
    // get entry_status and entry_id if it exists
    $new_status = $meta['status'];
    $entry_id = $data['entry_id'];

    // check if the entry exists
    $entry = ee()->db->select('status')
                 ->from('channel_titles')
                 ->where('entry_id', $entry_id)
                 ->get();

    // do we have an entry and is it's status different?
    if ( ( $entry->num_rows() > 0 ) &&
         ( $entry->status !== $new_status ) ) 
    {
        // we have different entry status! do stuff here!
    }
}

The above code is completely untested, but that's the idea and should work just fine for your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.