BBP_Forums_Group_Extension::validate_topic_forum_id( int $topic_id )
Validate the forum ID for a topic in a group forum.
Description Description
This method ensures that when a topic is saved, it is only allowed to be saved to a forum that is either:
- A forum in the current group
- A forum the current user can moderate outside of this group
If all checks fail, an error gets added to prevent the topic from saving.
Parameters Parameters
- $topic_id
-
(Required)
Source Source
File: includes/extend/buddypress/groups.php
public function validate_topic_forum_id( $topic_id = 0 ) { // Bail if no topic if ( empty( $topic_id ) ) { return; } // Get current forum ID $forum_id = bbp_get_topic_forum_id( $topic_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 group forum IDs $forum_ids = bbp_get_group_forum_ids( $group_id ); // Get posted forum ID $new_forum_id = ! empty( $_POST['bbp_forum_id'] ) ? absint( $_POST['bbp_forum_id'] ) : 0; // Bail if new forum ID is a forum in this group if ( in_array( $new_forum_id, $forum_ids, true ) ) { return; } // Get the current user ID $user_id = bbp_get_current_user_id(); // Bail if current user can moderate the new forum ID if ( bbp_is_user_forum_moderator( $user_id, $new_forum_id ) ) { return; } // If everything else has failed, then something is wrong and we need // to add an error to prevent this topic from saving. bbp_add_error( 'bbp_topic_forum_id', __( '<strong>ERROR</strong>: Forum ID is invalid.', 'bbpress' ) ); }
Changelog Changelog
Version | Description |
---|---|
2.6.14 | Introduced. |