本文整理汇总了PHP中bbp_get_reply_forum_id函数的典型用法代码示例。如果您正苦于以下问题:PHP bbp_get_reply_forum_id函数的具体用法?PHP bbp_get_reply_forum_id怎么用?PHP bbp_get_reply_forum_id使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bbp_get_reply_forum_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bbps_is_reply_premium
function bbps_is_reply_premium()
{
$is_premium = get_post_meta(bbp_get_reply_forum_id(), '_bbps_is_premium');
if ($is_premium[0] == 1) {
return true;
} else {
return false;
}
}
示例2: test_bbp_update_reply_forum_id
/**
* @covers ::bbp_update_reply_forum_id
*/
public function test_bbp_update_reply_forum_id()
{
bbp_create_initial_content();
$forum_id = 36;
$topic_id = 37;
$reply_id = 38;
bbp_update_reply_forum_id($reply_id, $forum_id);
$reply_forum_id = bbp_get_reply_forum_id($reply_id);
$this->assertSame(36, $reply_forum_id);
}
示例3: has_access
/**
* Verify access to the current content.
*
* @since 1.0.0
*
* @param int $id The content post ID to verify access.
* @return bool|null True if has access, false otherwise.
* Null means: Rule not relevant for current page.
*/
public function has_access($id, $admin_has_access = true)
{
global $wp_query;
$has_access = null;
if (empty($id)) {
$id = $this->get_current_post_id();
}
if (!empty($id)) {
$post_type = get_post_type($id);
if (in_array($post_type, self::get_bb_cpt())) {
$has_access = false;
// Only verify permission if addon is enabled.
if (MS_Addon_Bbpress::is_active()) {
switch ($post_type) {
case self::CPT_BB_FORUM:
$has_access = parent::has_access($id, $admin_has_access);
break;
case self::CPT_BB_TOPIC:
if (function_exists('bbp_get_topic_forum_id')) {
$forum_id = bbp_get_topic_forum_id($id);
$has_access = parent::has_access($forum_id, $admin_has_access);
}
break;
case self::CPT_BB_REPLY:
if (function_exists('bbp_get_reply_forum_id')) {
$forum_id = bbp_get_reply_forum_id($id);
$has_access = parent::has_access($forum_id, $admin_has_access);
}
break;
}
} else {
$has_access = true;
}
}
} else {
/*
* If post type is forum and no post_id, it is the forum list page, give access.
* @todo Find another way to verify if the current page is the forum list page.
*/
if (self::CPT_BB_FORUM === $wp_query->get('post_type')) {
$has_access = true;
}
}
return apply_filters('ms_addon_bbpress_model_rule_has_access', $has_access, $id, $this);
}
示例4: nav_menu_css_class
static function nav_menu_css_class($classes, $item, $args, $depth)
{
if ($item->object == bbp_get_forum_post_type() && is_bbpress()) {
if (bbp_is_topic_edit() || bbp_is_single_topic()) {
$forum_id = bbp_get_topic_forum_id();
if ($forum_id == $item->object_id) {
$classes[] = 'current-menu-parent';
$classes[] = 'current-' . bbp_get_topic_post_type() . '-parent';
} elseif ($ancestors = self::forum_ancestors($forum_id, array())) {
if (in_array($item->object_id, $ancestors)) {
$classes[] = 'current-menu-ancestor';
$classes[] = 'current-' . bbp_get_topic_post_type() . '-ancestor';
}
}
} elseif (bbp_is_reply_edit() || bbp_is_single_reply()) {
$forum_id = bbp_get_reply_forum_id();
}
}
return $classes;
}
示例5: tehnik_bpp_get_forum_id_from_post_id
function tehnik_bpp_get_forum_id_from_post_id($post_id, $post_type)
{
$forum_id = 0;
// Check post type
switch ($post_type) {
// Forum
case bbp_get_forum_post_type():
$forum_id = bbp_get_forum_id($post_id);
break;
// Topic
// Topic
case bbp_get_topic_post_type():
$forum_id = bbp_get_topic_forum_id($post_id);
break;
// Reply
// Reply
case bbp_get_reply_post_type():
$forum_id = bbp_get_reply_forum_id($post_id);
break;
}
return $forum_id;
}
示例6: post_stylesheets_stylesheet_uri
/**
* Checks if a post (or any post type) has the given meta key of 'Stylesheet' when on the singular view of
* the post on the front of the site. If found, the function checks within the '/css' folder of the stylesheet
* directory (child theme) and the template directory (parent theme). If the file exists, it is used rather
* than the typical style.css file.
*
* @since 0.1.0
* @todo Use features from Ticket #18302 when available. http://core.trac.wordpress.org/ticket/18302
* @access public
* @param string $stylesheet_uri The URI of the active theme's stylesheet.
* @param string $stylesheet_dir_uri The directory URI of the active theme's stylesheet.
* @return string $stylesheet_uri
*/
function post_stylesheets_stylesheet_uri($stylesheet_uri, $stylesheet_dir_uri)
{
/* Check if viewing a singular post. */
if (is_singular()) {
/* If viewing a bbPress topic, use its forum object. */
if (function_exists('bbp_is_single_topic') && bbp_is_single_topic()) {
$post = get_post(bbp_get_topic_forum_id(get_queried_object_id()));
} elseif (function_exists('bbp_is_single_reply') && bbp_is_single_reply()) {
$post = get_post(bbp_get_reply_forum_id(get_queried_object_id()));
} else {
$post = get_queried_object();
}
/* Check if the post type supports 'post-stylesheets' before proceeding. */
if (post_type_supports($post->post_type, 'post-stylesheets')) {
/* Check if the user has set a value for the post stylesheet. */
$stylesheet = get_post_stylesheet($post->ID);
/* If a meta value was given and the file exists, set $stylesheet_uri to the new file. */
if (!empty($stylesheet)) {
/* If the stylesheet is found in the child theme, use it. */
if (file_exists(trailingslashit(get_stylesheet_directory()) . $stylesheet)) {
$stylesheet_uri = trailingslashit($stylesheet_dir_uri) . $stylesheet;
} elseif (file_exists(trailingslashit(get_template_directory()) . $stylesheet)) {
$stylesheet_uri = trailingslashit(get_template_directory_uri()) . $stylesheet;
} else {
/* If the stylesheet is found in the child theme '/css' folder, use it. */
if (file_exists(trailingslashit(get_stylesheet_directory()) . "css/{$stylesheet}")) {
$stylesheet_uri = trailingslashit($stylesheet_dir_uri) . "css/{$stylesheet}";
/* Set the post stylesheet to the correct directory. */
set_post_stylesheet($post->ID, str_replace(get_stylesheet_directory_uri(), 'css/', $stylesheet_uri));
} elseif (file_exists(trailingslashit(get_template_directory()) . "css/{$stylesheet}")) {
$stylesheet_uri = trailingslashit(get_template_directory_uri()) . "css/{$stylesheet}";
/* Set the post stylesheet to the correct directory. */
set_post_stylesheet($post->ID, str_replace(get_template_directory_uri(), 'css/', $stylesheet_uri));
}
}
}
}
}
/* Return the stylesheet URI. */
return $stylesheet_uri;
}
示例7: bbp_forum_enforce_private
/**
* Check if it's a private forum or a topic or reply of a private forum and if
* the user can't view it, then sets a 404
*
* @since bbPress (r2996)
*
* @uses current_user_can() To check if the current user can read private forums
* @uses is_singular() To check if it's a singular page
* @uses bbp_is_user_keymaster() To check if user is a keymaster
* @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_topic_forum_id() To get the topic forum id
* @uses bbp_get_reply_forum_id() To get the reply forum id
* @uses bbp_is_forum_private() To check if the forum is private or not
* @uses bbp_set_404() To set a 404 status
*/
function bbp_forum_enforce_private()
{
// Bail if not viewing a single item or if user has caps
if (!is_singular() || bbp_is_user_keymaster() || current_user_can('read_private_forums')) {
return;
}
global $wp_query;
// Define local variable
$forum_id = 0;
// Check post type
switch ($wp_query->get('post_type')) {
// Forum
case bbp_get_forum_post_type():
$forum_id = bbp_get_forum_id($wp_query->post->ID);
break;
// Topic
// Topic
case bbp_get_topic_post_type():
$forum_id = bbp_get_topic_forum_id($wp_query->post->ID);
break;
// Reply
// Reply
case bbp_get_reply_post_type():
$forum_id = bbp_get_reply_forum_id($wp_query->post->ID);
break;
}
// If forum is explicitly hidden and user not capable, set 404
if (!empty($forum_id) && bbp_is_forum_private($forum_id) && !current_user_can('read_private_forums')) {
bbp_set_404();
}
}
示例8: bbp_update_reply_walker
/**
* Walk up the ancestor tree from the current reply, and update all the counts
*
* @since bbPress (r2884)
*
* @param int $reply_id Optional. Reply id
* @param string $last_active_time Optional. Last active time
* @param int $forum_id Optional. Forum id
* @param int $topic_id Optional. Topic id
* @param bool $refresh If set to true, unsets all the previous parameters.
* Defaults to true
* @uses bbp_get_reply_id() To get the reply id
* @uses bbp_get_reply_topic_id() To get the reply topic id
* @uses bbp_get_reply_forum_id() To get the reply forum id
* @uses get_post_ancestors() To get the ancestors of the reply
* @uses bbp_is_reply() To check if the ancestor is a reply
* @uses bbp_is_topic() To check if the ancestor is a topic
* @uses bbp_update_topic_last_reply_id() To update the topic last reply id
* @uses bbp_update_topic_last_active_id() To update the topic last active id
* @uses bbp_get_topic_last_active_id() To get the topic last active id
* @uses get_post_field() To get the post date of the last active id
* @uses bbp_update_topic_last_active_time() To update the last active topic meta
* @uses bbp_update_topic_voice_count() To update the topic voice count
* @uses bbp_update_topic_reply_count() To update the topic reply count
* @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
* count
* @uses bbp_is_forum() To check if the ancestor is a forum
* @uses bbp_update_forum_last_topic_id() To update the last topic id forum meta
* @uses bbp_update_forum_last_reply_id() To update the last reply id forum meta
* @uses bbp_update_forum_last_active_id() To update the forum last active id
* @uses bbp_get_forum_last_active_id() To get the forum last active id
* @uses bbp_update_forum_last_active_time() To update the forum last active time
* @uses bbp_update_forum_reply_count() To update the forum reply count
*/
function bbp_update_reply_walker($reply_id, $last_active_time = '', $forum_id = 0, $topic_id = 0, $refresh = true)
{
// Verify the reply ID
$reply_id = bbp_get_reply_id($reply_id);
// Reply was passed
if (!empty($reply_id)) {
// Get the topic ID if none was passed
if (empty($topic_id)) {
$topic_id = bbp_get_reply_topic_id($reply_id);
}
// Get the forum ID if none was passed
if (empty($forum_id)) {
$forum_id = bbp_get_reply_forum_id($reply_id);
}
}
// Set the active_id based on topic_id/reply_id
$active_id = empty($reply_id) ? $topic_id : $reply_id;
// Setup ancestors array to walk up
$ancestors = array_values(array_unique(array_merge(array($topic_id, $forum_id), (array) get_post_ancestors($topic_id))));
// If we want a full refresh, unset any of the possibly passed variables
if (true === $refresh) {
$forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
}
// Walk up ancestors
if (!empty($ancestors)) {
foreach ($ancestors as $ancestor) {
// Reply meta relating to most recent reply
if (bbp_is_reply($ancestor)) {
// @todo - hierarchical replies
// Topic meta relating to most recent reply
} elseif (bbp_is_topic($ancestor)) {
// Last reply and active ID's
bbp_update_topic_last_reply_id($ancestor, $reply_id);
bbp_update_topic_last_active_id($ancestor, $active_id);
// Get the last active time if none was passed
$topic_last_active_time = $last_active_time;
if (empty($last_active_time)) {
$topic_last_active_time = get_post_field('post_date', bbp_get_topic_last_active_id($ancestor));
}
// Only update if reply is published
if (bbp_is_reply_published($reply_id)) {
bbp_update_topic_last_active_time($ancestor, $topic_last_active_time);
}
// Counts
bbp_update_topic_voice_count($ancestor);
bbp_update_topic_reply_count($ancestor);
bbp_update_topic_reply_count_hidden($ancestor);
// Forum meta relating to most recent topic
} elseif (bbp_is_forum($ancestor)) {
// Last topic and reply ID's
bbp_update_forum_last_topic_id($ancestor, $topic_id);
bbp_update_forum_last_reply_id($ancestor, $reply_id);
// Last Active
bbp_update_forum_last_active_id($ancestor, $active_id);
// Get the last active time if none was passed
$forum_last_active_time = $last_active_time;
if (empty($last_active_time)) {
$forum_last_active_time = get_post_field('post_date', bbp_get_forum_last_active_id($ancestor));
}
// Only update if reply is published
if (bbp_is_reply_published($reply_id)) {
bbp_update_forum_last_active_time($ancestor, $forum_last_active_time);
}
// Counts
bbp_update_forum_reply_count($ancestor);
}
//.........这里部分代码省略.........
示例9: reply_update
/**
* Update the activity stream entry when a reply status changes
*
* @param int $post_id
* @param obj $post
* @uses get_post_type()
* @uses bbp_get_reply_post_type()
* @uses bbp_get_reply_id()
* @uses bbp_is_reply_anonymous()
* @uses bbp_get_public_status_id()
* @uses bbp_get_closed_status_id()
* @uses bbp_get_reply_topic_id()
* @uses bbp_get_reply_forum_id()
* @uses bbp_get_reply_author_id()
* @return Bail early if not a reply, or reply is by anonymous user
*/
public function reply_update($reply_id, $post)
{
// Bail early if not a reply
if (get_post_type($post) != bbp_get_reply_post_type()) {
return;
}
$reply_id = bbp_get_reply_id($reply_id);
// Bail early if reply is by anonymous user
if (bbp_is_reply_anonymous($reply_id)) {
return;
}
$anonymous_data = array();
// Action based on new status
if ($post->post_status == bbp_get_public_status_id()) {
// Validate reply data
$topic_id = bbp_get_reply_topic_id($reply_id);
$forum_id = bbp_get_reply_forum_id($reply_id);
$reply_author_id = bbp_get_reply_author_id($reply_id);
$this->reply_create($reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author_id);
} else {
$this->reply_delete($reply_id);
}
}
示例10: bbp_suppress_private_author_link
/**
* Replace forum author details for users that cannot view them.
*
* @since bbPress (r3162)
*
* @param string $retval
* @param int $forum_id
*
* @uses bbp_is_forum_private()
* @uses get_post_field()
* @uses bbp_get_topic_post_type()
* @uses bbp_is_forum_private()
* @uses bbp_get_topic_forum_id()
* @uses bbp_get_reply_post_type()
* @uses bbp_get_reply_forum_id()
*
* @return string
*/
function bbp_suppress_private_author_link($author_link, $args)
{
// Assume the author link is the return value
$retval = $author_link;
// Show the normal author link
if (!empty($args['post_id']) && !current_user_can('read_private_forums')) {
// What post type are we looking at?
$post_type = get_post_field('post_type', $args['post_id']);
switch ($post_type) {
// Topic
case bbp_get_topic_post_type():
if (bbp_is_forum_private(bbp_get_topic_forum_id($args['post_id']))) {
$retval = '';
}
break;
// Reply
// Reply
case bbp_get_reply_post_type():
if (bbp_is_forum_private(bbp_get_reply_forum_id($args['post_id']))) {
$retval = '';
}
break;
// Post
// Post
default:
if (bbp_is_forum_private($args['post_id'])) {
$retval = '';
}
break;
}
}
return apply_filters('bbp_suppress_private_author_link', $retval);
}
示例11: display_reply
/**
* Display the contents of a specific reply ID in an output buffer
* and return to ensure that post/page contents are displayed first.
*
* @since bbPress (r3031)
*
* @param array $attr
* @param string $content
* @uses get_template_part()
* @return string
*/
public function display_reply($attr, $content = '')
{
// Sanity check required info
if (!empty($content) || (empty($attr['id']) || !is_numeric($attr['id']))) {
return $content;
}
// Unset globals
$this->unset_globals();
// Set passed attribute to $reply_id for clarity
$reply_id = bbpress()->current_reply_id = $attr['id'];
$forum_id = bbp_get_reply_forum_id($reply_id);
// Bail if ID passed is not a reply
if (!bbp_is_reply($reply_id)) {
return $content;
}
// Reset the queries if not in theme compat
if (!bbp_is_theme_compat_active()) {
$bbp = bbpress();
// Reset necessary forum_query attributes for replys loop to function
$bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
$bbp->forum_query->in_the_loop = true;
$bbp->forum_query->post = get_post($forum_id);
// Reset necessary reply_query attributes for replys loop to function
$bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type();
$bbp->reply_query->in_the_loop = true;
$bbp->reply_query->post = get_post($reply_id);
}
// Start output buffer
$this->start('bbp_single_reply');
// Check forum caps
if (bbp_user_can_view_forum(array('forum_id' => $forum_id))) {
bbp_get_template_part('content', 'single-reply');
// Forum is private and user does not have caps
} elseif (bbp_is_forum_private($forum_id, false)) {
bbp_get_template_part('feedback', 'no-access');
}
// Return contents of output buffer
return $this->end();
}
示例12: _build_email
/**
* @since 1.4
*/
private function _build_email($type, $post_id)
{
$email_subject = get_option("bbpress_notify_new{$type}_email_subject");
$email_body = get_option("bbpress_notify_new{$type}_email_body");
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$excerpt_size = apply_filters('bpnns_excerpt_size', 100);
// Replace shortcodes
if ('topic' === $type) {
$content = bbp_get_topic_content($post_id);
$title = html_entity_decode(strip_tags(bbp_get_topic_title($post_id)), ENT_NOQUOTES, 'UTF-8');
$excerpt = html_entity_decode(strip_tags(bbp_get_topic_excerpt($post_id, $excerpt_size)), ENT_NOQUOTES, 'UTF-8');
$author = bbp_get_topic_author($post_id);
$url = apply_filters('bbpnns_topic_url', bbp_get_topic_permalink($post_id), $post_id, $title);
$forum = html_entity_decode(strip_tags(get_the_title(bbp_get_topic_forum_id($post_id))), ENT_NOQUOTES, 'UTF-8');
} elseif ('reply' === $type) {
$content = bbp_get_reply_content($post_id);
$title = html_entity_decode(strip_tags(bbp_get_reply_title($post_id)), ENT_NOQUOTES, 'UTF-8');
$excerpt = html_entity_decode(strip_tags(bbp_get_reply_excerpt($post_id, $excerpt_size)), ENT_NOQUOTES, 'UTF-8');
$author = bbp_get_reply_author($post_id);
$url = apply_filters('bbpnns_reply_url', bbp_get_reply_permalink($post_id), $post_id, $title);
$forum = html_entity_decode(strip_tags(get_the_title(bbp_get_reply_forum_id($post_id))), ENT_NOQUOTES, 'UTF-8');
} else {
wp_die('Invalid type!');
}
$content = preg_replace('/<br\\s*\\/?>/is', PHP_EOL, $content);
$content = preg_replace('/(?:<\\/p>\\s*<p>)/ism', PHP_EOL . PHP_EOL, $content);
$content = html_entity_decode(strip_tags($content), ENT_NOQUOTES, 'UTF-8');
$topic_reply = apply_filters('bbpnns_topic_reply', bbp_get_reply_url($post_id), $post_id, $title);
$email_subject = str_replace('[blogname]', $blogname, $email_subject);
$email_subject = str_replace("[{$type}-title]", $title, $email_subject);
$email_subject = str_replace("[{$type}-content]", $content, $email_subject);
$email_subject = str_replace("[{$type}-excerpt]", $excerpt, $email_subject);
$email_subject = str_replace("[{$type}-author]", $author, $email_subject);
$email_subject = str_replace("[{$type}-url]", $url, $email_subject);
$email_subject = str_replace("[{$type}-replyurl]", $topic_reply, $email_subject);
$email_subject = str_replace("[{$type}-forum]", $forum, $email_subject);
$email_body = str_replace('[blogname]', $blogname, $email_body);
$email_body = str_replace("[{$type}-title]", $title, $email_body);
$email_body = str_replace("[{$type}-content]", $content, $email_body);
$email_body = str_replace("[{$type}-excerpt]", $excerpt, $email_body);
$email_body = str_replace("[{$type}-author]", $author, $email_body);
$email_body = str_replace("[{$type}-url]", $url, $email_body);
$email_body = str_replace("[{$type}-replyurl]", $topic_reply, $email_body);
$email_body = str_replace("[{$type}-forum]", $forum, $email_body);
/**
* Allow subject and body modifications
* @since 1.6.6
*/
$email_subject = apply_filters('bbpnns_filter_email_subject_in_build', $email_subject, $type, $post_id);
$email_body = apply_filters('bbpnns_filter_email_body_in_build', $email_body, $type, $post_id);
return array($email_subject, $email_body);
}
示例13: can_download
static function can_download($attachment)
{
$attachment = get_post($attachment);
if (!$attachment || $attachment->post_type != 'attachment') {
return false;
}
$post = get_post($attachment->post_parent);
$post_type = get_post_type($post);
$bbp_types = array(bbp_get_topic_post_type(), bbp_get_reply_post_type());
if (in_array($post_type, $bbp_types)) {
if (current_user_can('moderate')) {
return true;
}
$forum_id = $post_type == bbp_get_topic_post_type() ? bbp_get_topic_forum_id() : bbp_get_reply_forum_id();
$allowed_roles = (array) get_option('_bbpkr_download_perms', self::$download_perms);
if ($use_custom = Permissions::use_custom($forum_id)) {
$allowed_roles = Permissions::get_forum_perms($use_custom, 'download');
}
$can = in_array(bbpresskr()->get_user_role(), $allowed_roles);
} else {
// TODO: default user level for download, currently for all
$can = self::check_user(self::$wp_download_level);
}
return $can;
}
示例14: bbp_update_reply_walker
/**
* Walk up the ancestor tree from the current reply, and update all the counts
*
* @since 2.0.0 bbPress (r2884)
*
* @param int $reply_id Optional. Reply id
* @param string $last_active_time Optional. Last active time
* @param int $forum_id Optional. Forum id
* @param int $topic_id Optional. Topic id
* @param bool $refresh If set to true, unsets all the previous parameters.
* Defaults to true
* @uses bbp_get_reply_id() To get the reply id
* @uses bbp_get_reply_topic_id() To get the reply topic id
* @uses bbp_get_reply_forum_id() To get the reply forum id
* @uses get_post_ancestors() To get the ancestors of the reply
* @uses bbp_is_reply() To check if the ancestor is a reply
* @uses bbp_is_topic() To check if the ancestor is a topic
* @uses bbp_update_topic_last_reply_id() To update the topic last reply id
* @uses bbp_update_topic_last_active_id() To update the topic last active id
* @uses bbp_get_topic_last_active_id() To get the topic last active id
* @uses get_post_field() To get the post date of the last active id
* @uses bbp_update_topic_last_active_time() To update the last active topic meta
* @uses bbp_update_topic_voice_count() To update the topic voice count
* @uses bbp_update_topic_reply_count() To update the topic reply count
* @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
* count
* @uses bbp_is_forum() To check if the ancestor is a forum
* @uses bbp_update_forum_last_topic_id() To update the last topic id forum meta
* @uses bbp_update_forum_last_reply_id() To update the last reply id forum meta
* @uses bbp_update_forum_last_active_id() To update the forum last active id
* @uses bbp_get_forum_last_active_id() To get the forum last active id
* @uses bbp_update_forum_last_active_time() To update the forum last active time
* @uses bbp_update_forum_reply_count() To update the forum reply count
*/
function bbp_update_reply_walker($reply_id, $last_active_time = '', $forum_id = 0, $topic_id = 0, $refresh = true)
{
// Verify the reply ID
$reply_id = bbp_get_reply_id($reply_id);
// Reply was passed
if (!empty($reply_id)) {
// Get the topic ID if none was passed
if (empty($topic_id)) {
$topic_id = bbp_get_reply_topic_id($reply_id);
// Make every effort to get topic id
// https://bbpress.trac.wordpress.org/ticket/2529
if (empty($topic_id) && current_filter() === 'bbp_deleted_reply') {
$topic_id = get_post_field('post_parent', $reply_id);
}
}
// Get the forum ID if none was passed
if (empty($forum_id)) {
$forum_id = bbp_get_reply_forum_id($reply_id);
}
}
// Set the active_id based on topic_id/reply_id
$active_id = empty($reply_id) ? $topic_id : $reply_id;
// Setup ancestors array to walk up
$ancestors = array_values(array_unique(array_merge(array($topic_id, $forum_id), (array) get_post_ancestors($topic_id))));
// If we want a full refresh, unset any of the possibly passed variables
if (true === $refresh) {
$forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
}
// Walk up ancestors
if (!empty($ancestors)) {
foreach ($ancestors as $ancestor) {
// Reply meta relating to most recent reply
if (bbp_is_reply($ancestor)) {
// @todo - hierarchical replies
// Topic meta relating to most recent reply
} elseif (bbp_is_topic($ancestor)) {
// Last reply and active ID's
bbp_update_topic_last_reply_id($ancestor, $reply_id);
bbp_update_topic_last_active_id($ancestor, $active_id);
// Get the last active time if none was passed
$topic_last_active_time = $last_active_time;
if (empty($last_active_time)) {
$topic_last_active_time = get_post_field('post_date', bbp_get_topic_last_active_id($ancestor));
}
// Update the topic last active time regardless of reply status.
// See https://bbpress.trac.wordpress.org/ticket/2838
bbp_update_topic_last_active_time($ancestor, $topic_last_active_time);
// Counts
bbp_update_topic_voice_count($ancestor);
// Only update reply count if we're deleting a reply, or in the dashboard.
if (in_array(current_filter(), array('bbp_deleted_reply', 'save_post'), true)) {
bbp_update_topic_reply_count($ancestor);
bbp_update_topic_reply_count_hidden($ancestor);
}
// Forum meta relating to most recent topic
} elseif (bbp_is_forum($ancestor)) {
// Last topic and reply ID's
bbp_update_forum_last_topic_id($ancestor, $topic_id);
bbp_update_forum_last_reply_id($ancestor, $reply_id);
// Last Active
bbp_update_forum_last_active_id($ancestor, $active_id);
// Get the last active time if none was passed
$forum_last_active_time = $last_active_time;
if (empty($last_active_time)) {
$forum_last_active_time = get_post_field('post_date', bbp_get_forum_last_active_id($ancestor));
}
//.........这里部分代码省略.........
示例15: bbp_map_primary_meta_caps
/**
* Maps primary capabilities
*
* @since 2.2.0 bbPress (r4242)
*
* @param array $caps Capabilities for meta capability.
* @param string $cap Capability name.
* @param int $user_id User id.
* @param array $args Arguments.
* @uses bbp_is_user_inactive() To check if user is spammer or deleted
* @uses get_post() To get the post
* @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_topic_forum_id() To get the topic forum id
* @uses bbp_get_reply_post_type() To get the reply post type
* @uses bbp_get_reply_forum_id() To get the reply forum id
* @uses bbp_is_user_forum_mod() To check if the user is a forum moderator
* @uses apply_filters() Filter mapped results
*
* @return array Actual capabilities for meta capability
*/
function bbp_map_primary_meta_caps($caps = array(), $cap = '', $user_id = 0, $args = array())
{
// What capability is being checked?
switch ($cap) {
case 'spectate':
// Do not allow inactive users.
if (bbp_is_user_inactive($user_id)) {
$caps = array('do_not_allow');
// Default to the current cap.
} else {
$caps = array($cap);
}
break;
case 'participate':
// Do not allow inactive users.
if (bbp_is_user_inactive($user_id)) {
$caps = array('do_not_allow');
// Default to the current cap.
} else {
$caps = array($cap);
}
break;
case 'moderate':
// Do not allow inactive users.
if (bbp_is_user_inactive($user_id)) {
$caps = array('do_not_allow');
// Default to the current cap.
} else {
$caps = array($cap);
// Bail if no post to check.
if (empty($args[0])) {
break;
}
// Get the post.
$_post = get_post($args[0]);
if (empty($_post)) {
break;
}
// Get forum ID for specific type of post.
switch ($_post->post_type) {
// Forum.
case bbp_get_forum_post_type():
$forum_id = $_post->ID;
break;
// Topic.
// Topic.
case bbp_get_topic_post_type():
$forum_id = bbp_get_topic_forum_id($_post->ID);
break;
// Reply.
// Reply.
case bbp_get_reply_post_type():
$forum_id = bbp_get_reply_forum_id($_post->ID);
break;
// Any other post type defaults to 0.
// Any other post type defaults to 0.
default:
$forum_id = 0;
break;
}
// Bail if no forum ID.
if (empty($forum_id)) {
break;
}
// If user is a per-forum moderator, make sure they can spectate.
if (bbp_is_user_forum_mod($user_id, $forum_id)) {
$caps = array('spectate');
}
}
break;
}
return apply_filters('bbp_map_primary_meta_caps', $caps, $cap, $user_id, $args);
}