bbp_update_reply_walker( int $reply_id, string $last_active_time = '', int $forum_id, int $topic_id, bool $refresh = true )
Walk up the ancestor tree from the current reply, and update all the counts
Description
Parameters
- $reply_id
-
(Optional) Reply id
- $last_active_time
-
(Optional) Last active time
Default value: ''
- $forum_id
-
(Optional) Forum id
- $topic_id
-
(Optional) Topic id
- $refresh
-
(Optional) If set to true, unsets all the previous parameters. Defaults to true
Default value: true
Source
File: bp-forums/replies/functions.php
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 | function bbp_update_reply_walker( $reply_id , $last_active_time = '' , $forum_id = 0, $topic_id = 0, $refresh = true ) { // Verify the reply ID $reply_id = bbp_get_reply_id( $reply_id ); // Reply was passed if ( ! empty ( $reply_id ) ) { // Get the topic ID if none was passed if ( empty ( $topic_id ) ) { $topic_id = bbp_get_reply_topic_id( $reply_id ); } // Get the forum ID if none was passed if ( empty ( $forum_id ) ) { $forum_id = bbp_get_reply_forum_id( $reply_id ); } } // Set the active_id based on topic_id/reply_id $active_id = empty ( $reply_id ) ? $topic_id : $reply_id ; // Setup ancestors array to walk up $ancestors = array_values ( array_unique ( array_merge ( array ( $topic_id , $forum_id ), ( array ) get_post_ancestors( $topic_id ) ) ) ); // If we want a full refresh, unset any of the possibly passed variables if ( true === $refresh ) $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0; // Walk up ancestors if ( ! empty ( $ancestors ) ) { foreach ( $ancestors as $ancestor ) { // Reply meta relating to most recent reply if ( bbp_is_reply( $ancestor ) ) { // @todo - hierarchical replies // Topic meta relating to most recent reply } elseif ( bbp_is_topic( $ancestor ) ) { // Last reply and active ID's bbp_update_topic_last_reply_id ( $ancestor , $reply_id ); bbp_update_topic_last_active_id( $ancestor , $active_id ); // Get the last active time if none was passed $topic_last_active_time = $last_active_time ; if ( empty ( $last_active_time ) ) { $topic_last_active_time = get_post_field( 'post_date' , bbp_get_topic_last_active_id( $ancestor ) ); } // Only update if reply is published if ( bbp_is_reply_published( $reply_id ) ) { bbp_update_topic_last_active_time( $ancestor , $topic_last_active_time ); } // Counts bbp_update_topic_voice_count ( $ancestor ); bbp_update_topic_reply_count ( $ancestor ); bbp_update_topic_reply_count_hidden( $ancestor ); // Forum meta relating to most recent topic } elseif ( bbp_is_forum( $ancestor ) ) { // Last topic and reply ID's bbp_update_forum_last_topic_id( $ancestor , $topic_id ); bbp_update_forum_last_reply_id( $ancestor , $reply_id ); // Last Active bbp_update_forum_last_active_id( $ancestor , $active_id ); // Get the last active time if none was passed $forum_last_active_time = $last_active_time ; if ( empty ( $last_active_time ) ) { $forum_last_active_time = get_post_field( 'post_date' , bbp_get_forum_last_active_id( $ancestor ) ); } // Only update if reply is published if ( bbp_is_reply_published( $reply_id ) ) { bbp_update_forum_last_active_time( $ancestor , $forum_last_active_time ); } // Counts bbp_update_forum_reply_count( $ancestor ); } } } } |
Changelog
Version | Description |
---|---|
bbPress (r2884) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.