本文整理汇总了PHP中bbp_get_trash_status_id函数的典型用法代码示例。如果您正苦于以下问题:PHP bbp_get_trash_status_id函数的具体用法?PHP bbp_get_trash_status_id怎么用?PHP bbp_get_trash_status_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bbp_get_trash_status_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bbp_admin_repair_topic_hidden_reply_count
/**
* Recount topic hidden replies (spammed/trashed)
*
* @since bbPress (r2747)
*
* @uses wpdb::query() To run our recount sql queries
* @uses is_wp_error() To check if the executed query returned {@link WP_Error}
* @return array An array of the status code and the message
*/
function bbp_admin_repair_topic_hidden_reply_count()
{
global $wpdb;
$statement = __('Counting the number of spammed and trashed replies in each topic… %s', 'bbpress');
$result = __('Failed!', 'bbpress');
$sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_reply_count_hidden';";
if (is_wp_error($wpdb->query($sql_delete))) {
return array(1, sprintf($statement, $result));
}
$sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` IN ( '" . implode("','", array(bbp_get_trash_status_id(), bbp_get_spam_status_id())) . "') GROUP BY `post_parent`);";
if (is_wp_error($wpdb->query($sql))) {
return array(2, sprintf($statement, $result));
}
return array(0, sprintf($statement, __('Complete!', 'bbpress')));
}
示例2: bbp_has_search_results
/**
* The main search loop. WordPress does the heavy lifting.
*
* @since bbPress (r4579)
*
* @param mixed $args All the arguments supported by {@link WP_Query}
* @uses bbp_get_view_all() Are we showing all results?
* @uses bbp_get_public_status_id() To get the public status id
* @uses bbp_get_closed_status_id() To get the closed status id
* @uses bbp_get_spam_status_id() To get the spam status id
* @uses bbp_get_trash_status_id() To get the trash status id
* @uses bbp_get_forum_post_type() To get the forum post type
* @uses bbp_get_topic_post_type() To get the topic post type
* @uses bbp_get_reply_post_type() To get the reply post type
* @uses bbp_get_replies_per_page() To get the replies per page option
* @uses bbp_get_paged() To get the current page value
* @uses bbp_get_search_terms() To get the search terms
* @uses WP_Query To make query and get the search results
* @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
* @uses bbp_get_search_url() To get the forum search url
* @uses paginate_links() To paginate search results
* @uses apply_filters() Calls 'bbp_has_search_results' with
* bbPress::search_query::have_posts()
* and bbPress::reply_query
* @return object Multidimensional array of search information
*/
function bbp_has_search_results($args = '')
{
global $wp_rewrite;
/** Defaults **************************************************************/
$default_post_type = array(bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type());
// Default query args
$default = array('post_type' => $default_post_type, 'posts_per_page' => bbp_get_replies_per_page(), 'paged' => bbp_get_paged(), 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true, 's' => bbp_get_search_terms());
// What are the default allowed statuses (based on user caps)
if (bbp_get_view_all()) {
// Default view=all statuses
$post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id());
// Add support for private status
if (current_user_can('read_private_topics')) {
$post_statuses[] = bbp_get_private_status_id();
}
// Join post statuses together
$default['post_status'] = implode(',', $post_statuses);
// Lean on the 'perm' query var value of 'readable' to provide statuses
} else {
$default['perm'] = 'readable';
}
/** Setup *****************************************************************/
// Parse arguments against default values
$r = bbp_parse_args($args, $default, 'has_search_results');
// Get bbPress
$bbp = bbpress();
// Call the query
if (!empty($r['s'])) {
$bbp->search_query = new WP_Query($r);
}
// Add pagination values to query object
$bbp->search_query->posts_per_page = $r['posts_per_page'];
$bbp->search_query->paged = $r['paged'];
// Never home, regardless of what parse_query says
$bbp->search_query->is_home = false;
// Only add pagination is query returned results
if (!empty($bbp->search_query->found_posts) && !empty($bbp->search_query->posts_per_page)) {
// Array of arguments to add after pagination links
$add_args = array();
// If pretty permalinks are enabled, make our pagination pretty
if ($wp_rewrite->using_permalinks()) {
// Shortcode territory
if (is_page() || is_single()) {
$base = trailingslashit(get_permalink());
// Default search location
} else {
$base = trailingslashit(bbp_get_search_results_url());
}
// Add pagination base
$base = $base . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/');
// Unpretty permalinks
} else {
$base = add_query_arg('paged', '%#%');
}
// Add args
if (bbp_get_view_all()) {
$add_args['view'] = 'all';
}
// Add pagination to query object
$bbp->search_query->pagination_links = paginate_links(apply_filters('bbp_search_results_pagination', array('base' => $base, 'format' => '', 'total' => ceil((int) $bbp->search_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->search_query->paged, 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'mid_size' => 1, 'add_args' => $add_args)));
// Remove first page from pagination
if ($wp_rewrite->using_permalinks()) {
$bbp->search_query->pagination_links = str_replace($wp_rewrite->pagination_base . '/1/', '', $bbp->search_query->pagination_links);
} else {
$bbp->search_query->pagination_links = str_replace('&paged=1', '', $bbp->search_query->pagination_links);
}
}
// Return object
return apply_filters('bbp_has_search_results', $bbp->search_query->have_posts(), $bbp->search_query);
}
示例3: bbp_get_all_child_ids
/**
* Query the DB and get a the child id's of all children
*
* @since 2.0.0 bbPress (r3325)
*
* @param int $parent_id Parent id
* @param string $post_type Post type. Defaults to 'post'
* @uses wp_cache_get() To check if there is a cache of the children
* @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_pending_status_id() To get the pending status id
* @uses bbp_get_closed_status_id() To get the closed status id
* @uses bbp_get_trash_status_id() To get the trash status id
* @uses bbp_get_spam_status_id() To get the spam status id
* @uses bbp_get_forum_post_type() To get the forum post type
* @uses bbp_get_topic_post_type() To get the topic post type
* @uses bbp_get_reply_post_type() To get the reply post type
* @uses wpdb::prepare() To prepare the query
* @uses wpdb::get_col() To get the result of the query in an array
* @uses wp_cache_set() To set the cache for future use
* @uses apply_filters() Calls 'bbp_get_all_child_ids' with the child ids,
* parent id and post type
* @return array The array of children
*/
function bbp_get_all_child_ids($parent_id = 0, $post_type = 'post')
{
// Bail if nothing passed
if (empty($parent_id)) {
return false;
}
// The ID of the cached query
$cache_id = 'bbp_parent_all_' . $parent_id . '_type_' . $post_type . '_child_ids';
// Check for cache and set if needed
$child_ids = wp_cache_get($cache_id, 'bbpress_posts');
if (false === $child_ids) {
$post_status = array(bbp_get_public_status_id());
// Extra post statuses based on post type
switch ($post_type) {
// Forum
case bbp_get_forum_post_type():
$post_status[] = bbp_get_private_status_id();
$post_status[] = bbp_get_hidden_status_id();
break;
// Topic
// Topic
case bbp_get_topic_post_type():
$post_status[] = bbp_get_pending_status_id();
$post_status[] = bbp_get_closed_status_id();
$post_status[] = bbp_get_trash_status_id();
$post_status[] = bbp_get_spam_status_id();
break;
// Reply
// Reply
case bbp_get_reply_post_type():
$post_status[] = bbp_get_pending_status_id();
$post_status[] = bbp_get_trash_status_id();
$post_status[] = bbp_get_spam_status_id();
break;
}
// Join post statuses together
$post_status = "'" . implode("', '", $post_status) . "'";
$bbp_db = bbp_db();
$query = $bbp_db->prepare("SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type);
$child_ids = (array) $bbp_db->get_col($query);
wp_cache_set($cache_id, $child_ids, 'bbpress_posts');
} else {
$child_ids = (array) $child_ids;
}
// Filter and return
return (array) apply_filters('bbp_get_all_child_ids', $child_ids, $parent_id, $post_type);
}
示例4: bbp_new_reply_handler
//.........这里部分代码省略.........
// Default
} else {
$reply_status = bbp_get_public_status_id();
}
/** Reply To **************************************************************/
// Handle Reply To of the reply; $_REQUEST for non-JS submissions
if (isset($_REQUEST['bbp_reply_to'])) {
$reply_to = bbp_validate_reply_to($_REQUEST['bbp_reply_to']);
}
/** Topic Closed **********************************************************/
// If topic is closed, moderators can still reply
if (bbp_is_topic_closed($topic_id) && !current_user_can('moderate')) {
bbp_add_error('bbp_reply_topic_closed', __('<strong>ERROR</strong>: Topic is closed.', 'bbpress'));
}
/** Topic Tags ************************************************************/
// Either replace terms
if (bbp_allow_topic_tags() && current_user_can('assign_topic_tags') && !empty($_POST['bbp_topic_tags'])) {
$terms = esc_attr(strip_tags($_POST['bbp_topic_tags']));
// ...or remove them.
} elseif (isset($_POST['bbp_topic_tags'])) {
$terms = '';
// Existing terms
} else {
$terms = bbp_get_topic_tag_names($topic_id);
}
/** Additional Actions (Before Save) **************************************/
do_action('bbp_new_reply_pre_extras', $topic_id, $forum_id);
// Bail if errors
if (bbp_has_errors()) {
return;
}
/** No Errors *************************************************************/
// Add the content of the form to $reply_data as an array
// Just in time manipulation of reply data before being created
$reply_data = apply_filters('bbp_new_reply_pre_insert', array('post_author' => $reply_author, 'post_title' => $reply_title, 'post_content' => $reply_content, 'post_status' => $reply_status, 'post_parent' => $topic_id, 'post_type' => bbp_get_reply_post_type(), 'comment_status' => 'closed', 'menu_order' => bbp_get_topic_reply_count($topic_id, false) + 1));
// Insert reply
$reply_id = wp_insert_post($reply_data);
/** No Errors *************************************************************/
// Check for missing reply_id or error
if (!empty($reply_id) && !is_wp_error($reply_id)) {
/** Topic Tags ********************************************************/
// Just in time manipulation of reply terms before being edited
$terms = apply_filters('bbp_new_reply_pre_set_terms', $terms, $topic_id, $reply_id);
// Insert terms
$terms = wp_set_post_terms($topic_id, $terms, bbp_get_topic_tag_tax_id(), false);
// Term error
if (is_wp_error($terms)) {
bbp_add_error('bbp_reply_tags', __('<strong>ERROR</strong>: There was a problem adding the tags to the topic.', 'bbpress'));
}
/** Trash Check *******************************************************/
// If this reply starts as trash, add it to pre_trashed_replies
// for the topic, so it is properly restored.
if (bbp_is_topic_trash($topic_id) || $reply_data['post_status'] === bbp_get_trash_status_id()) {
// Trash the reply
wp_trash_post($reply_id);
// Only add to pre-trashed array if topic is trashed
if (bbp_is_topic_trash($topic_id)) {
// Get pre_trashed_replies for topic
$pre_trashed_replies = get_post_meta($topic_id, '_bbp_pre_trashed_replies', true);
// Add this reply to the end of the existing replies
$pre_trashed_replies[] = $reply_id;
// Update the pre_trashed_reply post meta
update_post_meta($topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies);
}
/** Spam Check ********************************************************/
// If reply or topic are spam, officially spam this reply
} elseif (bbp_is_topic_spam($topic_id) || $reply_data['post_status'] === bbp_get_spam_status_id()) {
add_post_meta($reply_id, '_bbp_spam_meta_status', bbp_get_public_status_id());
// Only add to pre-spammed array if topic is spam
if (bbp_is_topic_spam($topic_id)) {
// Get pre_spammed_replies for topic
$pre_spammed_replies = get_post_meta($topic_id, '_bbp_pre_spammed_replies', true);
// Add this reply to the end of the existing replies
$pre_spammed_replies[] = $reply_id;
// Update the pre_spammed_replies post meta
update_post_meta($topic_id, '_bbp_pre_spammed_replies', $pre_spammed_replies);
}
}
/** Update counts, etc... *********************************************/
do_action('bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, false, $reply_to);
/** Additional Actions (After Save) ***********************************/
do_action('bbp_new_reply_post_extras', $reply_id);
/** Redirect **********************************************************/
// Redirect to
$redirect_to = bbp_get_redirect_to();
// Get the reply URL
$reply_url = bbp_get_reply_url($reply_id, $redirect_to);
// Allow to be filtered
$reply_url = apply_filters('bbp_new_reply_redirect_to', $reply_url, $redirect_to, $reply_id);
/** Successful Save ***************************************************/
// Redirect back to new reply
wp_safe_redirect($reply_url);
// For good measure
exit;
/** Errors ****************************************************************/
} else {
$append_error = is_wp_error($reply_id) && $reply_id->get_error_message() ? $reply_id->get_error_message() . ' ' : '';
bbp_add_error('bbp_reply_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your reply:' . $append_error . 'Please try again.', 'bbpress'));
}
}
示例5: row_actions
/**
* Reply Row actions
*
* Remove the quick-edit action link under the reply title and add the
* content and spam link
*
* @since 2.0.0 bbPress (r2577)
*
* @param array $actions Actions
* @param array $reply Reply object
* @uses bbp_get_reply_post_type() To get the reply post type
* @uses bbp_reply_content() To output reply content
* @uses bbp_get_reply_url() To get the reply link
* @uses bbp_get_reply_title() To get the reply title
* @uses current_user_can() To check if the current user can edit or
* delete the reply
* @uses bbp_is_reply_spam() To check if the reply is marked as spam
* @uses get_post_type_object() To get the reply post type object
* @uses add_query_arg() To add custom args to the url
* @uses remove_query_arg() To remove custom args from the url
* @uses wp_nonce_url() To nonce the url
* @uses get_delete_post_link() To get the delete post link of the reply
* @return array $actions Actions
*/
public function row_actions($actions, $reply)
{
if ($this->bail()) {
return $actions;
}
unset($actions['inline hide-if-no-js']);
// Reply view links to topic
$actions['view'] = '<a href="' . esc_url(bbp_get_reply_url($reply->ID)) . '" title="' . esc_attr(sprintf(__('View “%s”', 'bbpress'), bbp_get_reply_title($reply->ID))) . '" rel="permalink">' . esc_html__('View', 'bbpress') . '</a>';
// User cannot view replies in trash
if (bbp_get_trash_status_id() === $reply->post_status && !current_user_can('view_trash')) {
unset($actions['view']);
}
// Only show the actions if the user is capable of viewing them
if (current_user_can('moderate', $reply->ID)) {
// Show the 'approve' link on pending posts only and 'unapprove' on published posts only
$approve_uri = wp_nonce_url(add_query_arg(array('reply_id' => $reply->ID, 'action' => 'bbp_toggle_reply_approve'), remove_query_arg(array('bbp_reply_toggle_notice', 'reply_id', 'failed', 'super'))), 'approve-reply_' . $reply->ID);
if (bbp_is_reply_published($reply->ID)) {
$actions['unapproved'] = '<a href="' . esc_url($approve_uri) . '" title="' . esc_attr__('Unapprove this reply', 'bbpress') . '">' . _x('Unapprove', 'Unapprove reply', 'bbpress') . '</a>';
} elseif (!bbp_is_reply_private($reply->ID)) {
$actions['approved'] = '<a href="' . esc_url($approve_uri) . '" title="' . esc_attr__('Approve this reply', 'bbpress') . '">' . _x('Approve', 'Approve reply', 'bbpress') . '</a>';
}
// Show the 'spam' link on published and pending replies and 'not spam' on spammed replies
if (in_array($reply->post_status, array(bbp_get_public_status_id(), bbp_get_pending_status_id(), bbp_get_spam_status_id()))) {
$spam_uri = wp_nonce_url(add_query_arg(array('reply_id' => $reply->ID, 'action' => 'bbp_toggle_reply_spam'), remove_query_arg(array('bbp_reply_toggle_notice', 'reply_id', 'failed', 'super'))), 'spam-reply_' . $reply->ID);
if (bbp_is_reply_spam($reply->ID)) {
$actions['spam'] = '<a href="' . esc_url($spam_uri) . '" title="' . esc_attr__('Mark the reply as not spam', 'bbpress') . '">' . esc_html__('Not spam', 'bbpress') . '</a>';
} else {
$actions['spam'] = '<a href="' . esc_url($spam_uri) . '" title="' . esc_attr__('Mark this reply as spam', 'bbpress') . '">' . esc_html__('Spam', 'bbpress') . '</a>';
}
}
}
// Trash
if (current_user_can('delete_reply', $reply->ID)) {
if (bbp_get_trash_status_id() === $reply->post_status) {
$post_type_object = get_post_type_object(bbp_get_reply_post_type());
$actions['untrash'] = "<a title='" . esc_attr__('Restore this item from the Trash', 'bbpress') . "' href='" . esc_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_reply_post_type()), admin_url('edit.php'))), wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&action=untrash', $reply->ID)), 'untrash-' . $reply->post_type . '_' . $reply->ID))) . "'>" . esc_html__('Restore', 'bbpress') . "</a>";
} elseif (EMPTY_TRASH_DAYS) {
$actions['trash'] = "<a class='submitdelete' title='" . esc_attr__('Move this item to the Trash', 'bbpress') . "' href='" . esc_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_reply_post_type()), admin_url('edit.php'))), get_delete_post_link($reply->ID))) . "'>" . esc_html__('Trash', 'bbpress') . "</a>";
}
if (bbp_get_trash_status_id() === $reply->post_status || !EMPTY_TRASH_DAYS) {
$actions['delete'] = "<a class='submitdelete' title='" . esc_attr__('Delete this item permanently', 'bbpress') . "' href='" . esc_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_reply_post_type()), admin_url('edit.php'))), get_delete_post_link($reply->ID, '', true))) . "'>" . esc_html__('Delete Permanently', 'bbpress') . "</a>";
} elseif (bbp_get_spam_status_id() === $reply->post_status) {
unset($actions['trash']);
}
}
return $actions;
}
示例6: display_forums
/**
* Output the forums for a group in the edit screens
*
* @since bbPress (r3653)
* @uses bp_get_current_group_id()
* @uses bbp_get_group_forum_ids()
* @uses bbp_has_forums()
* @uses bbp_get_template_part()
*/
public function display_forums($offset = 0)
{
// Allow actions immediately before group forum output
do_action('bbp_before_group_forum_display');
// Load up bbPress once
$bbp = bbpress();
// Forum data
$forum_slug = bp_action_variable($offset);
$forum_ids = bbp_get_group_forum_ids(bp_get_current_group_id());
$forum_args = array('post__in' => $forum_ids, 'post_parent' => null);
// Unset global queries
$bbp->forum_query = new stdClass();
$bbp->topic_query = new stdClass();
$bbp->reply_query = new stdClass();
// Unset global ID's
$bbp->current_forum_id = 0;
$bbp->current_topic_id = 0;
$bbp->current_reply_id = 0;
$bbp->current_topic_tag_id = 0;
// Reset the post data
wp_reset_postdata();
// Allow admins special views
$post_status = array(bbp_get_closed_status_id(), bbp_get_public_status_id());
if (is_super_admin() || current_user_can('moderate') || bp_is_item_admin() || bp_is_item_mod()) {
$post_status = array_merge($post_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()));
}
?>
<div id="bbpress-forums">
<?php
// Looking at the group forum root
if (empty($forum_slug) || 'page' == $forum_slug) {
// Query forums and show them if they exist
if (!empty($forum_ids) && bbp_has_forums($forum_args)) {
// Only one forum found
if (1 == $bbp->forum_query->post_count) {
// Remove 'name' check for paginated requests
if ('page' == $forum_slug) {
$forum_args = array('post_type' => bbp_get_forum_post_type());
} else {
$forum_args = array('name' => $forum_slug, 'post_type' => bbp_get_forum_post_type());
}
// Get the forums
$forums = get_posts($forum_args);
bbp_the_forum();
// Forum exists
if (!empty($forums)) {
$forum = $forums[0];
// Suppress subforums for now
add_filter('bbp_get_forum_subforum_count', '__return_false');
// Set up forum data
bbpress()->current_forum_id = $forum->ID;
bbp_set_query_name('bbp_single_forum');
?>
<h3><?php
bbp_forum_title();
?>
</h3>
<?php
bbp_get_template_part('content', 'single-forum');
?>
<?php
// Remove the subforum suppression filter
remove_filter('bbp_get_forum_subforum_count', '__return_false');
?>
<?php
} else {
?>
<?php
bbp_get_template_part('feedback', 'no-topics');
?>
<?php
bbp_get_template_part('form', 'topic');
?>
<?php
}
// More than 1 forum found or group forum admin screen
} elseif (1 < $bbp->forum_query->post_count) {
?>
<h3><?php
_e('Forums', 'bbpress');
?>
//.........这里部分代码省略.........
示例7: bbp_update_topic_reply_count_hidden
/**
* Adjust the total hidden reply count of a topic (hidden includes trashed,
* spammed and pending replies)
*
* @since 2.0.0 bbPress (r2740)
*
* @param int $topic_id Optional. Topic id to update
* @param int $reply_count Optional. Set the reply count manually
* @uses bbp_is_reply() To check if the passed topic id is a reply
* @uses bbp_get_reply_topic_id() To get the reply topic id
* @uses bbp_get_topic_id() To get the topic id
* @uses bbp_get_trash_status_id() To get the trash status id
* @uses bbp_get_spam_status_id() To get the spam status id
* @uses bbp_get_pending_status_id() To get the pending status id
* @uses bbp_get_reply_post_type() To get the reply post type
* @uses wpdb::prepare() To prepare our sql query
* @uses wpdb::get_var() To execute our query and get the var back
* @uses update_post_meta() To update the topic hidden reply count meta
* @uses apply_filters() Calls 'bbp_update_topic_reply_count_hidden' with the
* hidden reply count and topic id
* @return int Topic hidden reply count
*/
function bbp_update_topic_reply_count_hidden($topic_id = 0, $reply_count = 0)
{
// If it's a reply, then get the parent (topic id)
if (bbp_is_reply($topic_id)) {
$topic_id = bbp_get_reply_topic_id($topic_id);
} else {
$topic_id = bbp_get_topic_id($topic_id);
}
// Get replies of topic
if (empty($reply_count)) {
$statuses = array(bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id());
$post_status = "'" . implode("','", $statuses) . "'";
$bbp_db = bbp_db();
$query = $bbp_db->prepare("SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $topic_id, bbp_get_reply_post_type());
$reply_count = $bbp_db->get_var($query);
}
$reply_count = (int) $reply_count;
update_post_meta($topic_id, '_bbp_reply_count_hidden', $reply_count);
return (int) apply_filters('bbp_update_topic_reply_count_hidden', $reply_count, $topic_id);
}
示例8: bbp_update_topic_reply_count_hidden
/**
* Adjust the total hidden reply count of a topic (hidden includes trashed and spammed replies)
*
* @since bbPress (r2740)
*
* @param int $topic_id Optional. Topic id to update
* @param int $reply_count Optional. Set the reply count manually
* @uses bbp_is_reply() To check if the passed topic id is a reply
* @uses bbp_get_reply_topic_id() To get the reply topic id
* @uses bbp_get_topic_id() To get the topic id
* @uses bbp_get_reply_post_type() To get the reply post type
* @uses wpdb::prepare() To prepare our sql query
* @uses wpdb::get_var() To execute our query and get the var back
* @uses update_post_meta() To update the topic hidden reply count meta
* @uses apply_filters() Calls 'bbp_update_topic_reply_count_hidden' with the
* hidden reply count and topic id
* @return int Topic hidden reply count
*/
function bbp_update_topic_reply_count_hidden($topic_id = 0, $reply_count = 0)
{
global $wpdb;
// If it's a reply, then get the parent (topic id)
if (bbp_is_reply($topic_id)) {
$topic_id = bbp_get_reply_topic_id($topic_id);
} else {
$topic_id = bbp_get_topic_id($topic_id);
}
// Get replies of topic
if (empty($reply_count)) {
$post_status = "'" . implode("','", array(bbp_get_trash_status_id(), bbp_get_spam_status_id())) . "'";
$reply_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $topic_id, bbp_get_reply_post_type()));
}
update_post_meta($topic_id, '_bbp_reply_count_hidden', (int) $reply_count);
return apply_filters('bbp_update_topic_reply_count_hidden', (int) $reply_count, $topic_id);
}
示例9: bbp_update_forum_topic_count_hidden
/**
* Adjust the total hidden topic count of a forum (hidden includes trashed,
* spammed and pending topics)
*
* @since 2.0.0 bbPress (r2888)
* @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects
*
* @param int $forum_id Optional. Topic id to update.
* @param int $topic_count Optional. Set the topic count manually.
* @uses bbp_is_topic() To check if the supplied id is a topic
* @uses bbp_get_topic_id() To get the topic id
* @uses bbp_get_topic_forum_id() To get the topic forum id
* @uses bbp_get_forum_id() To get the forum id
* @uses bbp_get_trash_status_id() To get the trash status id
* @uses bbp_get_spam_status_id() To get the spam status id
* @uses bbp_get_pending_status_id() To get the pending status id
* @uses bbp_get_topic_post_type() To get the topic post type
* @uses update_post_meta() To update the forum hidden topic count meta
* @uses apply_filters() Calls 'bbp_update_forum_topic_count_hidden' with the
* hidden topic count and forum id
* @return int Topic hidden topic count
*/
function bbp_update_forum_topic_count_hidden($forum_id = 0, $topic_count = 0)
{
// If topic_id was passed as $forum_id, then get its forum
if (bbp_is_topic($forum_id)) {
$topic_id = bbp_get_topic_id($forum_id);
$forum_id = bbp_get_topic_forum_id($topic_id);
// $forum_id is not a topic_id, so validate and proceed
} else {
$forum_id = bbp_get_forum_id($forum_id);
}
// Can't update what isn't there
if (!empty($forum_id)) {
// Get topics of forum
if (empty($topic_count)) {
$query = new WP_Query(array('fields' => 'ids', 'post_parent' => $forum_id, 'post_status' => array(bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id()), 'post_type' => bbp_get_topic_post_type(), 'posts_per_page' => -1, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'ignore_sticky_posts' => true));
$topic_count = $query->post_count;
unset($query);
}
$topic_count = (int) $topic_count;
// Update the count
update_post_meta($forum_id, '_bbp_topic_count_hidden', $topic_count);
}
return (int) apply_filters('bbp_update_forum_topic_count_hidden', $topic_count, $forum_id);
}
示例10: bbp_new_reply_handler
//.........这里部分代码省略.........
$reply_title = apply_filters('bbp_new_reply_pre_title', $reply_title);
// No reply title
if (empty($reply_title)) {
bbp_add_error('bbp_reply_title', __('<strong>ERROR</strong>: Your reply needs a title.', 'bbpress'));
}
/** Reply Content *********************************************************/
if (!empty($_POST['bbp_reply_content'])) {
$reply_content = $_POST['bbp_reply_content'];
}
// Filter and sanitize
$reply_content = apply_filters('bbp_new_reply_pre_content', $reply_content);
// No reply content
if (empty($reply_content)) {
bbp_add_error('bbp_reply_content', __('<strong>ERROR</strong>: Your reply cannot be empty.', 'bbpress'));
}
/** Reply Flooding ********************************************************/
if (!bbp_check_for_flood($anonymous_data, $reply_author)) {
bbp_add_error('bbp_reply_flood', __('<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress'));
}
/** Reply Duplicate *******************************************************/
if (!bbp_check_for_duplicate(array('post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data))) {
bbp_add_error('bbp_reply_duplicate', __('<strong>ERROR</strong>: Duplicate reply detected; it looks as though you’ve already said that!', 'bbpress'));
}
/** Reply Blacklist *******************************************************/
if (!bbp_check_for_blacklist($anonymous_data, $reply_author, $reply_title, $reply_content)) {
bbp_add_error('bbp_reply_blacklist', __('<strong>ERROR</strong>: Your reply cannot be created at this time.', 'bbpress'));
}
/** Reply Moderation ******************************************************/
$post_status = bbp_get_public_status_id();
if (!bbp_check_for_moderation($anonymous_data, $reply_author, $reply_title, $reply_content)) {
$post_status = bbp_get_pending_status_id();
}
/** Topic Tags ************************************************************/
if (!empty($_POST['bbp_topic_tags'])) {
$terms = esc_attr(strip_tags($_POST['bbp_topic_tags']));
}
/** Additional Actions (Before Save) **************************************/
do_action('bbp_new_reply_pre_extras', $topic_id, $forum_id);
// Bail if errors
if (bbp_has_errors()) {
return;
}
/** No Errors *************************************************************/
// Add the content of the form to $reply_data as an array
// Just in time manipulation of reply data before being created
$reply_data = apply_filters('bbp_new_reply_pre_insert', array('post_author' => $reply_author, 'post_title' => $reply_title, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'post_status' => $post_status, 'post_type' => bbp_get_reply_post_type(), 'comment_status' => 'closed', 'menu_order' => (int) (bbp_get_topic_reply_count($topic_id) + 1)));
// Insert reply
$reply_id = wp_insert_post($reply_data);
/** No Errors *************************************************************/
// Check for missing reply_id or error
if (!empty($reply_id) && !is_wp_error($reply_id)) {
/** Topic Tags ********************************************************/
// Just in time manipulation of reply terms before being edited
$terms = apply_filters('bbp_new_reply_pre_set_terms', $terms, $topic_id, $reply_id);
// Insert terms
$terms = wp_set_post_terms($topic_id, $terms, bbp_get_topic_tag_tax_id(), false);
// Term error
if (is_wp_error($terms)) {
bbp_add_error('bbp_reply_tags', __('<strong>ERROR</strong>: There was a problem adding the tags to the topic.', 'bbpress'));
}
/** Trash Check *******************************************************/
// If this reply starts as trash, add it to pre_trashed_replies
// for the topic, so it is properly restored.
if (bbp_is_topic_trash($topic_id) || $reply_data['post_status'] == bbp_get_trash_status_id()) {
// Trash the reply
wp_trash_post($reply_id);
// Get pre_trashed_replies for topic
$pre_trashed_replies = get_post_meta($topic_id, '_bbp_pre_trashed_replies', true);
// Add this reply to the end of the existing replies
$pre_trashed_replies[] = $reply_id;
// Update the pre_trashed_reply post meta
update_post_meta($topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies);
}
/** Spam Check ********************************************************/
// If reply or topic are spam, officially spam this reply
if (bbp_is_topic_spam($topic_id) || $reply_data['post_status'] == bbp_get_spam_status_id()) {
add_post_meta($reply_id, '_bbp_spam_meta_status', bbp_get_public_status_id());
}
/** Update counts, etc... *********************************************/
do_action('bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author);
/** Additional Actions (After Save) ***********************************/
do_action('bbp_new_reply_post_extras', $reply_id);
/** Redirect **********************************************************/
// Redirect to
$redirect_to = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '';
// Get the reply URL
$reply_url = bbp_get_reply_url($reply_id, $redirect_to);
// Allow to be filtered
$reply_url = apply_filters('bbp_new_reply_redirect_to', $reply_url, $redirect_to, $reply_id);
/** Successful Save ***************************************************/
// Redirect back to new reply
wp_safe_redirect($reply_url);
// For good measure
exit;
/** Errors ****************************************************************/
} else {
$append_error = is_wp_error($reply_id) && $reply_id->get_error_message() ? $reply_id->get_error_message() . ' ' : '';
bbp_add_error('bbp_reply_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your reply:' . $append_error . 'Please try again.', 'bbpress'));
}
}
示例11: bbp_get_reply_admin_links
/**
* Return admin links for reply
*
* @since bbPress (r2667)
*
* @param mixed $args This function supports these arguments:
* - id: Optional. Reply id
* - before: HTML before the links. Defaults to
* '<span class="bbp-admin-links">'
* - after: HTML after the links. Defaults to '</span>'
* - sep: Separator. Defaults to ' | '
* - links: Array of the links to display. By default, edit, trash,
* spam and topic split links are displayed
* @uses bbp_is_topic() To check if it's the topic page
* @uses bbp_is_reply() To check if it's the reply page
* @uses bbp_get_reply_id() To get the reply id
* @uses bbp_get_reply_edit_link() To get the reply edit link
* @uses bbp_get_reply_trash_link() To get the reply trash link
* @uses bbp_get_reply_spam_link() To get the reply spam link
* @uses bbp_get_topic_split_link() To get the topic split link
* @uses current_user_can() To check if the current user can edit or
* delete the reply
* @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the
* reply admin links and args
* @return string Reply admin links
*/
function bbp_get_reply_admin_links($args = '')
{
$defaults = array('id' => 0, 'before' => '<span class="bbp-admin-links">', 'after' => '</span>', 'sep' => ' | ', 'links' => array());
$r = bbp_parse_args($args, $defaults, 'get_reply_admin_links');
$r['id'] = bbp_get_reply_id((int) $r['id']);
// If post is a topic, return the topic admin links instead
if (bbp_is_topic($r['id'])) {
return bbp_get_topic_admin_links($args);
}
// If post is not a reply, return
if (!bbp_is_reply($r['id'])) {
return;
}
// Make sure user can edit this reply
if (!current_user_can('edit_reply', $r['id'])) {
return;
}
// If topic is trashed, do not show admin links
if (bbp_is_topic_trash(bbp_get_reply_topic_id($r['id']))) {
return;
}
// If no links were passed, default to the standard
if (empty($r['links'])) {
$r['links'] = array('edit' => bbp_get_reply_edit_link($r), 'split' => bbp_get_topic_split_link($r), 'trash' => bbp_get_reply_trash_link($r), 'spam' => bbp_get_reply_spam_link($r));
}
// Check caps for trashing the topic
if (!current_user_can('delete_reply', $r['id']) && !empty($r['links']['trash'])) {
unset($r['links']['trash']);
}
// See if links need to be unset
$reply_status = bbp_get_reply_status($r['id']);
if (in_array($reply_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()))) {
// Spam link shouldn't be visible on trashed topics
if ($reply_status == bbp_get_trash_status_id()) {
unset($r['links']['spam']);
// Trash link shouldn't be visible on spam topics
} elseif (isset($r['links']['trash']) && bbp_get_spam_status_id() == $reply_status) {
unset($r['links']['trash']);
}
}
// Process the admin links
$links = implode($r['sep'], array_filter($r['links']));
$retval = $r['before'] . $links . $r['after'];
return apply_filters('bbp_get_reply_admin_links', $retval, $args);
}
示例12: bbp_get_reply_statuses
/**
* Return an associative array of available reply statuses
*
* @since 2.6.0 bbPress (r5399)
*
* @param int $reply_id Optional. Reply id.
*
* @return array
*/
function bbp_get_reply_statuses($reply_id = 0)
{
return apply_filters('bbp_get_reply_statuses', array(bbp_get_public_status_id() => _x('Publish', 'Publish the reply', 'bbpress'), bbp_get_spam_status_id() => _x('Spam', 'Spam the reply', 'bbpress'), bbp_get_trash_status_id() => _x('Trash', 'Trash the reply', 'bbpress'), bbp_get_pending_status_id() => _x('Pending', 'Mark reply as pending', 'bbpress')), $reply_id);
}
示例13: post_new_topic
//.........这里部分代码省略.........
/** TOPIC DATA ***************************************************/
$topic_content = $data['content'];
$topic_title = $data['subject'];
bp_rbe_log('Message #' . $i . ': body contents - ' . $topic_content);
bp_rbe_log('Subject - ' . $topic_title);
if (empty($topic_content) || empty($topic_title)) {
//do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_new_forum_topic_empty' );
return new WP_Error('bbp_new_forum_topic_empty', '', $data);
}
// Filter and sanitize
$topic_title = apply_filters('bbp_new_topic_pre_title', $topic_title);
$topic_content = apply_filters('bbp_new_topic_pre_content', $topic_content);
/** Topic Tags ****************************************************/
/* TODO
if ( bbp_allow_topic_tags() ) {
// Escape tag input
$terms = esc_attr( strip_tags( $_POST['bbp_topic_tags'] ) );
// Explode by comma
if ( strstr( $terms, ',' ) ) {
$terms = explode( ',', $terms );
}
// Add topic tag ID as main key
$terms = array( bbp_get_topic_tag_tax_id() => $terms );
}
*/
/** TOPIC MODERATION *********************************************/
// Post Flooding
if (!bbp_check_for_flood($anonymous_data, $topic_author)) {
//do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_flood' );
//bbp_add_error( 'bbp_reply_flood', __( '<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress' ) );
return new WP_Error('bbp_topic_flood', '', $data);
}
// Topic Duplicate
if (!bbp_check_for_duplicate(array('post_type' => bbp_get_topic_post_type(), 'post_author' => $topic_author, 'post_content' => $topic_content, 'anonymous_data' => $anonymous_data))) {
//do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_duplicate' );
return new WP_Error('bbp_topic_duplicate', '', $data);
}
// Topic Blacklist
if (!bbp_check_for_blacklist($anonymous_data, $topic_author, $topic_title, $topic_content)) {
//do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_blacklist' );
return new WP_Error('bbp_topic_blacklist', '', $data);
}
// Topic Status
// Maybe put into moderation
if (!bbp_check_for_moderation($anonymous_data, $topic_author, $topic_title, $topic_content)) {
$topic_status = bbp_get_pending_status_id();
// Default
} else {
$topic_status = bbp_get_public_status_id();
}
/** POSTING TIME! ************************************************/
// bbP hook before save
do_action('bbp_new_topic_pre_extras', $forum_id);
// Setup reply data
$topic_data = apply_filters('bbp_new_topic_pre_insert', array('post_author' => $topic_author, 'post_title' => $topic_title, 'post_content' => $topic_content, 'post_status' => $topic_status, 'post_parent' => $forum_id, 'post_type' => bbp_get_topic_post_type(), 'comment_status' => 'closed'));
// Insert topic
$topic_id = wp_insert_post($topic_data);
// Topic posted!
if (!is_wp_error($topic_id)) {
// more internal logging
bp_rbe_log('Message #' . $i . ': bbPress topic successfully posted!');
// Problem posting
} else {
//do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_error' );
return new WP_Error('bbp_topic_error', '', $data);
}
/** AFTER POSTING ************************************************/
// stuff that needs to happen after a bbP topic is posted occurs here... bbP
// should preferably do the following at the 'bbp_new_reply' hook, until then
// do what bbP does inline.
// Trash Check ////////////////////////////////////////////////////
// If the forum is trash, or the topic_status is switched to
// trash, trash it properly
if (get_post_field('post_status', $forum_id) == bbp_get_trash_status_id() || $topic_data['post_status'] == bbp_get_trash_status_id()) {
// Trash the reply
wp_trash_post($topic_id);
}
// Spam Check /////////////////////////////////////////////////////
// If reply or topic are spam, officially spam this reply
if ($topic_data['post_status'] == bbp_get_spam_status_id()) {
add_post_meta($topic_id, '_bbp_spam_meta_status', bbp_get_public_status_id());
}
// Reply By Email /////////////////////////////////////////////////
// Add a RBE marker to the post's meta
// Could potentially show that post was made via email on the frontend
add_post_meta($topic_id, 'bp_rbe', 1);
/** POST HOOKS ***************************************************/
// RBE Custom Hooks ///////////////////////////////////////////////
// change activity action
add_filter('bbp_before_record_activity_parse_args', array($this, 'change_activity_action'));
// add RBE's special activity hook
add_action('bp_activity_after_save', array($this, 'activity_rbe_hook'));
// bbPress Topic Hooks ////////////////////////////////////////////
do_action('bbp_new_topic', $topic_id, $forum_id, $anonymous_data, $topic_author);
do_action('bbp_new_topic_post_extras', $topic_id);
return array('bbp_topic_id' => $topic_id);
}
示例14: bbp_get_reply_admin_links
/**
* Return admin links for reply
*
* @since bbPress (r2667)
*
* @param array $args This function supports these arguments:
* - id: Optional. Reply id
* - before: HTML before the links. Defaults to
* '<span class="bbp-admin-links">'
* - after: HTML after the links. Defaults to '</span>'
* - sep: Separator. Defaults to ' | '
* - links: Array of the links to display. By default, edit, trash,
* spam, reply move, and topic split links are displayed
* @uses bbp_is_topic() To check if it's the topic page
* @uses bbp_is_reply() To check if it's the reply page
* @uses bbp_get_reply_id() To get the reply id
* @uses bbp_get_reply_edit_link() To get the reply edit link
* @uses bbp_get_reply_trash_link() To get the reply trash link
* @uses bbp_get_reply_spam_link() To get the reply spam link
* @uses bbp_get_reply_move_link() To get the reply move link
* @uses bbp_get_topic_split_link() To get the topic split link
* @uses current_user_can() To check if the current user can edit or
* delete the reply
* @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the
* reply admin links and args
* @return string Reply admin links
*/
function bbp_get_reply_admin_links($args = array())
{
// Parse arguments against default values
$r = bbp_parse_args($args, array('id' => 0, 'before' => '<span class="bbp-admin-links">', 'after' => '</span>', 'sep' => ' | ', 'links' => array()), 'get_reply_admin_links');
$r['id'] = bbp_get_reply_id((int) $r['id']);
// If post is a topic, return the topic admin links instead
if (bbp_is_topic($r['id'])) {
return bbp_get_topic_admin_links($args);
}
// If post is not a reply, return
if (!bbp_is_reply($r['id'])) {
return;
}
// If topic is trashed, do not show admin links
if (bbp_is_topic_trash(bbp_get_reply_topic_id($r['id']))) {
return;
}
// If no links were passed, default to the standard
if (empty($r['links'])) {
$r['links'] = apply_filters('bbp_reply_admin_links', array('edit' => bbp_get_reply_edit_link($r), 'move' => bbp_get_reply_move_link($r), 'split' => bbp_get_topic_split_link($r), 'trash' => bbp_get_reply_trash_link($r), 'spam' => bbp_get_reply_spam_link($r), 'reply' => bbp_get_reply_to_link($r)), $r['id']);
}
// See if links need to be unset
$reply_status = bbp_get_reply_status($r['id']);
if (in_array($reply_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()))) {
// Spam link shouldn't be visible on trashed topics
if (bbp_get_trash_status_id() === $reply_status) {
unset($r['links']['spam']);
// Trash link shouldn't be visible on spam topics
} elseif (bbp_get_spam_status_id() === $reply_status) {
unset($r['links']['trash']);
}
}
// Process the admin links
$links = implode($r['sep'], array_filter($r['links']));
$retval = $r['before'] . $links . $r['after'];
return apply_filters('bbp_get_reply_admin_links', $retval, $r, $args);
}
示例15: tehnik_bbp_has_topics
function tehnik_bbp_has_topics($args = '')
{
global $wp_rewrite;
/** Defaults ************************************************************* */
// Other defaults
$default_topic_search = !empty($_REQUEST['ts']) ? $_REQUEST['ts'] : false;
$default_show_stickies = (bool) (bbp_is_single_forum() || bbp_is_topic_archive()) && false === $default_topic_search;
$default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any';
// Default argument array
$default = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $default_post_parent, 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'posts_per_page' => bbp_get_topics_per_page(), 'paged' => bbp_get_paged(), 's' => $default_topic_search, 'show_stickies' => $default_show_stickies, 'max_num_pages' => false);
//Get an array of IDs which the current user has permissions to view
$allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($default));
// The default forum query with allowed forum ids array added
$default['post__in'] = $allowed_forums;
// What are the default allowed statuses (based on user caps)
if (bbp_get_view_all()) {
// Default view=all statuses
$post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id());
// Add support for private status
if (current_user_can('read_private_topics')) {
$post_statuses[] = bbp_get_private_status_id();
}
// Join post statuses together
$default['post_status'] = join(',', $post_statuses);
// Lean on the 'perm' query var value of 'readable' to provide statuses
} else {
$default['perm'] = 'readable';
}
// Maybe query for topic tags
if (bbp_is_topic_tag()) {
$default['term'] = bbp_get_topic_tag_slug();
$default['taxonomy'] = bbp_get_topic_tag_tax_id();
}
/** Setup **************************************************************** */
// Parse arguments against default values
$r = bbp_parse_args($args, $default, 'has_topics');
// Get bbPress
$bbp = bbpress();
// Call the query
$bbp->topic_query = new WP_Query($r);
// Set post_parent back to 0 if originally set to 'any'
if ('any' == $r['post_parent']) {
$r['post_parent'] = 0;
}
// Limited the number of pages shown
if (!empty($r['max_num_pages'])) {
$bbp->topic_query->max_num_pages = $r['max_num_pages'];
}
/** Stickies ************************************************************* */
// Put sticky posts at the top of the posts array
if (!empty($r['show_stickies']) && $r['paged'] <= 1) {
// Get super stickies and stickies in this forum
$stickies = bbp_get_super_stickies();
// Get stickies for current forum
if (!empty($r['post_parent'])) {
$stickies = array_merge($stickies, bbp_get_stickies($r['post_parent']));
}
// Remove any duplicate stickies
$stickies = array_unique($stickies);
// We have stickies
if (is_array($stickies) && !empty($stickies)) {
// Start the offset at -1 so first sticky is at correct 0 offset
$sticky_offset = -1;
// Loop over topics and relocate stickies to the front.
foreach ($stickies as $sticky_index => $sticky_ID) {
// Get the post offset from the posts array
$post_offsets = wp_filter_object_list($bbp->topic_query->posts, array('ID' => $sticky_ID), 'OR', 'ID');
// Continue if no post offsets
if (empty($post_offsets)) {
continue;
}
// Loop over posts in current query and splice them into position
foreach (array_keys($post_offsets) as $post_offset) {
$sticky_offset++;
$sticky = $bbp->topic_query->posts[$post_offset];
// Remove sticky from current position
array_splice($bbp->topic_query->posts, $post_offset, 1);
// Move to front, after other stickies
array_splice($bbp->topic_query->posts, $sticky_offset, 0, array($sticky));
// Cleanup
unset($stickies[$sticky_index]);
unset($sticky);
}
// Cleanup
unset($post_offsets);
}
// Cleanup
unset($sticky_offset);
// If any posts have been excluded specifically, Ignore those that are sticky.
if (!empty($stickies) && !empty($r['post__not_in'])) {
$stickies = array_diff($stickies, $r['post__not_in']);
}
// Fetch sticky posts that weren't in the query results
if (!empty($stickies)) {
// Query to use in get_posts to get sticky posts
$sticky_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => 'any', 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'include' => $stickies);
//Get an array of IDs which the current user has permissions to view
$allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($sticky_query));
// The default forum query with allowed forum ids array added
$sticky_query['post__in'] = $allowed_forums;
//.........这里部分代码省略.........