Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
bbp_toggle_topic( array $args = array() )
Do the actual topic toggling
Description Description
This function is used by bbp_toggle_topic_handler()
to do the actual heavy lifting when it comes to toggling topic. It only really makes sense to call within that context, so if you need to call this function directly, make sure you’re also doing what the handler does too.
Parameters Parameters
- $args
-
(Optional)
Default value: array()
Source Source
File: includes/topics/functions.php
function bbp_toggle_topic( $args = array() ) { // Parse the arguments $r = bbp_parse_args( $args, array( 'id' => 0, 'action' => '', 'sub_action' => '', 'data' => array() ) ); // Build the nonce suffix $nonce_suffix = bbp_get_topic_post_type() . '_' . (int) $r['id']; // Default return values $retval = array( 'status' => 0, 'message' => '', 'redirect_to' => bbp_get_topic_permalink( $r['id'], bbp_get_redirect_to() ), 'view_all' => false ); // What action are we trying to perform? switch ( $r['action'] ) { // Toggle approve/unapprove case 'bbp_toggle_topic_approve' : check_ajax_referer( "approve-{$nonce_suffix}" ); $is_pending = bbp_is_topic_pending( $r['id'] ); $retval['view_all'] = ! $is_pending; // Toggle $retval['status'] = ( true === $is_pending ) ? bbp_approve_topic( $r['id'] ) : bbp_unapprove_topic( $r['id'] ); // Feedback $retval['message'] = ( true === $is_pending ) ? __( '<strong>ERROR</strong>: There was a problem approving the topic.', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem unapproving the topic.', 'bbpress' ); break; // Toggle open/close case 'bbp_toggle_topic_close' : check_ajax_referer( "close-{$nonce_suffix}" ); $is_open = bbp_is_topic_open( $r['id'] ); // Toggle $retval['status'] = ( true === $is_open ) ? bbp_close_topic( $r['id'] ) : bbp_open_topic( $r['id'] ); // Feedback $retval['message'] = ( true === $is_open ) ? __( '<strong>ERROR</strong>: There was a problem closing the topic.', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem opening the topic.', 'bbpress' ); break; // Toggle sticky/super-sticky/unstick case 'bbp_toggle_topic_stick' : check_ajax_referer( "stick-{$nonce_suffix}" ); $is_sticky = bbp_is_topic_sticky( $r['id'] ); $is_super = false === $is_sticky && ! empty( $_GET['super'] ) && ( "1" === $_GET['super'] ) ? true : false; // Toggle $retval['status'] = ( true === $is_sticky ) ? bbp_unstick_topic( $r['id'] ) : bbp_stick_topic( $r['id'], $is_super ); // Feedback $retval['message'] = ( true === $is_sticky ) ? __( '<strong>ERROR</strong>: There was a problem unsticking the topic.', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem sticking the topic.', 'bbpress' ); break; // Toggle spam case 'bbp_toggle_topic_spam' : check_ajax_referer( "spam-{$nonce_suffix}" ); $is_spam = bbp_is_topic_spam( $r['id'] ); $retval['view_all'] = ! $is_spam; // Toggle $retval['status'] = ( true === $is_spam ) ? bbp_unspam_topic( $r['id'] ) : bbp_spam_topic( $r['id'] ); // Feedback $retval['message'] = ( true === $is_spam ) ? __( '<strong>ERROR</strong>: There was a problem unmarking the topic as spam.', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem marking the topic as spam.', 'bbpress' ); break; // Toggle trash case 'bbp_toggle_topic_trash' : switch ( $r['sub_action'] ) { case 'trash': check_ajax_referer( "trash-{$nonce_suffix}" ); $retval['view_all'] = true; $retval['status'] = wp_trash_post( $r['id'] ); $retval['message'] = __( '<strong>ERROR</strong>: There was a problem trashing the topic.', 'bbpress' ); $retval['redirect_to'] = current_user_can( 'view_trash' ) ? bbp_get_topic_permalink( $r['id'] ) : bbp_get_forum_permalink( bbp_get_topic_forum_id( $r['id'] ) ); break; case 'untrash': check_ajax_referer( "untrash-{$nonce_suffix}" ); $retval['status'] = wp_untrash_post( $r['id'] ); $retval['message'] = __( '<strong>ERROR</strong>: There was a problem untrashing the topic.', 'bbpress' ); $retval['redirect_to'] = bbp_get_topic_permalink( $r['id'] ); break; case 'delete': check_ajax_referer( "delete-{$nonce_suffix}" ); $retval['status'] = wp_delete_post( $r['id'] ); $retval['message'] = __( '<strong>ERROR</strong>: There was a problem deleting the topic.', 'bbpress' ); $retval['redirect_to'] = bbp_get_forum_permalink( $retval['status']->post_parent ); break; } break; } // Add view all if needed if ( ! empty( $retval['view_all'] ) ) { $retval['redirect_to'] = bbp_add_view_all( $retval['redirect_to'], true ); } // Filter & return return apply_filters( 'bbp_toggle_topic', $retval, $r, $args ); }
Changelog Changelog
Version | Description |
---|---|
2.6.0 | Introduced. |