</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); ?> "<?php selected(mb_get_forum_type(), $forum_type->name); ?> ><?php echo esc_html($forum_type->label); ?> </option> <?php } ?> </select> </p> <p> <label for="mb_menu_order"><?php _e('Order:', 'message-board'); ?>
/** * Callback for the `save_post` hook to handle meta boxes. * * @since 1.0.0 * @access public * @param int $post_id * @param object $post * @return void */ function save_post($post_id, $post) { /* Fix for attachment save issue in WordPress 3.5. @link http://core.trac.wordpress.org/ticket/21963 */ if (!is_object($post)) { $post = get_post(); } if (mb_get_forum_post_type() !== $post->post_type) { return; } if (!isset($_POST['mb_forum_attr_nonce']) || !wp_verify_nonce($_POST['mb_forum_attr_nonce'], '_mb_forum_attr_nonce')) { return; } /* Set the forum type. */ if (isset($_POST['mb_forum_type']) && mb_get_forum_type($post_id) !== $_POST['mb_forum_type']) { mb_set_forum_type($post_id, sanitize_key($_POST['mb_forum_type'])); } }
/** * Handles the output for custom columns. * * @since 1.0.0 * @access public * @param string $column * @param int $post_id */ public function manage_columns($column, $post_id) { switch ($column) { /* Post status column. */ case 'status': $post_type = mb_get_forum_post_type(); $status = get_post_status_object(mb_get_forum_status($post_id)); /* If the forum has the "publish" post status, change it to "open". */ if (mb_get_publish_post_status() === $status->name) { wp_update_post(array('ID' => $post_id, 'post_status' => mb_get_open_post_status())); } $url = add_query_arg(array('post_status' => $status->name, 'post_type' => $post_type), admin_url('edit.php')); printf('<a href="%s">%s</a>', $url, $status->label); break; /* Forum type column. */ /* Forum type column. */ case 'type': $post_type = mb_get_forum_post_type(); $forum_type = mb_get_forum_type_object(mb_get_forum_type($post_id)); $url = add_query_arg(array('post_type' => $post_type, 'forum_type' => $forum_type->name), admin_url('edit.php')); printf('<a href="%s">%s</a>', $url, $forum_type->label); break; /* Topic count column. */ /* Topic count column. */ case 'subforums': $subforum_count = mb_get_forum_subforum_count($post_id); $subforum_count = !empty($subforum_count) ? absint($subforum_count) : number_format_i18n(0); if (0 < $subforum_count) { printf('<a href="%s">%s</a>', add_query_arg(array('post_type' => mb_get_forum_post_type(), 'post_parent' => $post_id), admin_url('edit.php')), $subforum_count); } else { echo $subforum_count; } break; /* Topic count column. */ /* Topic count column. */ case 'topics': $topic_count = mb_get_forum_topic_count($post_id); $topic_count = !empty($topic_count) ? absint($topic_count) : number_format_i18n(0); if (0 < $topic_count && current_user_can('edit_topics')) { printf('<a href="%s">%s</a>', add_query_arg(array('post_type' => mb_get_topic_post_type(), 'post_parent' => $post_id), admin_url('edit.php')), $topic_count); } else { echo $topic_count; } break; /* Reply count column. */ /* Reply count column. */ case 'replies': $reply_count = mb_get_forum_reply_count($post_id); $reply_count = !empty($reply_count) ? absint($reply_count) : number_format_i18n(0); if (0 < $reply_count && current_user_can('edit_replies')) { printf('<a href="%s">%s</a>', add_query_arg(array('post_type' => mb_get_reply_post_type(), 'mb_forum' => $post_id), admin_url('edit.php')), $reply_count); } else { echo $reply_count; } break; /* Datetime column. */ /* Datetime column. */ case 'datetime': the_time(get_option('date_format')); echo '<br />'; the_time(get_option('time_format')); break; /* Just break out of the switch statement for everything else. */ /* Just break out of the switch statement for everything else. */ default: break; } }
?> </p> </header><!-- .mb-page-header --> <?php if (current_user_can('read_forum', mb_get_forum_id())) { // Check if the current user can read the forum. ?> <?php mb_get_template_part('loop-forum', mb_show_hierarchical_forums() ? 'hierarchical' : 'flat'); ?> <?php if (mb_forum_type_allows_topics(mb_get_forum_type())) { // Only show topics if they're allowed. ?> <?php mb_get_template_part('loop', 'topic'); ?> <?php } // End show topics check. ?> <?php } // End check to see if user can read forum.
/** * Creates a dropdown `<select>` for selecting the forum type in forms. * * @since 1.0.0 * @access public * @param array $args * @return string */ function mb_dropdown_forum_type($args = array()) { $defaults = array('name' => 'mb_forum_type', 'id' => 'mb_forum_type', 'selected' => mb_get_forum_type(), 'echo' => true); $args = wp_parse_args($args, $defaults); $types = mb_get_forum_type_objects(); $out = sprintf('<select name="%s" id="%s">', sanitize_html_class($args['name']), sanitize_html_class($args['id'])); foreach ($types as $type) { $out .= sprintf('<option value="%s"%s>%s</option>', esc_attr($type->name), selected($type->name, $args['selected'], false), $type->label); } $out .= '</select>'; if (!$args['echo']) { return $out; } echo $out; }
/** * @see Walker::start_el() * @since 1.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param object $page Page data object. * @param int $depth Depth of page in reference to parent pages. Used for padding. * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element. * @param int $id */ public function start_el(&$output, $page, $depth = 0, $args = array(), $id = 0) { $forum_type = mb_get_forum_type_object(mb_get_forum_type($page->ID)); $pad = str_repeat(' ', $depth * 3); $output .= "\t<option class=\"level-{$depth}\" value=\"{$page->ID}\""; if ($page->ID == $args['selected']) { $output .= ' selected="selected"'; } $post_status = mb_get_forum_status($page->ID); if (mb_get_forum_post_type() === $args['child_type'] && !mb_forum_allows_subforums($page->ID)) { $output .= ' disabled="disabled"'; } elseif (mb_get_topic_post_type() === $args['child_type'] && !mb_forum_allows_topics($page->ID)) { $output .= ' disabled="disabled"'; } $output .= '>'; $title = $page->post_title; if ('' === $title) { $title = sprintf(__('#%d (no title)'), $page->ID); } /** * Filter the page title when creating an HTML drop-down list of pages. * * @since 3.1.0 * * @param string $title Page title. * @param object $page Page data object. */ $title = apply_filters('list_pages', $title, $page); $output .= $pad . esc_html($title); $output .= "</option>\n"; }
/** * Forum attribute meta box. This handles the forum type, parent, and menu order. * * @since 1.0.0 * @access public * @param object $post * @return void */ function mb_forum_attributes_meta_box($post) { wp_nonce_field('_mb_forum_attr_nonce', 'mb_forum_attr_nonce'); $forum_types = mb_get_forum_type_objects(); ?> <p> <label for="mb_forum_type"> <strong><?php _e('Forum Type:', 'message-board'); ?> </strong> </label> </p> <p> <?php mb_dropdown_forum_type(array('selected' => mb_get_forum_type($post->ID))); ?> </p> <p> <label for="mb_parent_forum"> <strong><?php _e('Parent Forum:', 'message-board'); ?> </strong> </label> </p> <p> <?php mb_dropdown_forums(array('name' => 'parent_id', 'id' => 'mb_parent_forum', 'show_option_none' => __('(no parent)', 'message-board'), 'option_none_value' => 0, 'selected' => $post->post_parent)); ?> </p> <p> <label for="mb_menu_order"><strong><?php _e('Order:', 'message-board'); ?> </strong></label> </p> <p> <input type="number" name="menu_order" id="mb_menu_order" value="<?php echo esc_attr($post->menu_order); ?> " /> </p><?php }