diff --git a/hivepress-messages.php b/hivepress-messages.php index 39a9325..c8fb302 100644 --- a/hivepress-messages.php +++ b/hivepress-messages.php @@ -2,7 +2,7 @@ /** * Plugin Name: HivePress Messages * Description: Allow users to send private messages. - * Version: 1.2.8 + * Version: 1.2.9 * Author: HivePress * Author URI: https://hivepress.io/ * Text Domain: hivepress-messages diff --git a/includes/blocks/class-message-send-form.php b/includes/blocks/class-message-send-form.php index a93b304..5df648f 100644 --- a/includes/blocks/class-message-send-form.php +++ b/includes/blocks/class-message-send-form.php @@ -69,7 +69,7 @@ protected function boot() { if ( $vendor ) { $this->values['recipient'] = $vendor->get_user__id(); - } elseif ( hivepress()->get_version( 'marketplace' ) ) { + } elseif ( hivepress()->get_version( 'marketplace' ) || hivepress()->get_version( 'requests' ) ) { // Get order. $order = $this->get_context( 'order' ); @@ -80,6 +80,14 @@ protected function boot() { } else { $this->values['recipient'] = $order->get_buyer__id(); } + } else { + + // Get request. + $request = $this->get_context( 'request' ); + + if ( $request ) { + $this->values['recipient'] = $request->get_user__id(); + } } } } diff --git a/includes/controllers/class-message.php b/includes/controllers/class-message.php index 3373a9b..a8098a2 100644 --- a/includes/controllers/class-message.php +++ b/includes/controllers/class-message.php @@ -144,13 +144,17 @@ public function send_message( $request ) { if ( $message_draft && $message_draft->get_attachment__id() ) { - // Get attachment. - $attachment = $message_draft->get_attachment(); + // Get attachments. + $attachments = $message_draft->get_attachment(); - if ( $attachment ) { + if ( ! is_array( $attachments ) ) { + $attachments = [ $attachments ]; + } + + if ( $attachments ) { // Set attachment. - $message->set_attachment( $attachment->get_id() ); + $message->set_attachment( $message_draft->get_attachment__id() ); } } } @@ -179,9 +183,11 @@ public function send_message( $request ) { return hp\rest_error( 400, $message->_get_errors() ); } - // Set attachment. - if ( isset( $attachment ) ) { - $attachment->set_parent( $message->get_id() )->save_parent(); + // Set attachments. + if ( isset( $attachments ) ) { + foreach ( $attachments as $attachment ) { + $attachment->set_parent( $message->get_id() )->save_parent(); + } $message_draft->set_attachment( null )->save_attachment(); } diff --git a/readme.txt b/readme.txt index 6e5e07f..fdcc60c 100644 --- a/readme.txt +++ b/readme.txt @@ -3,9 +3,9 @@ Contributors: hivepress Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7785WBVGMNB44&source=url Tags: hivepress, messages, directory, listings, classifieds Requires at least: 4.9 -Tested up to: 5.7 +Tested up to: 5.8 Requires PHP: 5.6 -Stable tag: 1.2.8 +Stable tag: 1.2.9 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html diff --git a/templates/message/view/message-attachment.php b/templates/message/view/message-attachment.php index 150bb08..b942397 100644 --- a/templates/message/view/message-attachment.php +++ b/templates/message/view/message-attachment.php @@ -4,7 +4,7 @@ if ( $message->get_attachment__id() ) : ?> - + get_attachment__name() ); ?>