Hi Andrii!
Thank you for the reply.
I’ve tried the proposed solution, but I run into a few issues.
First of all a vendor could not see the new button I’m trying to add, and while debuging, I figured out that this happens due to the incorrect user ID on this line
$vendor = \HivePress\Models\Vendor::query()->filter(['user' => $user->get_id()])->get_first();
So, in order to fix that, i’ve replaced it with the $current_user->ID like so:
$current_user = wp_get_current_user();
if ( ! ( $current_user instanceof WP_User ) ) {
return;
}
$vendor = \HivePress\Models\Vendor::query()->filter(['user' => $current_user->ID])->get_first();
This makes the button show up correctly. But When I try to send a message as a Vendor, it tells me “You can’t send messages to yourself.”
Could you help me figure out where the user IDs are being messed up in this situation?
The entire custom code I’m using is the following:
add_filter(
'hivepress/v1/templates/request_view_page/blocks',
function ( $blocks, $template ) {
if(hivepress()->get_version( 'messages' )){
$request = $template->get_context('request');
if(!$request){
return $blocks;
}
$user = $request->get_user();
if(!$user){
return $blocks;
}
$current_user = wp_get_current_user();
if ( ! ( $current_user instanceof WP_User ) ) {
return;
}
$vendor = \HivePress\Models\Vendor::query()->filter(['user' => $current_user->ID])->get_first();
if(!$vendor){
return $blocks;
}
$template->set_context('vendor', $vendor);
return hivepress()->template->merge_blocks(
$blocks,
[
'request_actions_primary' => [
'blocks' => [
'message_send_modal' => [
'type' => 'modal',
'model' => 'vendor',
'title' => hivepress()->translator->get_string( 'send_message' ),
'_capability' => 'read',
'_order' => 5,
'blocks' => [
'message_send_form' => [
'type' => 'message_send_form',
'_order' => 10,
'attributes' => [
'class' => [ 'hp-form--narrow' ],
],
],
],
],
'message_send_link' => [
'type' => 'part',
'path' => 'vendor/view/page/message-send-link',
'_order' => 10,
],
],
],
]
);
}
return $blocks;
},
1000,
2
);
Thanks