GravityView - Filter Entry Notes by Gravity Flow Assignee.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* GravityView - Filter Entry Notes by Gravity Flow Assignee. | |
* @license https://opensource.org/license/gpl-2-0/ GPL-2.0 | |
*/ | |
apply_filters( 'gravityview/entry_notes/get_notes', 'filter_gravityview_notes_by_gravity_flow_assignee', 10, 2 ); | |
/** | |
* Filter the notes by Gravity Flow assignee. | |
* | |
* @param stdClass[]|null $notes Notes as returned by {@see GFFormsModel::get_lead_notes} | |
* @param int $entry_id The entry ID. | |
* | |
* @return array | |
*/ | |
function filter_gravityview_notes_by_gravity_flow_assignee( $notes = array(), $entry_id = 0 ) { | |
if ( ! class_exists( 'Gravity_Flow_API' ) ) { | |
return $notes; | |
} | |
if ( empty( $notes ) ) { | |
return $notes; | |
} | |
$entry = GFAPI::get_entry( $entry_id ); | |
if ( is_wp_error( $entry ) ) { | |
return $notes; | |
} | |
$api = new Gravity_Flow_API( $entry['form_id'] ); | |
$step = $api->get_current_step( $entry ); | |
if ( false === $step ) { | |
return $notes; | |
} | |
$assignees = $step->get_assignees(); | |
if ( empty( $assignees ) ) { | |
return array(); | |
} | |
$assignee_user_ids = array(); | |
foreach ( $assignees as $assignee ) { | |
/** @var \WP_User $assignee_user */ | |
$assignee_user = $assignee->get_user(); | |
if ( ! $assignee_user ) { | |
continue; | |
} | |
$assignee_user_ids[] = $assignee_user->ID; | |
} | |
$notes = array_filter( $notes, function ( $note ) use ( $assignee_user_ids ) { | |
if ( empty( $note->user_id ) ) { | |
return false; | |
} | |
return in_array( $note->user_id, $assignee_user_ids, true ); | |
} ); | |
return $notes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment