8000 DMs: Preview lastest message by akirk · Pull Request #493 · akirk/friends · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

DMs: Preview lastest message #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2025
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
0