我真的很难思考如何解决这个问题。用户可以在我的网站上互相发送私人消息。如下图所示,您可以看到我在左侧显示消息作者,在右下角显示消息收件人。
原始邮件作者发送的第一封邮件(最下方)会按原样正确显示原始邮件收件人(右下角)。
收件人回复初始消息后,新的回复将发送回原始发件人,原始发件人现在是“收件人”,并在右下角显示其元数据(化身+用户名)。
这就是问题所在。原始发件人收到原始收件人的回复后,原始收件人的元数据仍显示在右下角。您可以在底部的第二条消息中看到这一点(只要两个用户仍在同一父线程中发送消息,问题就会继续,如图所示)。
我已经划掉了不应该用红色X显示的内容。我只希望每个邮件的收件人显示在右下角,但我认为,由于代码将邮件本身视为一个“线程”,它希望显示该邮件“线程”的“所有收件人”,而不是只显示每个新发送邮件的收件人。
下面是显示收件人头像+用户名的代码。我现在完全走到了死胡同。有人对如何解决这个问题有什么想法吗?
function get_table_columns() {
$columns = array(
\'recipientname\' => __(\'RecipientsName\', \'front-end-pm\'),
\'recipientimage\' => __(\'RecipientsImage\', \'front-end-pm\')
);
return apply_filters(\'fep_message_table_columns\', $columns );
}
function get_column_content($column) {
$recipients = get_post_meta( get_the_ID(), \'_recipients\' );
$name = array();
$image = array();
foreach( $recipients as $recipient ) {
$name[] = fep_get_userdata( $recipient, \'display_name\', \'id\' );
$image[] = get_avatar ( $recipient, \'id\' );
}
switch( $column ) {
case \'recipientname\' :
?></a></div>
<div class="recipentusername"><a href="<?php echo um_user_profile_url(); ?>" target=\'_blank\'><?php _e("", \'front-end-pm\'); ?> <?php echo implode( $name );
break;
case \'recipientimage\' :
?></a></div><div class="recipientavatar"> <a href="<?php echo um_user_profile_url(); ?>" target=\'_blank\'> <?php echo implode( $image );
break;
下面是存储\\u recipients元密钥的代码,该元密钥存储数据库中所有邮件收件人的用户ID。
// Insert the message into the database
$message_id = wp_insert_post( $post );
if( ! $message_id || is_wp_error( $message_id ) ) {
return false;
}
$inserted_message = get_post( $message_id );
if( ! empty($message[\'message_to_id\'] ) ) { //FRONT END message_to return id of participants
if( is_array( $message[\'message_to_id\'] ) ) {
foreach( $message[\'message_to_id\'] as $participant ) {
add_post_meta( $message_id, \'_participants\', $participant );
add_post_meta( $message_id, \'_recipients\', $participant );
}
} else {
add_post_meta( $message_id, \'_participants\', $message[\'message_to_id\'] );
add_post_meta( $message_id, \'_recipients\', $message[\'message_to_id\'] );
}
}
add_post_meta( $message_id, \'_participants\', $inserted_message->post_author );
if( $inserted_message->post_parent ) {
$participants = get_post_meta( $inserted_message->post_parent, \'_recipients\' );
if( $participants && is_array( $participants ) )
{
foreach( $participants as $participant )
{
delete_post_meta( $inserted_message->post_parent, \'_fep_parent_read_by_\'. $participant );
delete_user_meta( $participant, \'_fep_user_message_count\' );
}
}
if( $recipients && is_array( $recipients ) )
{
foreach( $recipients as $recipient )
{
delete_post_meta( $inserted_message->post_parent, \'_fep_parent_read_by_\'. $recipient );
delete_user_meta( $recipient, \'_fep_user_message_count\' );
}
}
fep_make_read( true, $inserted_message->post_parent, $inserted_message->post_author );
} else {
$participants = get_post_meta( $message_id, \'_participants\' );
if( $participants && is_array( $participants ) )
{
foreach( $participants as $participant )
{
delete_user_meta( $participant, \'_fep_user_message_count\' );
}
}
$recipients = get_post_meta( $message_id, \'_recipients\' );
if( $recipients && is_array( $recipients ) )
{
foreach( $recipients as $recipient )
{
delete_user_meta( $recipient, \'_fep_user_message_count\' );
}
}
}
fep_make_read( true, $message_id, $inserted_message->post_author );
do_action(\'fep_action_message_after_send\', $message_id, $message, $inserted_message );
return $message_id;
下面是定义message\\u to\\u id的代码
function fep_send_message( $message = null, $override = array() )
{
if( null === $message ) {
$message = $_POST;
}
if( ! empty($message[\'fep_parent_id\'] ) ) {
$message[\'post_status\'] = fep_get_option(\'reply_post_status\',\'publish\');
$message[\'message_title\'] = __(\'RE:\', \'front-end-pm\'). \' \' . get_the_title( $message[\'fep_parent_id\'] );
$message[\'message_to_id\'] = get_post_meta( $message[\'fep_parent_id\'], \'_participants\' );
$message[\'post_parent\'] = absint( $message[\'fep_parent_id\'] );
} else {
$message[\'post_status\'] = fep_get_option(\'parent_post_status\',\'publish\');
$message[\'post_parent\'] = 0;
}
$message = apply_filters(\'fep_filter_message_before_send\', $message );
if( empty($message[\'message_title\']) || empty($message[\'message_content\']) ) {
return false;
}
// Create post array
$post = array(
\'post_title\' => $message[\'message_title\'],
\'post_content\' => $message[\'message_content\'],
\'post_status\' => $message[\'post_status\'],
\'post_parent\' => $message[\'post_parent\'],
\'post_type\' => \'fep_message\'
);
if( $override && is_array( $override ) ) {
$post = wp_parse_args( $override, $post );
}
$post = apply_filters(\'fep_filter_message_after_override\', $post );