/**
 * Front end edit forum handler.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function mb_handler_edit_forum()
{
    /* Verify the nonce. */
    if (!mb_check_post_nonce('mb_edit_forum_nonce', 'mb_edit_forum_action')) {
        return;
    }
    /* Make sure we have a forum ID. */
    if (!isset($_POST['mb_forum_id'])) {
        mb_bring_the_doom('what-edit');
    }
    /* Get the forum ID. */
    $forum_id = mb_get_forum_id($_POST['mb_forum_id']);
    /* Make sure the current user can edit this forum. */
    if (!current_user_can('edit_forum', $forum_id)) {
        mb_bring_the_doom('no-permission');
    }
    /* Make sure we have a forum title. */
    if (empty($_POST['mb_forum_title'])) {
        mb_bring_the_doom('no-title');
    }
    /* Post title. */
    $post_title = apply_filters('mb_pre_insert_forum_title', $_POST['mb_forum_title']);
    /* Post content. */
    $post_content = apply_filters('mb_pre_insert_forum_content', $_POST['mb_forum_content']);
    /* Forum ID. */
    $post_parent = isset($_POST['mb_post_parent']) ? absint($_POST['mb_post_parent']) : mb_get_forum_parent_id($forum_id);
    /* Menu order. */
    $menu_order = isset($_POST['mb_menu_order']) ? intval($_POST['mb_menu_order']) : mb_get_forum_order($forum_id);
    /* Update the forum. */
    $published = wp_update_post(array('ID' => $forum_id, 'post_title' => $post_title, 'post_content' => $post_content, 'post_parent' => $post_parent, 'menu_order' => $menu_order));
    /* If the post was published. */
    if ($published && !is_wp_error($published)) {
        $user_id = mb_get_forum_author_id($published);
        /* Forum type. */
        if (isset($_POST['mb_forum_type'])) {
            mb_set_forum_type($published, sanitize_key($_POST['mb_forum_type']));
        }
        /* If the user chose to subscribe to the forum. */
        if (isset($_POST['mb_forum_subscribe']) && 1 === absint($_POST['mb_forum_subscribe'])) {
            mb_add_user_forum_subscription($user_id, $published);
        } else {
            mb_remove_user_forum_subscription($user_id, $published);
        }
        /* Redirect to the published topic page. */
        wp_safe_redirect(get_permalink($published));
        exit;
    }
}
/**
 * Returns the forum author URL.
 *
 * @since  1.0.0
 * @access public
 * @param  int     $forum_id
 * @return string
 */
function mb_get_forum_author_url($forum_id = 0)
{
    $forum_id = mb_get_forum_id($forum_id);
    $author_id = mb_get_forum_author_id($forum_id);
    $author_url = $author_id ? mb_get_user_url($author_id) : '';
    return apply_filters('mb_get_forum_author_url', $author_url, $forum_id);
}