Exemplo n.º 1
0
/**
 * Sets the forum type for a specific forum.
 *
 * @since  1.0.0
 * @access public
 * @param  int     $forum_id
 * @param  string  $forum_type
 * @return bool
 */
function mb_set_forum_type($forum_id, $type)
{
    $type = mb_forum_type_exists($type) ? $type : mb_get_normal_forum_type();
    return update_post_meta($forum_id, mb_get_forum_type_meta_key(), $type);
}
Exemplo n.º 2
0
/**
 * Front end new forum handler.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function mb_handler_new_forum()
{
    /* Verify the nonce. */
    if (!mb_check_post_nonce('mb_new_forum_nonce', 'mb_new_forum_action')) {
        return;
    }
    /* Make sure the current user can create forums. */
    if (!current_user_can('create_forums')) {
        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']) ? mb_get_forum_id($_POST['mb_post_parent']) : 0;
    /* Menu order. */
    $menu_order = isset($_POST['mb_menu_order']) ? absint($_POST['mb_menu_order']) : 0;
    /* Post status. */
    $post_status = isset($_POST['mb_post_status']) && in_array($_POST['mb_post_status'], mb_get_forum_post_statuses()) ? $_POST['mb_post_status'] : mb_get_open_post_status();
    /* Publish a new forum. */
    $published = mb_insert_forum(array('post_title' => $post_title, 'post_content' => $post_content, 'post_parent' => $post_parent, 'post_status' => $post_status, 'menu_order' => $menu_order));
    /* If the post was published. */
    if ($published && !is_wp_error($published)) {
        /* Forum type. */
        $forum_type = isset($_POST['mb_forum_type']) && mb_forum_type_exists($_POST['mb_forum_type']) ? sanitize_key($_POST['mb_forum_type']) : 'forum';
        mb_set_forum_type($published, $forum_type);
        /* Forum subscription. */
        if (isset($_POST['mb_forum_subscribe']) && 1 === absint($_POST['mb_forum_subscribe'])) {
            mb_add_user_forum_subscription(mb_get_forum_author_id($published), $published);
        }
        /* Redirect to the published single post. */
        wp_safe_redirect(get_permalink($published));
        exit;
    }
}