Users are able to submit an entry and it defaults to a status of 'Awaiting Moderation'. When our administrator reviews the entry and changes its status to 'Open', I would like to set the expiration date 60 days in the future.
In my extension, I've tried using the entry_submission_ready hook and the entry_submission_end hook, but I don't seem to be able to detect a difference in status.
public function set_expiration_date( $meta = array(), $data = array(), $auto_save = array() ) {
$old_status = isset( $meta['status'] ) ? strtolower( $meta['status'] ) : '';
$new_status = isset( $_POST['status'] ) ? strtolower( $_POST['status'] ) : '';
if ( 'open' != $old_status && 'open' == $new_status && '14' == $data['channel_id'] && 'mydata' == $data['field_id_123'] ) {
// set expiration date 60 days in the future
$future = date('Y-m-d', time() + 60*24*60*60);
$exp_time = strtotime( $future . ' 23:59:59' );
$data['expiration_date'] = $exp_time;
} else {
return;
}
}
When using entry_submission_ready, $old_status
and $new_status
always seems to be the previous status. And with entry_submission_end, $old_status
and $new_status
are always the next status. So $_POST
is changed.
I don't understand how to use this EE hook. What am I missing?