Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions includes/class-messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,23 @@ public function friends_display_messages( $args ) {
}
$args['accounts'] = apply_filters( 'friends_message_form_accounts', array(), $args['friend_user'] );

add_filter( 'excerpt_length', array( $this, 'friends_message_excerpt_length' ) );

Friends::template_loader()->get_template_part(
'frontend/messages/friend',
null,
$args
);

remove_filter( 'excerpt_length', array( $this, 'friends_message_excerpt_length' ) );

}
}

public function friends_message_excerpt_length() {
return 10;
}

/**
* Embed the message form for the friend user.
*
Expand Down
17 changes: 9 additions & 8 deletions templates/frontend/messages/friend.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
<strong><?php esc_html_e( 'Messages', 'friends' ); ?></strong>
<?php
foreach ( $args['existing_messages']->get_posts() as $_post ) {
$subject = get_the_title( $_post );
if ( ! $subject ) {
$subject = get_the_excerpt( $_post );
}

$messages = get_posts(
array(
'post_parent' => $_post->ID,
Expand All @@ -32,20 +27,26 @@
);
array_unshift( $messages, $_post );

$class = '';
$classes = array( 'display-message' => true );
$subject = false;
$last_message_time = false;
foreach ( $messages as $message ) {
if ( get_post_status( $message ) === 'friends_unread' ) {
$class .= ' unread';
$classes['unread'] = true;
}
$post_time = get_post_modified_time( 'U', true, $message );
if ( ! $last_message_time || $post_time > $last_message_time ) {
$last_message_time = $post_time;

$subject = get_the_title( $message );
if ( ! $subject ) {
$subject = get_the_excerpt( $message );
}
}
}
?>
<div class="friend-message" id="message-<?php echo esc_attr( $_post->ID ); ?>" data-id="<?php echo esc_attr( $_post->ID ); ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( 'friends-mark-read' ) ); ?>">
<a href="" class="display-message<?php echo esc_attr( $class ); ?>" title="<?php echo esc_attr( date_i18n( $time_format, $last_message_time ) ); ?>">
<a href="" class="<?php echo esc_attr( implode( ' ', array_keys( $classes ) ) ); ?>" title="<?php echo esc_attr( date_i18n( $time_format, $last_message_time ) ); ?>">
<?php
// translators: %s is a time span.
echo esc_html( sprintf( __( '%s ago' ), human_time_diff( $last_message_time ) ) ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
Expand Down