Skip to content

Instantly share code, notes, and snippets.

@mlbd
Created September 3, 2025 21:30
Show Gist options
  • Save mlbd/dff12f2330c04ec726b0415f86be7de3 to your computer and use it in GitHub Desktop.
Save mlbd/dff12f2330c04ec726b0415f86be7de3 to your computer and use it in GitHub Desktop.
Add ‘Last Signed Off By’ to show who performed the most recent sign-off.
// [PATCH] Added custom placeholder "%last_signed_off_by%" for emails and its runtime resolver.
if ( ! function_exists( 'owf_register_last_signed_off_by_placeholder' ) ) {
function owf_register_last_signed_off_by_placeholder() {
// Show the placeholder label in the Step Info email editor (step-info-content.php)
add_filter( 'oasiswf_custom_placeholders', function( $placeholders ) {
if ( ! is_array( $placeholders ) ) {
$placeholders = array();
}
// [PATCH] Added new placeholder label so it appears in the dropdown
$placeholders['%last_signed_off_by%'] = esc_html__( 'Last Signed off by', 'oasisworkflow' );
return $placeholders;
} );
/**
* Inject the runtime value for assignment/reminder emails.
* This filter is called in the email sending pipeline with full context.
*
* @param array $mapping Existing custom placeholder map.
* @param int $action_id Current action history id (for the receiving assignment).
* @param int $step_id Current step id.
* @param int $to_user_id Recipient user id.
* @param int $post_id Post id.
*
* @return array
*/
add_filter( 'oasiswf_custom_placeholders_list', function( $mapping, $action_id, $step_id, $to_user_id, $post_id ) {
if ( ! is_array( $mapping ) ) {
$mapping = array();
}
// [PATCH] Compute "Last Signed off by" using the previous action (same logic as Inbox list).
$name = owf_get_last_signed_off_by( $action_id, $post_id );
if ( $name ) {
$mapping['%last_signed_off_by%'] = $name;
}
return $mapping;
}, 10, 5 );
}
owf_register_last_signed_off_by_placeholder();
}
function owf_get_last_signed_off_by( $action_id, $post_id ) {
$action_id = intval( $action_id );
$post_id = intval( $post_id );
if ( ! $action_id || ! $post_id ) {
return '';
}
$ow_history_service = new OW_History_Service();
$previous = $ow_history_service->get_action_history_by_id( $action_id ); // previous step/action
if ( ! $previous ) {
return '';
}
// Mirror class-ow-inbox-service.php get_table_rows() logic.
$comments = null;
if ( intval( $previous->assign_actor_id ) === -1 ) {
// Multi-assignee/review case: get review row with status "complete" for the previous action.
$review_rows = $ow_history_service->get_review_action_by_status( 'complete', $previous->ID );
if ( $review_rows ) {
$comments = json_decode( $review_rows[0]->comments );
}
}
if ( ! $comments ) {
$comments = json_decode( $previous->comment );
}
if ( is_array( $comments ) && ! empty( $comments[0]->send_id ) ) {
return OW_Utility::instance()->get_user_name( intval( $comments[0]->send_id ) );
}
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment