function mb_forum_rewrite_tags($post_type, $args) { if (mb_get_forum_post_type() !== $post_type) { return; } add_rewrite_tag("%{$post_type}%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type={$post_type}&pagename="); // add_rewrite_tag("%{$post_type}%", '([^/]+)', "post_type=$post_type&pagename="); $permastruct_args = $args->rewrite; $permastruct_args['feed'] = $permastruct_args['feeds']; add_permastruct($post_type, mb_get_forum_slug() . "/%{$post_type}%", $permastruct_args); }
/** * Plugin functions and filters for users. * * @package MessageBoard * @subpackage Includes * @author Justin Tadlock <*****@*****.**> * @copyright Copyright (c) 2014, Justin Tadlock * @link https://github.com/justintadlock/message-board * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ function mb_set_user_forum_count($user_id) { global $wpdb; $open_status = mb_get_open_post_status(); $close_status = mb_get_close_post_status(); $publish_status = mb_get_publish_post_status(); $hidden_status = mb_get_hidden_post_status(); $private_status = mb_get_private_post_status(); $where = $wpdb->prepare("WHERE post_author = %d AND post_type = %s", $user_id, mb_get_forum_post_type()); $status_where = "AND (post_status = '{$open_status}' OR post_status = '{$close_status}' OR post_status = '{$publish_status}' OR post_status = '{$private_status}' OR post_status = '{$hidden_status}')"; $count = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} {$where} {$status_where}"); update_user_meta($user_id, mb_get_user_forum_count_meta_key(), $count); return $count; }
/** * Adds the board home link to `$items` array. * * @since 1.0.0 * @access public * @return void */ public function mb_do_board_home_link() { if (mb_is_forum_front()) { return; } $show_on_front = mb_get_show_on_front(); if ('forums' === $show_on_front) { $object = get_post_type_object(mb_get_forum_post_type()); $label = mb_get_forum_label('archive_title'); } elseif ('topics' === $show_on_front) { $object = get_post_type_object(mb_get_topic_post_type()); $label = mb_get_topic_label('archive_title'); } $this->items[] = sprintf('<a href="%s">%s</a>', esc_url(get_post_type_archive_link($object->name)), $label); }
/** * 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; } }
/** * Makes sure the correct post status is used when loading forums on the nav menus screen. By * default, WordPress will only load them if they have the "publish" post status. * * @since 1.0.0 * @access public * @param object $object * @return object */ public function nav_menu_meta_box_object($object) { if (isset($object->name) && mb_get_forum_post_type() === $object->name) { $statuses = array(mb_get_open_post_status(), mb_get_close_post_status(), mb_get_publish_post_status(), mb_get_private_post_status(), mb_get_hidden_post_status(), mb_get_archive_post_status()); $object->_default_query = wp_parse_args(array('post_status' => $statuses), $object->_default_query); } return $object; }
/** * This is a filter on `posts_clauses` that allows the plugin to work around core WP expecting * hierarchical post types to have hierarchical permalinks. Rather, we want our forums to be * flat, so we need to make sure the correct forum is queried on single forum views. We do this * by overwriting the "where" clause and querying by the post name. * * @since 1.0.0 * @access public * @param array $clauses * @param object $query * @return array */ function mb_posts_clauses($clauses, $query) { global $wpdb; $type = mb_get_forum_post_type(); if ($query->get($type) && $query->get('post_type') && $type === $query->get('post_type')) { $clauses['where'] = $wpdb->prepare(" AND {$wpdb->posts}.post_name = %s AND {$wpdb->posts}.post_type = %s", sanitize_title_for_query($query->get($type)), $type); } return $clauses; }
/** * Callback function on the `after_delete_post` hook for when a forum is deleted. * * @todo All forum topics need to become orphans at this point. Attempt to move topics into parent if avail. * @todo Reset counts for parent forums. * @todo `wp_die()` if this is the default forum. * * @since 1.0.0 * @access public * @param int $post_id * @return void */ function mb_after_delete_forum($post_id) { global $wpdb; $mb = message_board(); if (is_object($mb->deleted_post) && $mb->deleted_post->ID === $post_id) { $forum_id = mb_get_forum_id($post_id); $user_id = mb_get_user_id($post->deleted_post->post_author); $parent_forum_id = $mb->deleted_post->post_parent; /* Get the current forum's subforum IDs. */ $subforum_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_parent = %s ORDER BY menu_order DESC", mb_get_forum_post_type(), absint($forum_id))); if (!empty($subforum_ids)) { $moved_forums = false; while (0 < $parent_forum_id) { if (mb_forum_allows_subforums($parent_forum_id)) { /* Change all of the subforums' parents to the new forum ID. */ $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID IN (" . implode(',', $subforum_ids) . ")", absint($parent_forum_id))); /* Reset data based on new forum. */ mb_reset_forum_data($parent_forum_id); $parent_forum_id = 0; $moved_forums = true; /* Break out of the while loop at this point. */ break; } $post = get_post($parent_forum_id); $parent_forum_id = $post->post_parent; } /* If subforums didn't get moved to a new forum, make them a top-level forum. */ if (false === $moved_forums) { $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID IN (" . implode(',', $subforum_ids) . ")", 0)); } } $parent_forum_id = $mb->deleted_post->post_parent; /* Get the current forum's topic IDs. */ $topic_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_parent = %s ORDER BY menu_order DESC", mb_get_topic_post_type(), absint($forum_id))); if (!empty($topic_ids)) { $moved_topics = false; while (0 < $parent_forum_id) { if (mb_forum_allows_topics($parent_forum_id)) { /* Change all of the topics' parents to the new forum ID. */ $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID IN (" . implode(',', $topic_ids) . ")", absint($parent_forum_id))); /* Reset data based on new forum. */ mb_reset_forum_data($parent_forum_id); $parent_forum_id = 0; $moved_topics = true; /* Break out of the while loop at this point. */ break; } $post = get_post($parent_forum_id); $parent_forum_id = $post->post_parent; } /* If topics didn't get moved to a new forum, set their status to "orphan". */ if (false === $moved_topics) { $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE ID IN (" . implode(',', $topic_ids) . ")", mb_get_orphan_post_status())); } } /* Reset user forum count. */ mb_set_user_forum_count($user_id); } }
/** * Resets a forum's subforum count. * * @todo Update the $status_where to use any published forum status rather than hardcoding them. * * @since 1.0.0 * @access public * @param int $forum_id * @global object $wpdb * @return int */ function mb_reset_forum_subforum_count($forum_id) { global $wpdb; $forum_id = mb_get_forum_id($forum_id); $open_status = mb_get_open_post_status(); $close_status = mb_get_close_post_status(); $publish_status = mb_get_publish_post_status(); $hidden_status = mb_get_hidden_post_status(); $private_status = mb_get_private_post_status(); $archive_status = mb_get_archive_post_status(); $where = $wpdb->prepare("WHERE post_parent = %d AND post_type = %s", $forum_id, mb_get_forum_post_type()); $status_where = "AND (post_status = '{$open_status}' OR post_status = '{$close_status}' OR post_status = '{$publish_status}' OR post_status = '{$private_status}' OR post_status = '{$hidden_status}' OR post_status = '{$archive_status}')"; $count = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} {$where} {$status_where}"); mb_set_forum_subforum_count($forum_id, $count); return $count; }
/** * @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 activity dashboard widget. * * @since 1.0.0 * @access public * @return void */ function mb_dashboard_activity_meta_box() { $statuses = mb_get_published_post_statuses(); $post_types = array(mb_get_forum_post_type(), mb_get_topic_post_type(), mb_get_reply_post_type()); ?> <div class="count-block"> <span class="dashicons dashicons-format-chat"></span> <ul> <?php foreach ($post_types as $type) { $count = 0; $num_posts = wp_count_posts($type); foreach ((array) $num_posts as $status => $num) { if (in_array($status, $statuses)) { $count = $count + absint($num); } } $post_type_object = get_post_type_object($type); $text = translate_nooped_plural($post_type_object->labels->mb_dashboard_count, $count, 'message-board'); $text = sprintf($text, number_format_i18n($count)); $class = sanitize_html_class('mb-' . mb_translate_post_type($type) . '-count'); if ($post_type_object && current_user_can($post_type_object->cap->edit_posts)) { printf('<li><a class="%s" href="%s">%s</a></li>', $class, add_query_arg('post_type', $type, admin_url('edit.php')), $text); } else { printf('<li><span class="%s">%s</span></li>', $class, $text); } } ?> </ul> </div><!-- .count-block --> <div id="mb-activity-widget"> <?php $args = array('posts_per_page' => 7, 'post_type' => $post_types, 'post_status' => $statuses, 'order' => 'DESC', 'orderby' => 'date', 'no_found_rows' => true, 'cache_results' => false, 'perm' => 'readable'); $loop = new WP_Query($args); if ($loop->have_posts()) { ?> <div class="activity-block"> <h4><?php _e('Recently Published', 'message-board'); ?> </h4> <ul> <?php $today = date('Y-m-d', current_time('timestamp')); $tomorrow = date('Y-m-d', strtotime('+1 day', current_time('timestamp'))); ?> <?php while ($loop->have_posts()) { ?> <?php $loop->the_post(); $time = get_the_time('U'); if (date('Y-m-d', $time) == $today) { $relative = __('Today'); } else { /* translators: date and time format for recent posts on the dashboard, see http://php.net/date */ $relative = date_i18n(__('M jS'), $time); } $url = current_user_can('edit_post', get_the_ID()) ? get_edit_post_link() : get_permalink(); $format = __('<span>%1$s, %2$s</span> %3$s', 'message-board'); $link = sprintf('<a href="%s">%s</a>', $url, get_the_title()); printf("<li>{$format}</li>", $relative, get_the_time(), $link); } ?> </ul> </div><!-- .activity-block --> <?php } ?> <?php wp_reset_postdata(); ?> </div> <?php }
/** * Post updated messages in the admin. * * @since 1.0.0 * @access public * @return void */ function mb_post_updated_messages($messages) { global $post, $post_ID; $forum_type = mb_get_forum_post_type(); $topic_type = mb_get_topic_post_type(); $reply_type = mb_get_reply_post_type(); $messages[$forum_type] = array(0 => '', 1 => sprintf(__('Forum updated. <a href="%s">View forum</a>', 'message-board'), esc_url(get_permalink($post_ID))), 2 => '', 3 => '', 4 => __('Forum updated.', 'message-board'), 5 => isset($_GET['revision']) ? sprintf(__('Forum restored to revision from %s', 'message-board'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('Forum published. <a href="%s">View forum</a>', 'message-board'), esc_url(get_permalink($post_ID))), 7 => __('Forum saved.', 'message-board'), 8 => '', 9 => '', 10 => ''); $messages[$topic_type] = array(0 => '', 1 => sprintf(__('Topic updated. <a href="%s">View topic</a>', 'message-board'), esc_url(get_permalink($post_ID))), 2 => '', 3 => '', 4 => __('Topic updated.', 'message-board'), 5 => isset($_GET['revision']) ? sprintf(__('Topic restored to revision from %s', 'message-board'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('Topic published. <a href="%s">View topic</a>', 'message-board'), esc_url(get_permalink($post_ID))), 7 => __('Topic saved.', 'message-board'), 8 => '', 9 => '', 10 => ''); $messages[$reply_type] = array(0 => '', 1 => sprintf(__('Reply updated. <a href="%s">View reply</a>', 'message-board'), esc_url(get_permalink($post_ID))), 2 => '', 3 => '', 4 => __('Reply updated.', 'message-board'), 5 => isset($_GET['revision']) ? sprintf(__('Reply restored to revision from %s', 'message-board'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('Reply published. <a href="%s">View reply</a>', 'message-board'), esc_url(get_permalink($post_ID))), 7 => __('Reply saved.', 'message-board'), 8 => '', 9 => '', 10 => ''); return $messages; }
/** * Filter on `body_class` to add custom classes for the plugin's pages on the front end. * * @todo Remove `bbpress` class. * @todo Decide on class naming system. * * @since 1.0.0 * @access public * @param array $classes * @return array */ function mb_body_class($classes) { global $wp; if (mb_is_message_board()) { $classes[] = 'mb'; $classes[] = 'bbpress'; // temporary class for compat $forum_type = mb_get_forum_post_type(); $topic_type = mb_get_topic_post_type(); $reply_type = mb_get_reply_post_type(); $_classes = $classes; $remove = array("single-{$forum_type}", "single-{$topic_type}", "single-{$reply_type}", "singular-{$forum_type}", "singular-{$topic_type}", "singular-{$reply_type}", "archive-{$forum_type}", "archive-{$topic_type}", "archive-{$reply_type}"); foreach ($_classes as $class_key => $class_value) { if (in_array($class_value, $remove)) { unset($classes[$class_key]); } } if (mb_is_forum_front()) { $classes[] = 'forum-front'; } elseif (mb_is_single_forum()) { $classes[] = 'single-forum'; } elseif (mb_is_single_topic()) { $classes[] = 'single-topic'; } elseif (mb_is_single_reply()) { $classes[] = 'single-reply'; } elseif (mb_is_single_role()) { $classes[] = 'single-role'; } elseif (mb_is_forum_archive()) { $classes[] = 'archive-forum'; } elseif (mb_is_topic_archive()) { $classes[] = 'archive-topic'; } elseif (mb_is_reply_archive()) { $classes[] = 'archive-reply'; } elseif (mb_is_role_archive()) { $classes[] = 'archive-role'; } elseif (mb_is_user_archive()) { $classes[] = 'archive-user'; } } return $classes; }
/** * Overwrites capabilities in certain scenarios. * * @since 1.0.0 * @access public * @param array $caps * @param string $cap * @param int $user_id * @param array $args * @return array */ function mb_forum_map_meta_cap($caps, $cap, $user_id, $args) { /* Checks if a user can read a specific forum. */ if ('read_post' === $cap && mb_is_forum($args[0])) { $post = get_post($args[0]); if ($user_id != $post->post_author) { $parent_id = $post->post_parent; /* If we have a parent forum and the user can't read it, don't allow reading this forum. */ if (0 < $parent_id && !mb_user_can($user_id, 'read_forum', $parent_id)) { $caps = array('do_not_allow'); /* If the user can read the parent forum, check if they can read this one. */ } else { $post_type = get_post_type_object($post->post_type); $post_status = mb_get_forum_status($post->ID); $status_obj = get_post_status_object($post_status); if (mb_get_hidden_post_status() === $status_obj->name) { $caps[] = $post_type->cap->read_hidden_forums; } elseif (mb_get_private_post_status() === $status_obj->name) { $caps[] = $post_type->cap->read_private_posts; } elseif ($post_type->cap->read !== $post_type->cap->read_others_forums) { $caps[] = $post_type->cap->read_others_forums; } else { $caps = array(); } } } else { $caps = array(); } /* Meta cap for editing a single forum. */ } elseif ('edit_post' === $cap && mb_is_forum($args[0])) { $post = get_post($args[0]); $forum_obj = get_post_type_object(mb_get_forum_post_type()); if ($user_id != $post->post_author) { // Open forums. if (mb_is_forum_open($args[0])) { $caps[] = $forum_obj->cap->edit_open_forums; } elseif (mb_is_forum_closed($args[0])) { $caps[] = $forum_obj->cap->edit_closed_forums; } elseif (mb_is_forum_hidden($args[0])) { $caps[] = $forum_obj->cap->edit_hidden_forums; } } /* Meta cap for opening a single forum. */ } elseif ('open_forum' === $cap) { $caps = array(); $caps[] = user_can($user_id, 'edit_forum', $args[0]) ? 'open_forums' : 'do_not_allow'; /* Meta cap for closing a single forum. */ } elseif ('close_forum' === $cap) { $caps = array(); $caps[] = user_can($user_id, 'edit_forum', $args[0]) ? 'close_forums' : 'do_not_allow'; /* Meta cap for privatizing a single forum. */ } elseif ('privatize_forum' === $cap) { $caps = array(); $caps[] = user_can($user_id, 'edit_forum', $args[0]) ? 'privatize_forums' : 'do_not_allow'; /* Meta cap for hiding a single forum. */ } elseif ('hide_forum' === $cap) { $caps = array(); $caps[] = user_can($user_id, 'edit_forum', $args[0]) ? 'hide_forums' : 'do_not_allow'; /* Meta cap for spamming a single forum. */ } elseif ('archive_forum' === $cap) { $caps = array(); $caps[] = user_can($user_id, 'edit_forum', $args[0]) ? 'archive_forums' : 'do_not_allow'; /* Meta cap for deleting a specific forum. */ } elseif ('delete_post' === $cap && mb_is_forum($args[0])) { $forum_id = mb_get_forum_id($args[0]); if (mb_get_default_forum_id() === $forum_id) { $caps = array('do_not_allow'); } /* Meta cap check for accessing the forum form. */ } elseif ('access_forum_form' === $cap) { $caps = array('create_forums'); /* If this is a single forum page, check if user can create sub-forums. */ if (mb_is_single_forum()) { $forum_id = mb_get_forum_id(); if (!current_user_can('read_forum', $forum_id)) { $caps[] = 'do_not_allow'; } elseif (!mb_forum_allows_subforums($forum_id)) { $caps[] = 'do_not_allow'; } } elseif (mb_is_forum_edit() && !user_can($user_id, 'edit_post', mb_get_forum_id())) { $caps[] = 'do_not_allow'; } } return $caps; }
function mb_dropdown_post_status($args = array()) { $defaults = array('post_type' => mb_get_forum_post_type(), 'exclude' => '', 'name' => 'post_status', 'id' => 'post_status', 'selected' => '', 'echo' => true); $args = wp_parse_args($args, $defaults); $post_type_object = get_post_type_object($args['post_type']); if (mb_get_forum_post_type() === $args['post_type']) { $stati = apply_filters('mb_select_forum_post_statuses', mb_get_forum_post_statuses()); } elseif (mb_get_topic_post_type() === $args['post_type']) { $stati = apply_filters('mb_select_topic_post_statuses', mb_get_topic_post_statuses()); } elseif (mb_get_reply_post_type() === $args['post_type']) { $stati = apply_filters('mb_select_reply_post_statuses', mb_get_reply_post_statuses()); } if (is_array($args['exclude'])) { $stati = array_diff($stati, $args['exclude']); } $out = sprintf('<select name="%s" id="%s">', sanitize_html_class($args['name']), sanitize_html_class($args['id'])); $current_status_object = get_post_status_object($args['selected']); $current_status_cap = isset($current_status_object->mb_capability) ? $current_status_object->mb_capability : 'edit_posts'; $current_status_cap = $post_type_object->cap->{$current_status_cap}; if (!empty($args['selected']) && !current_user_can($current_status_cap)) { $status_obj = $current_status_object; $out .= sprintf('<option value="%s"%s>%s</option>', esc_attr($status_obj->name), selected($status_obj->name, $args['selected'], false), $status_obj->label); } else { foreach ($stati as $status) { $status_obj = get_post_status_object($status); $status_cap = isset($status_obj->mb_capability) ? $status_obj->mb_capability : 'edit_posts'; $status_cap = $post_type_object->cap->{$status_cap}; if (!current_user_can($status_cap) || false === $status_obj->mb_show_in_status_select) { continue; } $out .= sprintf('<option value="%s"%s>%s</option>', esc_attr($status_obj->name), selected($status_obj->name, $args['selected'], false), $status_obj->label); } } $out .= '</select>'; if (!$args['echo']) { return $out; } echo $out; }
/** * Notifies users by email when a new post is published. By default, notifications are sent to users * who are subscribed to a particular forum or a particular topic. * * @since 1.0.0 * @access public * @param object|int $post * @return void */ function mb_notify_subscribers($post) { $post = !is_object($post) ? get_post($post) : $post; $forum_type = mb_get_forum_post_type(); $topic_type = mb_get_topic_post_type(); $reply_type = mb_get_reply_post_type(); if (!in_array($post->post_type, array($forum_type, $topic_type, $reply_type))) { return; } do_action('mb_before_notify_subscribers', $post); if ($topic_type === $post->post_type) { //mb_notify_forum_subscribers( $post ); } elseif ($reply_type === $post->post_type) { //mb_notify_forum_subscribers( $post ); mb_notify_topic_subscribers($post->post_parent, $post); } do_action('mb_after_notify_subscribers', $post); }
<label for="mb_forum_type"><?php mb_forum_label('mb_form_type'); ?> </label> <?php mb_dropdown_forum_type(); ?> </p><!-- .mb-form-type --> <p class="mb-form-status"> <label for="mb_post_status"><?php mb_forum_label('mb_form_status'); ?> </label> <?php mb_dropdown_post_status(array('post_type' => mb_get_forum_post_type(), 'name' => 'mb_post_status', 'id' => 'mb_post_status', 'selected' => mb_get_forum_status())); ?> </p><!-- .mb-form-status --> <p class="mb-form-order"> <label for="mb_menu_order"><?php mb_forum_label('mb_form_order'); ?> </label> <input type="number" id="mb_menu_order" name="mb_menu_order" value="<?php echo esc_attr(mb_get_forum_order()); ?> " /> </p><!-- .mb-form-order --> <div class="mb-form-content">