/** * 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; } }
_e('Forum Title:', 'message-board'); ?> </label> <input type="text" id="mb_forum_title" name="mb_forum_title" value="<?php echo esc_attr(mb_get_forum_title()); ?> " /> </p> <p> <label for="mb_post_parent"><?php _e('Parent Forum:', 'message-board'); ?> </label> <?php mb_dropdown_forums(array('name' => 'mb_post_parent', 'id' => 'mb_post_parent', 'show_option_none' => __('(no parent)', 'message-board'), 'option_none_value' => 0, 'selected' => mb_get_forum_parent_id())); ?> </p> <p> <label for="mb_forum_type"><?php _e('Forum Type:', 'message-board'); ?> </label> <select id="mb_forum_type" name="mb_forum_type"> <?php foreach (mb_get_forum_type_objects() as $forum_type) { ?> <option value="<?php echo esc_attr($forum_type->name); ?>
/** * Conditional check to see if a forum allows new topics to be created. * * @since 1.0.0 * @access public * @param int $forum_id * @return bool */ function mb_forum_allows_topics($forum_id = 0) { $forum_id = mb_get_forum_id($forum_id); $parent_id = mb_get_forum_parent_id($forum_id); $allow = true; /* Check if the forum type allows topics. */ if (!mb_forum_type_allows_topics(mb_get_forum_type($forum_id))) { $allow = false; } elseif (!mb_forum_status_allows_topics(mb_get_forum_status($forum_id))) { $allow = false; } elseif (0 < $parent_id && !mb_forum_status_allows_topics(mb_get_forum_status($parent_id))) { $allow = false; } return apply_filters('mb_forum_allows_subforums', $allow, $forum_id); }