BBP_Forums_Group_Extension::validate_reply_to_id( int $reply_id )

Validate the reply to for a reply in a group forum.


Description Description

This method ensures that when a reply to is saved, it is only allowed to be saved to the current topic.

If all checks fail, an error gets added to prevent the reply from saving.


Parameters Parameters

$reply_id

(Required)


Top ↑

Source Source

File: includes/extend/buddypress/groups.php

	public function validate_reply_to_id( $reply_id = 0 ) {

		// Bail if no reply
		if ( empty( $reply_id ) ) {
			return;
		}

		// Get posted reply to
		$new_reply_to = ! empty( $_POST['bbp_reply_to'] )
			? absint( $_POST['bbp_reply_to'] )
			: 0;

		// Bail if no reply to (assumes topic ID)
		if ( empty( $new_reply_to ) ) {
			return;
		}

		// Get current forum ID
		$forum_id = bbp_get_reply_forum_id( $reply_id );

		// Bail if not a group forum
		if ( ! bbp_is_forum_group_forum( $forum_id ) ) {
			return;
		}

		// Get current group ID
		$group_id = bp_get_current_group_id();

		// Bail if unknown group ID
		if ( empty( $group_id ) ) {
			return;
		}

		// Get current topic ID
		$topic_id = bbp_get_reply_topic_id( $reply_id );

		// Get topic reply IDs
		$reply_ids = bbp_get_public_child_ids( $topic_id, bbp_get_reply_post_type() );

		// Avoid recursion
		unset( $reply_ids[ $reply_id ] );

		// Bail if new reply parent ID is in this topic
		if ( in_array( $new_reply_to, $reply_ids, true ) ) {
			return;
		}

		// Add an error to prevent this reply from saving.
		bbp_add_error( 'bbp_reply_to_id', __( '<strong>ERROR</strong>: Reply To is invalid.', 'bbpress' ) );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.14 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.