bbp_update_reply( int $reply_id, int $topic_id, int $forum_id, bool|array $anonymous_data = false, int $author_id, bool $is_edit = false, int $reply_to )
Handle all the extra meta stuff from posting a new reply or editing a reply
Description
Parameters
- $reply_id
-
(Optional) Reply id
- $topic_id
-
(Optional) Topic id
- $forum_id
-
(Optional) Forum id
- $anonymous_data
-
(Optional) logged-out user data.
Default value: false
- $author_id
-
(Optional) Author id
- $is_edit
-
(Optional) Is the post being edited? Defaults to false.
Default value: false
- $reply_to
-
(Optional) Reply to id
Source
File: bp-forums/replies/functions.php
function bbp_update_reply( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0 ) {
// Validate the ID's passed from 'bbp_new_reply' action
$reply_id = bbp_get_reply_id( $reply_id );
$topic_id = bbp_get_topic_id( $topic_id );
$forum_id = bbp_get_forum_id( $forum_id );
$reply_to = bbp_validate_reply_to( $reply_to );
// Bail if there is no reply
if ( empty( $reply_id ) )
return;
// Check author_id
if ( empty( $author_id ) )
$author_id = bbp_get_current_user_id();
// Check topic_id
if ( empty( $topic_id ) )
$topic_id = bbp_get_reply_topic_id( $reply_id );
// Check forum_id
if ( !empty( $topic_id ) && empty( $forum_id ) )
$forum_id = bbp_get_topic_forum_id( $topic_id );
// If anonymous post, store name, email, website and ip in post_meta.
// It expects anonymous_data to be sanitized.
// Check bbp_filter_anonymous_post_data() for sanitization.
if ( !empty( $anonymous_data ) && is_array( $anonymous_data ) ) {
// Parse arguments against default values
$r = bbp_parse_args( $anonymous_data, array(
'bbp_anonymous_name' => '',
'bbp_anonymous_email' => '',
'bbp_anonymous_website' => '',
), 'update_reply' );
// Update all anonymous metas
foreach ( $r as $anon_key => $anon_value ) {
update_post_meta( $reply_id, '_' . $anon_key, (string) $anon_value, false );
}
// Set transient for throttle check (only on new, not edit)
if ( empty( $is_edit ) ) {
set_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted', time() );
}
} else {
if ( empty( $is_edit ) && !current_user_can( 'throttle' ) ) {
bbp_update_user_last_posted( $author_id );
}
}
// Handle Subscription Checkbox
if ( bbp_is_subscriptions_active() && !empty( $author_id ) && !empty( $topic_id ) ) {
$subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
$subscheck = ( !empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] ) ) ? true : false;
// Subscribed and unsubscribing
if ( true === $subscribed && false === $subscheck ) {
bbp_remove_user_subscription( $author_id, $topic_id );
// Subscribing
} elseif ( false === $subscribed && true === $subscheck ) {
bbp_add_user_subscription( $author_id, $topic_id );
}
}
// Reply meta relating to reply position in tree
bbp_update_reply_forum_id( $reply_id, $forum_id );
bbp_update_reply_topic_id( $reply_id, $topic_id );
bbp_update_reply_to ( $reply_id, $reply_to );
// Update associated topic values if this is a new reply
if ( empty( $is_edit ) ) {
// Update poster IP if not editing
update_post_meta( $reply_id, '_bbp_author_ip', bbp_current_author_ip(), false );
// Last active time
$last_active_time = current_time( 'mysql' );
// Walk up ancestors and do the dirty work
bbp_update_reply_walker( $reply_id, $last_active_time, $forum_id, $topic_id, false );
}
}
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.