BBP_Forums_Admin::toggle_forum()

Toggle forum


Description Description

Handles the admin-side opening/closing of forums


Source Source

File: includes/admin/forums.php

	public function toggle_forum() {

		// Bail if not a forum toggle action
		if ( ! bbp_is_get_request() || empty( $_GET['action'] ) || empty( $_GET['forum_id'] ) ) {
			return;
		}

		// Bail if not an allowed action
		$action = sanitize_key( $_GET['action'] );
		if ( empty( $action ) || ! in_array( $action, $this->get_allowed_action_toggles(), true ) ) {
			return;
		}

		// Bail if forum is missing
		$forum_id = bbp_get_forum_id( $_GET['forum_id'] );
		if ( ! bbp_get_forum( $forum_id ) ) {
			wp_die( esc_html__( 'The forum was not found.', 'bbpress' ) );
		}

		// What is the user doing here?
		if ( ! current_user_can( 'edit_forum', $forum_id ) ) {
			wp_die( esc_html__( 'You do not have permission to do that.', 'bbpress' ) );
		}

		// Defaults
		$post_data = array( 'ID' => $forum_id );
		$message   = '';
		$success   = false;

		switch ( $action ) {
			case 'bbp_toggle_forum_close' :
				check_admin_referer( 'close-forum_' . $forum_id );

				$is_open = bbp_is_forum_open( $forum_id );
				$message = ( true === $is_open )
					? 'closed'
					: 'opened';
				$success = ( true === $is_open )
					? bbp_close_forum( $forum_id )
					: bbp_open_forum( $forum_id );

				break;
		}

		// Setup the message
		$retval = array(
			'bbp_forum_toggle_notice' => $message,
			'forum_id'                => $forum_id
		);

		// Prepare for failure
		if ( ( false === $success ) || is_wp_error( $success ) ) {
			$retval['failed'] = '1';
		}

		// Filter all message args
		$retval = apply_filters( 'bbp_toggle_forum_action_admin', $retval, $forum_id, $action );

		// Do additional forum toggle actions (admin side)
		do_action( 'bbp_toggle_forum_admin', $success, $post_data, $action, $retval );

		// Redirect back to the forum
		$redirect = add_query_arg( $retval, remove_query_arg( array( 'action', 'forum_id' ) ) );
		bbp_redirect( $redirect );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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