BBP_Topics_Admin::attributes_metabox_save( int $topic_id )
Pass the topic attributes for processing
Description
Parameters
- $topic_id
-
(Required) Topic id
Return
(int) Parent id
Source
File: bp-forums/admin/topics.php
public function attributes_metabox_save( $topic_id ) {
if ( $this->bail() ) return $topic_id;
// Bail if doing an autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $topic_id;
// Bail if not a post request
if ( ! bbp_is_post_request() )
return $topic_id;
// Nonce check
if ( empty( $_POST['bbp_topic_metabox'] ) || !wp_verify_nonce( $_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save' ) )
return $topic_id;
// Bail if current user cannot edit this topic
if ( !current_user_can( 'edit_topic', $topic_id ) )
return $topic_id;
// Get the forum ID
$forum_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0;
// Get topic author data
$anonymous_data = bbp_filter_anonymous_post_data();
$author_id = bbp_get_topic_author_id( $topic_id );
$is_edit = (bool) isset( $_POST['save'] );
// Formally update the topic
bbp_update_topic( $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit );
// Stickies
if ( !empty( $_POST['bbp_stick_topic'] ) && in_array( $_POST['bbp_stick_topic'], array( 'stick', 'super', 'unstick' ) ) ) {
// What's the haps?
switch ( $_POST['bbp_stick_topic'] ) {
// Sticky in this forum
case 'stick' :
bbp_stick_topic( $topic_id );
break;
// Super sticky in all forums
case 'super' :
bbp_stick_topic( $topic_id, true );
break;
// Normal
case 'unstick' :
default :
bbp_unstick_topic( $topic_id );
break;
}
}
// Allow other fun things to happen
do_action( 'bbp_topic_attributes_metabox_save', $topic_id, $forum_id );
do_action( 'bbp_author_metabox_save', $topic_id, $anonymous_data );
return $topic_id;
}
Changelog
| Version | Description |
|---|---|
| bbPress (r2746) | 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.