Skip to content

Instantly share code, notes, and snippets.

@sbrajesh
Created February 19, 2019 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbrajesh/0f9427dcebd9f0b7c47feeaea042c1b8 to your computer and use it in GitHub Desktop.
Save sbrajesh/0f9427dcebd9f0b7c47feeaea042c1b8 to your computer and use it in GitHub Desktop.
Add user report button in message thread.
/**
* Add block/unblock button on single message thread.
*/
function buddydev_show_user_report_button_on_message_thread() {
// only message involving single user can be blocked.
if ( ! function_exists( 'bpmts_report_button' ) || ! bp_is_my_profile() ) {
return;
}
global $thread_template;
if ( ! $thread_template ) {
return;
}
$recipients = wp_list_pluck( $thread_template->thread->recipients, 'user_id' );
if ( empty( $recipients ) ) {
return;
}
$my_id = get_current_user_id();
$other_id = 0;
foreach ( $recipients as $user_id ) {
if ( $user_id != $my_id ) {
$other_id = $user_id;
break;
}
}
if ( ! $other_id ) {
return;
}
bpmts_report_button(
array(
'item_id' => $other_id,
'item_type' => 'user',
'context' => 'bp_message_screen',
'context_id' => bp_displayed_user_id(),
)
);
}
add_action( 'bp_after_message_thread_recipients', 'buddydev_show_user_report_button_on_message_thread' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment