Skip to content

Commit

Permalink
Merge pull request #17 from hivepress/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
hivepress committed Jul 21, 2021
2 parents e1ecdf2 + 92c579d commit cc48d5b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion hivepress-messages.php
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion includes/blocks/class-message-send-form.php
Expand Up @@ -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' );
Expand All @@ -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();
}
}
}
}
Expand Down
20 changes: 13 additions & 7 deletions includes/controllers/class-message.php
Expand Up @@ -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() );
}
}
}
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion templates/message/view/message-attachment.php
Expand Up @@ -4,7 +4,7 @@

if ( $message->get_attachment__id() ) :
?>
<a href="<?php echo esc_url( $message->get_attachment__url( 'full' ) ); ?>" target="_blank" class="hp-message__attachment hp-link">
<a href="<?php echo esc_url( $message->get_attachment__url() ); ?>" target="_blank" class="hp-message__attachment hp-link">
<i class="hp-icon fas fa-file-download"></i>
<span><?php echo esc_html( $message->get_attachment__name() ); ?></span>
</a>
Expand Down

0 comments on commit cc48d5b

Please sign in to comment.