bbp_toggle_reply_handler( string $action = '' )

Handles the front end spamming/unspamming and trashing/untrashing/deleting of replies


Description Description


Parameters Parameters

$action

(Optional) The requested action to compare this function to

Default value: ''


Top ↑

Source Source

File: includes/replies/functions.php

function bbp_toggle_reply_handler( $action = '' ) {

	// Bail if required GET actions aren't passed
	if ( empty( $_GET['reply_id'] ) ) {
		return;
	}

	// What's the reply id?
	$reply_id = bbp_get_reply_id( (int) $_GET['reply_id'] );

	// Get possible reply-handler toggles
	$toggles = bbp_get_reply_toggles( $reply_id );

	// Bail if action isn't meant for this function
	if ( ! in_array( $action, $toggles, true ) ) {
		return;
	}

	// Make sure reply exists
	$reply = bbp_get_reply( $reply_id );
	if ( empty( $reply ) ) {
		bbp_add_error( 'bbp_toggle_reply_missing', __( '<strong>ERROR</strong>: This reply could not be found or no longer exists.', 'bbpress' ) );
		return;
	}

	// What is the user doing here?
	if ( ! current_user_can( 'edit_reply', $reply_id ) || ( 'bbp_toggle_reply_trash' === $action && ! current_user_can( 'delete_reply', $reply_id ) ) ) {
		bbp_add_error( 'bbp_toggle_reply_permission', __( '<strong>ERROR</strong>: You do not have permission to do that.', 'bbpress' ) );
		return;
	}

	// Sub-action?
	$sub_action = ! empty( $_GET['sub_action'] )
		? sanitize_key( $_GET['sub_action'] )
		: false;

	// Preliminary array
	$post_data = array( 'ID' => $reply_id );

	// Do the reply toggling
	$retval = bbp_toggle_reply( array(
		'id'         => $reply_id,
		'action'     => $action,
		'sub_action' => $sub_action,
		'data'       => $post_data
	) );

	// Do additional reply toggle actions
	do_action( 'bbp_toggle_reply_handler', $retval['status'], $post_data, $action );

	// Redirect back to reply
	if ( ( false !== $retval['status'] ) && ! is_wp_error( $retval['status'] ) ) {
		bbp_redirect( $retval['redirect_to'] );

	// Handle errors
	} else {
		bbp_add_error( 'bbp_toggle_reply', $retval['message'] );
	}
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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