Skip to content

Instantly share code, notes, and snippets.

@mlbd
Created March 7, 2026 18:35
Show Gist options
  • Select an option

  • Save mlbd/c1c844432d7f6decb3f874f31955d838 to your computer and use it in GitHub Desktop.

Select an option

Save mlbd/c1c844432d7f6decb3f874f31955d838 to your computer and use it in GitHub Desktop.
Add custom "comment" placeholder for Oasis Workflow email templates.
/**
* Add custom "comment" placeholder for Oasis Workflow email templates.
*
* Usage: Use {comment} in your workflow step email subject/content
* to include the sign-off comments from the previous step.
*/
add_filter('oasiswf_custom_placeholders_list', 'ow_add_comment_placeholder', 10, 5);
// Display the {comment} placeholder in the email settings UI placeholder list.
add_filter('oasiswf_emails_placeholders', 'ow_add_comment_placeholder_to_list');
function ow_add_comment_placeholder_to_list($placeholders)
{
if (!is_array($placeholders)) {
$placeholders = array();
}
$placeholders['{comment}'] = 'Sign-off comments from the previous step';
return $placeholders;
}
function ow_add_comment_placeholder($placeholders, $action_id, $step_id, $to_user_id, $post_id)
{
$ow_email = new OW_Email();
$comment = $ow_email->get_step_comment_content($action_id);
$placeholders['{comment}'] = !empty($comment) ? $comment : '';
return $placeholders;
}
/**
* Handle {comment} replacement for template-based emails
* (post published, revised post published, unauthorized update, task claimed, workflow abort).
* These emails only pass $post_id, so we look up the action history to find comments.
*/
add_filter('oasiswf_emails_placeholders_handler', 'ow_add_comment_placeholder_for_emails');
function ow_add_comment_placeholder_for_emails($post_id)
{
$placeholders = array();
$post_id = intval($post_id);
if (empty($post_id)) {
return $placeholders;
}
$ow_history_service = new OW_History_Service();
$action_histories = $ow_history_service->get_action_history_by_post($post_id);
$all_comments = '';
if (!empty($action_histories)) {
$ow_email = new OW_Email();
foreach ($action_histories as $action_history) {
$comment = $ow_email->get_step_comment_content($action_history->ID);
if (!empty($comment)) {
$all_comments .= $comment;
}
}
}
$placeholders['{comment}'] = $all_comments;
return $placeholders;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment