お世話になります。
PHPに相当詳しくないと難しいかと思いますが…、
###バグの内容
★概要
「コメントされた」という通知はあっても、「コメントに返信された」という通知がない。
同様の報告
https://bbpress.org/forums/topic/notification-when-reply-in-topic-receives-reply/
★詳細
WordPressの有名プラグイン「BBPress」で掲示板を作り、
「BuddyPress」から通知を受け取っています。
私が作った掲示板にAさんがコメントすると、
「Aさんにコメントされた」
と私に通知があります。
これはいいのですが、
しかし、
Aさんのコメントに誰かが返信しても、
「誰かに返信された」
とAさんに通知が来ないのです。
###試したコード
functions.phpに下記で未解決
php
1/* notifications */ 2 3function jpr_buddypress_add_notification( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0 ) { 4 5 $current_topic_id = bbp_get_topic_id(); 6 $ids_of_subs = bbp_get_topic_subscribers($current_topic_id); 7 8 // this is who the notification goes to. whose post is replied to 9 $topic_author_id = bbp_get_topic_author_id( $reply_to ); 10 11 // Bail if somehow this is hooked to an edit action 12 if ( !empty( $is_edit ) ) { 13 return; 14 } 15 16 // Get author information 17 // $topic_author_id = bp_loggedin_user_id(); 18 $secondary_item_id = $author_id; 19 20 // Hierarchical replies 21 if ( !empty( $reply_to ) ) { 22 $reply_to_item_id = bbp_get_topic_author_id( $reply_to ); 23 } 24 25 // pass the $reply_id to the function that formats the notification 26 $topic_id = $reply_to; 27 28 // Get some reply information 29 $args = array( 30 'user_id' => $topic_author_id, 31 'item_id' => $topic_id, 32 'component_name' => bbp_get_component_name(), 33 'component_action' => 'bbp_new_reply', 34 'date_notified' => get_post( $reply_id )->post_date_gmt, 35 ); 36 37 // Notify the topic author if not the current reply author 38 if ( $author_id !== $topic_author_id ) { 39 $args['secondary_item_id'] = $secondary_item_id ; 40 41 bp_notifications_add_notification( $args ); 42 } 43 // Notify the immediate reply author if not the current reply author 44 if ( !empty( $reply_to ) && ( $author_id !== $reply_to_item_id ) ) { 45 $args['secondary_item_id'] = $secondary_item_id; 46 47 bp_notifications_add_notification( $args ); 48 } 49} 50// remove the bbpress notification function so we don't get dupicate notifications 51remove_action( 'bbp_new_reply', 'bbp_buddypress_add_notification', 10, 7 ); 52add_action( 'bbp_new_reply', 'jpr_buddypress_add_notification', 10, 7 ); 53 54// remove the bbpress format notification function before using our custom function 55remove_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications', 10, 5 ); 56 57function jpr_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { 58 59 // New reply notifications 60 if ( 'bbp_new_reply' === $action ) { 61 $topic_id = bbp_get_reply_id( $item_id ); 62 $topic_title = bbp_get_reply_title( $item_id ); 63 $topic_link = wp_nonce_url( add_query_arg( array( 'action' => 'bbp_mark_read', 'topic_id' => $topic_id ), bbp_get_reply_url( $item_id ) ), 'bbp_mark_topic_' . $topic_id ); 64 $title_attr = __( 'Topic Replies', 'bbpress' ); 65 66 if ( (int) $total_items > 1 ) { 67 $text = sprintf( __( 'You have %d new replies', 'bbpress' ), (int) $total_items ); 68 $filter = 'bbp_multiple_new_subscription_notification'; 69 } else { 70 if ( !empty( $secondary_item_id ) ) { 71 $text = sprintf( __( 'You have %d new reply to %2$s from %3$s', 'bbpress' ), (int) $total_items, $topic_title, bp_core_get_user_displayname( $secondary_item_id ) ); 72 } else { 73 $text = sprintf( __( 'You have %d new reply to %s', 'bbpress' ), (int) $total_items, $topic_title ); 74 } 75 $filter = 'bbp_single_new_subscription_notification'; 76 } 77 78 // WordPress Toolbar 79 if ( 'string' === $format ) { 80 $return = apply_filters( $filter, '<a href="' . esc_url( $topic_link ) . '" title="' . esc_attr( $title_attr ) . '">' . esc_html( $text ) . '</a>', (int) $total_items, $text, $topic_link ); 81 82 // Deprecated BuddyBar 83 } else { 84 $return = apply_filters( $filter, array( 85 'text' => $text, 86 'link' => $topic_link 87 ), $topic_link, (int) $total_items, $text, $topic_title ); 88 } 89 90 do_action( 'jpr_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items ); 91 92 return $return; 93 } 94} 95add_filter( 'bp_notifications_get_notifications_for_user', 'jpr_format_buddypress_notifications', 10, 5 );
###環境
WordPress最新、インストール直後で、プラグインは上の2つしか入れていない状態です。
あなたの回答
tips
プレビュー