本文整理汇总了PHP中bbp_is_forum_closed函数的典型用法代码示例。如果您正苦于以下问题:PHP bbp_is_forum_closed函数的具体用法?PHP bbp_is_forum_closed怎么用?PHP bbp_is_forum_closed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bbp_is_forum_closed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_bbp_is_forum_closed
/**
* @covers ::bbp_is_forum_closed
*/
public function test_bbp_is_forum_closed()
{
$f = $this->factory->forum->create();
$forum = bbp_is_forum_closed($f);
$this->assertFalse($forum);
bbp_close_forum($f);
$forum = bbp_is_forum_closed($f);
$this->assertTrue($forum);
}
示例2: bbp_topic_id
?>
<div id="no-reply-<?php
bbp_topic_id();
?>
" class="bbp-no-reply">
<div class="bbp-template-notice">
<p><?php
printf(esc_html__('The topic ‘%s’ is closed to new replies.', 'monsoon'), bbp_get_topic_title());
?>
</p>
</div>
</div>
<?php
} elseif (bbp_is_forum_closed(bbp_get_topic_forum_id())) {
?>
<div id="no-reply-<?php
bbp_topic_id();
?>
" class="bbp-no-reply">
<div class="bbp-template-notice">
<p><?php
printf(esc_html__('The forum ‘%s’ is closed to new topics and replies.', 'monsoon'), bbp_get_forum_title(bbp_get_topic_forum_id()));
?>
</p>
</div>
</div>
<?php
示例3: bbp_topic_form_fields
<?php
bbp_topic_form_fields();
?>
</fieldset>
<?php
do_action('bbp_theme_after_topic_form');
?>
</form>
</div>
<?php
} elseif (bbp_is_forum_closed()) {
?>
<div id="no-topic-<?php
bbp_topic_id();
?>
" class="bbp-no-topic">
<div class="bbp-template-notice">
<p><?php
printf(__('The forum ‘%s’ is closed to new topics and replies.', 'bbpress'), bbp_get_forum_title());
?>
</p>
</div>
</div>
<?php
示例4: bbp_edit_topic_handler
//.........这里部分代码省略.........
// Filter anonymous data
$anonymous_data = bbp_filter_anonymous_post_data(array(), true);
}
}
// Nonce check
if (!bbp_verify_nonce_request('bbp-edit-topic_' . $topic_id)) {
bbp_add_error('bbp_edit_topic_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
return;
}
// Remove kses filters from title and content for capable users and if the nonce is verified
if (current_user_can('unfiltered_html') && !empty($_POST['_bbp_unfiltered_html_topic']) && wp_create_nonce('bbp-unfiltered-html-topic_' . $topic_id) === $_POST['_bbp_unfiltered_html_topic']) {
remove_filter('bbp_edit_topic_pre_title', 'wp_filter_kses');
remove_filter('bbp_edit_topic_pre_content', 'bbp_encode_bad', 10);
remove_filter('bbp_edit_topic_pre_content', 'bbp_filter_kses', 30);
}
/** Topic Forum ***********************************************************/
// Forum id was not passed
if (empty($_POST['bbp_forum_id'])) {
bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum ID is missing.', 'bbpress'));
// Forum id was passed
} elseif (is_numeric($_POST['bbp_forum_id'])) {
$forum_id = (int) $_POST['bbp_forum_id'];
}
// Current forum this topic is in
$current_forum_id = bbp_get_topic_forum_id($topic_id);
// Forum exists
if (!empty($forum_id) && $forum_id !== $current_forum_id) {
// Forum is a category
if (bbp_is_forum_category($forum_id)) {
bbp_add_error('bbp_edit_topic_forum_category', __('<strong>ERROR</strong>: This forum is a category. No topics can be created in it.', 'bbpress'));
// Forum is not a category
} else {
// Forum is closed and user cannot access
if (bbp_is_forum_closed($forum_id) && !current_user_can('edit_forum', $forum_id)) {
bbp_add_error('bbp_edit_topic_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new topics.', 'bbpress'));
}
// Forum is private and user cannot access
if (bbp_is_forum_private($forum_id)) {
if (!current_user_can('read_private_forums')) {
bbp_add_error('bbp_edit_topic_forum_private', __('<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress'));
}
// Forum is hidden and user cannot access
} elseif (bbp_is_forum_hidden($forum_id)) {
if (!current_user_can('read_hidden_forums')) {
bbp_add_error('bbp_edit_topic_forum_hidden', __('<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress'));
}
}
}
}
/** Topic Title ***********************************************************/
if (!empty($_POST['bbp_topic_title'])) {
$topic_title = esc_attr(strip_tags($_POST['bbp_topic_title']));
}
// Filter and sanitize
$topic_title = apply_filters('bbp_edit_topic_pre_title', $topic_title, $topic_id);
// No topic title
if (empty($topic_title)) {
bbp_add_error('bbp_edit_topic_title', __('<strong>ERROR</strong>: Your topic needs a title.', 'bbpress'));
}
/** Topic Content *********************************************************/
if (!empty($_POST['bbp_topic_content'])) {
$topic_content = $_POST['bbp_topic_content'];
}
// Filter and sanitize
$topic_content = apply_filters('bbp_edit_topic_pre_content', $topic_content, $topic_id);
// No topic content
示例5: bbp_save_forum_extras
/**
* Handle the saving of core forum metadata (Status, Visibility, and Type)
*
* @since bbPress (r3678)
* @param int $forum_id
* @uses bbp_is_forum_closed() To check if forum is closed
* @uses bbp_close_forum() To close forum
* @uses bbp_open_forum() To open forum
* @uses bbp_is_forum_category() To check if forum is a category
* @uses bbp_categorize_forum() To turn forum into a category
* @uses bbp_normalize_forum() To turn category into forum
* @uses bbp_get_public_status_id() To get the public status ID
* @uses bbp_get_private_status_id() To get the private status ID
* @uses bbp_get_hidden_status_id() To get the hidden status ID
* @uses bbp_get_forum_visibility() To get the forums visibility
* @uses bbp_hide_forum() To hide a forum
* @uses bbp_privatize_forum() To make a forum private
* @uses bbp_publicize_forum() To make a forum public
* @return If forum ID is empty
*/
function bbp_save_forum_extras($forum_id = 0)
{
// Validate the forum ID
$forum_id = bbp_get_forum_id($forum_id);
// Bail if forum ID is empty
if (empty($forum_id) || !bbp_is_forum($forum_id)) {
return;
}
/** Forum Status ******************************************************/
if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) {
if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) {
bbp_close_forum($forum_id);
} elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) {
bbp_open_forum($forum_id);
}
}
/** Forum Type ********************************************************/
if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) {
if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
bbp_categorize_forum($forum_id);
} elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) {
bbp_normalize_forum($forum_id);
}
}
/** Forum Visibility **************************************************/
if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array(bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id()))) {
// Get forums current visibility
$visibility = bbp_get_forum_visibility($forum_id);
// What is the new forum visibility setting?
switch ($_POST['bbp_forum_visibility']) {
// Hidden
case bbp_get_hidden_status_id():
bbp_hide_forum($forum_id, $visibility);
break;
// Private
// Private
case bbp_get_private_status_id():
bbp_privatize_forum($forum_id, $visibility);
break;
// Publish (default)
// Publish (default)
case bbp_get_public_status_id():
default:
bbp_publicize_forum($forum_id, $visibility);
break;
}
}
}
示例6: bbp_edit_reply_handler
/**
* Handles the front end edit reply submission
*
* @param string $action The requested action to compare this function to
* @uses bbp_add_error() To add an error message
* @uses bbp_get_reply() To get the reply
* @uses bbp_verify_nonce_request() To verify the nonce and check the request
* @uses bbp_is_reply_anonymous() To check if the reply was by an anonymous user
* @uses current_user_can() To check if the current user can edit that reply
* @uses bbp_filter_anonymous_post_data() To filter anonymous data
* @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
* @uses remove_filter() To remove kses filters if needed
* @uses esc_attr() For sanitization
* @uses apply_filters() Calls 'bbp_edit_reply_pre_title' with the title and
* reply id
* @uses apply_filters() Calls 'bbp_edit_reply_pre_content' with the content
* reply id
* @uses wp_set_post_terms() To set the topic tags
* @uses bbp_has_errors() To get the {@link WP_Error} errors
* @uses wp_save_post_revision() To save a reply revision
* @uses bbp_update_reply_revision_log() To update the reply revision log
* @uses wp_update_post() To update the reply
* @uses bbp_get_reply_topic_id() To get the reply topic id
* @uses bbp_get_topic_forum_id() To get the topic forum id
* @uses bbp_get_reply_to() To get the reply to id
* @uses do_action() Calls 'bbp_edit_reply' with the reply id, topic id, forum
* id, anonymous data, reply author, bool true (for edit),
* and the reply to id
* @uses bbp_get_reply_url() To get the paginated url to the reply
* @uses wp_safe_redirect() To redirect to the reply url
* @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error
* message
*/
function bbp_edit_reply_handler($action = '')
{
// Bail if action is not bbp-edit-reply
if ('bbp-edit-reply' !== $action) {
return;
}
// Define local variable(s)
$revisions_removed = false;
$reply = $reply_id = $reply_author = $topic_id = $forum_id = $anonymous_data = 0;
$reply_title = $reply_content = $reply_edit_reason = $terms = '';
/** Reply *****************************************************************/
// Reply id was not passed
if (empty($_POST['bbp_reply_id'])) {
bbp_add_error('bbp_edit_reply_id', __('<strong>ERROR</strong>: Reply ID not found.', 'bbpress'));
return;
// Reply id was passed
} elseif (is_numeric($_POST['bbp_reply_id'])) {
$reply_id = (int) $_POST['bbp_reply_id'];
$reply = bbp_get_reply($reply_id);
}
// Nonce check
if (!bbp_verify_nonce_request('bbp-edit-reply_' . $reply_id)) {
bbp_add_error('bbp_edit_reply_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
return;
}
// Reply does not exist
if (empty($reply)) {
bbp_add_error('bbp_edit_reply_not_found', __('<strong>ERROR</strong>: The reply you want to edit was not found.', 'bbpress'));
return;
// Reply exists
} else {
// Check users ability to create new reply
if (!bbp_is_reply_anonymous($reply_id)) {
// User cannot edit this reply
if (!current_user_can('edit_reply', $reply_id)) {
bbp_add_error('bbp_edit_reply_permissions', __('<strong>ERROR</strong>: You do not have permission to edit that reply.', 'bbpress'));
return;
}
// Set reply author
$reply_author = bbp_get_reply_author_id($reply_id);
// It is an anonymous post
} else {
// Filter anonymous data
$anonymous_data = bbp_filter_anonymous_post_data();
}
}
// Remove kses filters from title and content for capable users and if the nonce is verified
if (current_user_can('unfiltered_html') && !empty($_POST['_bbp_unfiltered_html_reply']) && wp_create_nonce('bbp-unfiltered-html-reply_' . $reply_id) === $_POST['_bbp_unfiltered_html_reply']) {
remove_filter('bbp_edit_reply_pre_title', 'wp_filter_kses');
remove_filter('bbp_edit_reply_pre_content', 'bbp_encode_bad', 10);
remove_filter('bbp_edit_reply_pre_content', 'bbp_filter_kses', 30);
}
/** Reply Topic ***********************************************************/
$topic_id = bbp_get_reply_topic_id($reply_id);
/** Topic Forum ***********************************************************/
$forum_id = bbp_get_topic_forum_id($topic_id);
// Forum exists
if (!empty($forum_id) && $forum_id !== bbp_get_reply_forum_id($reply_id)) {
// Forum is a category
if (bbp_is_forum_category($forum_id)) {
bbp_add_error('bbp_edit_reply_forum_category', __('<strong>ERROR</strong>: This forum is a category. No replies can be created in this forum.', 'bbpress'));
// Forum is not a category
} else {
// Forum is closed and user cannot access
if (bbp_is_forum_closed($forum_id) && !current_user_can('edit_forum', $forum_id)) {
bbp_add_error('bbp_edit_reply_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new replies.', 'bbpress'));
}
//.........这里部分代码省略.........
示例7: bbp_is_forum_closed
/**
* Is the forum closed?
*
* @since bbPress (r2746)
*
* @param int $forum_id Optional. Forum id
* @param bool $check_ancestors Check if the ancestors are closed (only
* if they're a category)
* @uses bbp_get_forum_status() To get the forum status
* @uses bbp_get_forum_ancestors() To get the forum ancestors
* @uses bbp_is_forum_category() To check if the forum is a category
* @uses bbp_is_forum_closed() To check if the forum is closed
* @return bool True if closed, false if not
*/
function bbp_is_forum_closed($forum_id = 0, $check_ancestors = true)
{
$forum_id = bbp_get_forum_id($forum_id);
$retval = bbp_get_closed_status_id() == bbp_get_forum_status($forum_id);
if (!empty($check_ancestors)) {
$ancestors = bbp_get_forum_ancestors($forum_id);
foreach ((array) $ancestors as $ancestor) {
if (bbp_is_forum_category($ancestor, false) && bbp_is_forum_closed($ancestor, false)) {
$retval = true;
}
}
}
return (bool) apply_filters('bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors);
}
示例8: bbp_user_can_comment
function bbp_user_can_comment()
{
return bbpresskr()->forum_option('use_comments') && bbp_current_user_can_access_create_reply_form() && !bbp_is_topic_closed() && !bbp_is_forum_closed();
}
示例9: bbp_is_forum_open
/**
* Is the forum open?
*
* @since 2.0.0 bbPress (r2746)
*
* @param int $forum_id Optional. Forum id
* @param bool $check_ancestors Check if the ancestors are open (only
* if they're a category)
* @uses bbp_is_forum_closed() To check if the forum is closed
* @return bool Whether the forum is open or not
*/
function bbp_is_forum_open($forum_id = 0, $check_ancestors = true)
{
return !bbp_is_forum_closed($forum_id, $check_ancestors);
}
示例10: start_el
/**
* @see Walker::start_el()
*
* @since bbPress (r2746)
*
* @param string $output Passed by reference. Used to append additional
* content.
* @param object $_post Post data object.
* @param int $depth Depth of post in reference to parent posts. Used
* for padding.
* @param array $args Uses 'selected' argument for selected post to set
* selected HTML attribute for option element.
* @param int $current_object_id
* @uses bbp_is_forum_category() To check if the forum is a category
* @uses current_user_can() To check if the current user can post in
* closed forums
* @uses bbp_is_forum_closed() To check if the forum is closed
* @uses apply_filters() Calls 'bbp_walker_dropdown_post_title' with the
* title, output, post, depth and args
*/
public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
{
$pad = str_repeat(' ', (int) $depth * 3);
$output .= '<option class="level-' . (int) $depth . '"';
// Disable the <option> if:
// - we're told to do so
// - the post type is a forum
// - the forum is a category
// - forum is closed
if (true === $args['disable_categories'] && bbp_get_forum_post_type() === $object->post_type && (bbp_is_forum_category($object->ID) || !current_user_can('edit_forum', $object->ID) && bbp_is_forum_closed($object->ID))) {
$output .= ' disabled="disabled" value=""';
} else {
$output .= ' value="' . (int) $object->ID . '"' . selected($args['selected'], $object->ID, false);
}
$output .= '>';
$title = apply_filters('bbp_walker_dropdown_post_title', $object->post_title, $output, $object, $depth, $args);
$output .= $pad . esc_html($title);
$output .= "</option>\n";
}
示例11: start_el
/**
* @see Walker::start_el()
*
* @since bbPress (r2746)
*
* @param string $output Passed by reference. Used to append additional
* content.
* @param object $_post Post data object.
* @param int $depth Depth of post in reference to parent posts. Used
* for padding.
* @param array $args Uses 'selected' argument for selected post to set
* selected HTML attribute for option element.
* @uses bbp_is_forum_category() To check if the forum is a category
* @uses current_user_can() To check if the current user can post in
* closed forums
* @uses bbp_is_forum_closed() To check if the forum is closed
* @uses apply_filters() Calls 'bbp_walker_dropdown_post_title' with the
* title, output, post, depth and args
*/
public function start_el(&$output, $_post, $depth, $args)
{
$pad = str_repeat(' ', $depth * 3);
$output .= "\t<option class=\"level-{$depth}\"";
// Disable the <option> if we're told to do so, the post type is bbp_forum and the forum is a category or is closed
if (true == $args['disable_categories'] && $_post->post_type == bbp_get_forum_post_type() && (bbp_is_forum_category($_post->ID) || !current_user_can('edit_forum', $_post->ID) && bbp_is_forum_closed($_post->ID))) {
$output .= ' disabled="disabled" value=""';
} else {
$output .= ' value="' . $_post->ID . '"' . selected($args['selected'], $_post->ID, false);
}
$output .= '>';
$title = esc_html($_post->post_title);
$title = apply_filters('bbp_walker_dropdown_post_title', $_post->post_title, $output, $_post, $depth, $args);
$output .= $pad . $title;
$output .= "</option>\n";
}
示例12: bbp_save_forum_extras
/**
* Handle the saving of core forum metadata (Status, Visibility, and Type)
*
* @since 2.1.0 bbPress (r3678)
*
* @param int $forum_id
* @uses bbp_is_forum_closed() To check if forum is closed
* @uses bbp_close_forum() To close forum
* @uses bbp_open_forum() To open forum
* @uses bbp_is_forum_category() To check if forum is a category
* @uses bbp_categorize_forum() To turn forum into a category
* @uses bbp_normalize_forum() To turn category into forum
* @uses bbp_get_public_status_id() To get the public status ID
* @uses bbp_get_private_status_id() To get the private status ID
* @uses bbp_get_hidden_status_id() To get the hidden status ID
* @uses bbp_get_forum_visibility() To get the forums visibility
* @uses bbp_hide_forum() To hide a forum
* @uses bbp_privatize_forum() To make a forum private
* @uses bbp_publicize_forum() To make a forum public
* @return If forum ID is empty
*/
function bbp_save_forum_extras($forum_id = 0)
{
// Validate the forum ID
$forum_id = bbp_get_forum_id($forum_id);
// Bail if forum ID is empty
if (empty($forum_id) || !bbp_is_forum($forum_id)) {
return;
}
/** Forum Status **********************************************************/
if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) {
if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) {
bbp_close_forum($forum_id);
} elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_open($forum_id, false)) {
bbp_open_forum($forum_id);
} elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) {
bbp_open_forum($forum_id);
}
}
/** Forum Type ************************************************************/
if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) {
if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
bbp_categorize_forum($forum_id);
} elseif ('forum' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
bbp_normalize_forum($forum_id);
} elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) {
bbp_normalize_forum($forum_id);
}
}
/** Forum Visibility ******************************************************/
if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array_keys(bbp_get_forum_visibilities()))) {
// Get forums current visibility
$old_visibility = bbp_get_forum_visibility($forum_id);
// Sanitize the new visibility
$new_visibility = sanitize_key($_POST['bbp_forum_visibility']);
// What is the new forum visibility setting?
switch ($new_visibility) {
// Hidden
case bbp_get_hidden_status_id():
bbp_hide_forum($forum_id, $old_visibility);
break;
// Private
// Private
case bbp_get_private_status_id():
bbp_privatize_forum($forum_id, $old_visibility);
break;
// Publish (default)
// Publish (default)
case bbp_get_public_status_id():
default:
bbp_publicize_forum($forum_id, $old_visibility);
break;
}
/**
* Allow custom forum visibility save actions
*
* @since 2.6.0 bbPress (r5855)
*
* @param int $forum_id The forum ID
* @param string $old_visibility The current forum visibility
* @param string $new_visibility The new forum visibility
*/
do_action('bbp_update_forum_visibility', $forum_id, $old_visibility, $new_visibility);
}
/** Forum Moderators ******************************************************/
// Either replace terms
if (bbp_allow_forum_mods()) {
if (current_user_can('assign_moderators') && !empty($_POST['bbp_moderators'])) {
// Escape tag input
$users = sanitize_text_field($_POST['bbp_moderators']);
// Explode by comma
$users = strstr($users, ',') ? explode(',', $users) : (array) $users;
$user_ids = bbp_get_user_ids_from_nicenames($users);
// Update forum moderators
if (!empty($user_ids)) {
// Remove all moderators
bbp_remove_moderator($forum_id, null);
// Add moderators
foreach ($user_ids as $user_id) {
bbp_add_moderator($forum_id, $user_id);
//.........这里部分代码省略.........
示例13: do_action
</div>
<?php do_action( 'bbp_theme_after_topic_form_submit_wrapper' ); ?>
</div>
<?php bbp_topic_form_fields(); ?>
</fieldset>
<?php do_action( 'bbp_theme_after_topic_form' ); ?>
</form>
</div>
<?php elseif ( bbp_is_forum_closed() ) : ?>
<div id="no-topic-<?php bbp_topic_id(); ?>" class="bbp-no-topic">
<div class="bbp-template-notice">
<p><?php printf( __( 'The forum ‘%s’ is closed to new topics and replies.', 'bbpress' ), bbp_get_forum_title() ); ?></p>
</div>
</div>
<?php else : ?>
<div id="no-topic-<?php bbp_topic_id(); ?>" class="bbp-no-topic">
<div class="bbp-template-notice">
<p><?php is_user_logged_in() ? _e( 'You cannot create new topics.', 'bbpress' ) : _e( 'You must be logged in to create new topics.', 'bbpress' ); ?></p>
</div>
<?php wp_login_form(); ?>
</div>
示例14: test_bbp_insert_forum
/**
* @group canonical
* @covers ::bbp_insert_forum
*/
public function test_bbp_insert_forum()
{
$c = $this->factory->forum->create(array('post_title' => 'Category 1', 'post_content' => 'Content of Category 1', 'forum_meta' => array('forum_type' => 'category', 'status' => 'open')));
$f = $this->factory->forum->create(array('post_title' => 'Forum 1', 'post_content' => 'Content of Forum 1', 'post_parent' => $c, 'forum_meta' => array('forum_id' => $c, 'forum_type' => 'forum', 'status' => 'open')));
$now = time();
$post_date = date('Y-m-d H:i:s', $now - 60 * 60 * 100);
$t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date, 'topic_meta' => array('forum_id' => $f)));
$r = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
// Get the category.
$category = bbp_get_forum($c);
// Get the forum.
$forum = bbp_get_forum($f);
// Category post.
$this->assertSame('Category 1', bbp_get_forum_title($c));
$this->assertSame('Content of Category 1', bbp_get_forum_content($c));
$this->assertSame('open', bbp_get_forum_status($c));
$this->assertSame('category', bbp_get_forum_type($c));
$this->assertTrue(bbp_is_forum($c));
$this->assertTrue(bbp_is_forum_category($c));
$this->assertTrue(bbp_is_forum_open($c));
$this->assertTrue(bbp_is_forum_public($c));
$this->assertFalse(bbp_is_forum_closed($c));
$this->assertFalse(bbp_is_forum_hidden($c));
$this->assertFalse(bbp_is_forum_private($c));
$this->assertSame(0, bbp_get_forum_parent_id($c));
$this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?forum=' . $category->post_name, $category->guid);
// Forum post.
$this->assertSame('Forum 1', bbp_get_forum_title($f));
$this->assertSame('Content of Forum 1', bbp_get_forum_content($f));
$this->assertSame('open', bbp_get_forum_status($f));
$this->assertSame('forum', bbp_get_forum_type($f));
$this->assertTrue(bbp_is_forum($f));
$this->assertTrue(bbp_is_forum_open($f));
$this->assertTrue(bbp_is_forum_public($f));
$this->assertFalse(bbp_is_forum_closed($f));
$this->assertFalse(bbp_is_forum_hidden($f));
$this->assertFalse(bbp_is_forum_private($f));
$this->assertSame($c, bbp_get_forum_parent_id($f));
$this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?forum=' . $category->post_name . '/' . $forum->post_name, $forum->guid);
// Category meta.
$this->assertSame(1, bbp_get_forum_subforum_count($c, true));
$this->assertSame(0, bbp_get_forum_topic_count($c, false, true));
$this->assertSame(1, bbp_get_forum_topic_count($c, true, true));
$this->assertSame(0, bbp_get_forum_topic_count_hidden($c, true));
$this->assertSame(0, bbp_get_forum_reply_count($c, false, true));
$this->assertSame(1, bbp_get_forum_reply_count($c, true, true));
$this->assertSame(0, bbp_get_forum_post_count($c, false, true));
$this->assertSame(2, bbp_get_forum_post_count($c, true, true));
$this->assertSame($t, bbp_get_forum_last_topic_id($c));
$this->assertSame($r, bbp_get_forum_last_reply_id($c));
$this->assertSame($r, bbp_get_forum_last_active_id($c));
$this->assertSame('4 days, 4 hours ago', bbp_get_forum_last_active_time($c));
// Forum meta.
$this->assertSame(0, bbp_get_forum_subforum_count($f, true));
$this->assertSame(1, bbp_get_forum_topic_count($f, false, true));
$this->assertSame(1, bbp_get_forum_topic_count($f, true, true));
$this->assertSame(0, bbp_get_forum_topic_count_hidden($f, true));
$this->assertSame(1, bbp_get_forum_reply_count($f, false, true));
$this->assertSame(1, bbp_get_forum_reply_count($f, true, true));
$this->assertSame(2, bbp_get_forum_post_count($f, false, true));
$this->assertSame(2, bbp_get_forum_post_count($f, true, true));
$this->assertSame($t, bbp_get_forum_last_topic_id($f));
$this->assertSame($r, bbp_get_forum_last_reply_id($f));
$this->assertSame($r, bbp_get_forum_last_active_id($f));
$this->assertSame('4 days, 4 hours ago', bbp_get_forum_last_active_time($f));
}
示例15: post_new_topic
/**
* Post new topic by email handler.
*
* For bbPress, the logic in this method is the same as {@link bbp_new_topic_handler()}.
* It's duplicated because bbPress doesn't utilize hooks for verifying topics.
*
* @todo No fancy support for topic tags, subscriptions yet. Will probably need shortcodes.
*
* @param array $data {
* An array of arguments.
*
* @type array $headers Email headers.
* @type string $content The email body content.
* @type string $subject The email subject line.
* @type int $user_id The user ID who sent the email.
* @type bool $is_html Whether the email content is HTML or not.
* @type int $i The email message number.
* }
* @param array $params Parsed paramaters from the email address querystring.
* See {@link BP_Reply_By_Email_Parser::get_parameters()}.
* @return array|object Array of the parsed item on success. WP_Error object
* on failure.
*/
private function post_new_topic($data, $params)
{
//private function post_new_topic( $connection, $i, $headers, $params, $body, $topic_author ) {
/** SETUP DATA ***************************************************/
$i = $data['i'];
$topic_author = $data['user_id'];
$forum_id = $params[$this->forum_id_param];
/* current email is a bbPress new topic, let's proceed! */
// let RBE know that we're in the process of rendering a bbP new topic
// BuddyPress group new topic
if (!empty($params[$this->item_id_param])) {
bp_rbe_log('Message #' . $i . ': this is a bbPress group forum new topic');
// bbPress
} else {
bp_rbe_log('Message #' . $i . ': this is a bbPress new topic');
}
// other variables
$anonymous_data = 0;
/** GROUP PERMISSIONS ********************************************/
// posting from a BP group
if (!empty($params[$this->item_id_param])) {
global $bp;
// set group ID and cache it in global for later use
// $bp->rbe->temp->group_id gets passed to the set_group_id() method later on
$group_id = $bp->rbe->temp->group_id = $params[$this->item_id_param];
// get all group member data for the user in one swoop!
$group_member_data = bp_rbe_get_group_member_info($topic_author, $group_id);
// user is not a member of the group anymore
if (empty($group_member_data)) {
//do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'user_not_group_member' );
return new WP_Error('user_not_group_member', '', $data);
}
// user is banned from group
if ((int) $group_member_data->is_banned == 1) {
//do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'user_banned_from_group' );
return new WP_Error('user_banned_from_group', '', $data);
}
// override groups_get_current_group() with our cached group ID
add_filter('groups_get_current_group', array($this, 'set_group_id'));
// temporarily add some GES filters here
add_filter('bp_ass_activity_notification_subject', 'wp_specialchars_decode');
add_filter('bp_ass_activity_notification_content', 'wp_specialchars_decode');
}
/** TOPIC / FORUM PERMISSIONS ************************************/
// Allow member to pass default cap checks.
// The reason why we keep the user_can() checks below is b/c bbPress
// plugins may disable cap access for a specific user if they have hooked into
// the 'bbp_map_meta_caps' filter.
add_filter('bbp_map_meta_caps', array($this, 'map_forum_meta_caps'), 5, 4);
// User cannot create topics
if (!user_can($topic_author, 'publish_topics')) {
//do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_permissions' );
return new WP_Error('bbp_topic_permissions', '', $data);
}
// Forum is a category
if (bbp_is_forum_category($forum_id)) {
//do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_edit_topic_forum_category' );
//bbp_add_error( 'bbp_edit_topic_forum_category', __( '<strong>ERROR</strong>: This forum is a category. No topics can be created in this forum.', 'bbpress' ) );
return new WP_Error('bbp_edit_topic_forum_category', '', $data);
// Forum is not a category
} else {
// Forum is closed and user cannot access
if (bbp_is_forum_closed($forum_id) && !user_can($topic_author, 'edit_forum')) {
//do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_edit_topic_forum_closed' );
//bbp_add_error( 'bbp_edit_topic_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new topics.', 'bbpress' ) );
return new WP_Error('bbp_edit_topic_forum_closed', '', $data);
}
// Forum is private and user cannot access
if (bbp_is_forum_private($forum_id)) {
if (!user_can($topic_author, 'read_private_forums')) {
//do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_edit_topic_forum_private' );
//bbp_add_error( 'bbp_edit_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
return new WP_Error('bbp_edit_topic_forum_private', '', $data);
}
}
// Forum is hidden and user cannot access
if (bbp_is_forum_hidden($forum_id)) {
//.........这里部分代码省略.........