function maybe_add_robots() { global $post; if (is_singular() && bbp_is_topic($post->ID) && bbp_is_topic_closed($post->ID) && time() - get_post_time('U', true, $post) > YEAR_IN_SECONDS) { echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; } }
function pmpro_bbp_is_forum($forum_id = NULL) { global $post; if (bbp_is_forum($post->ID)) { if (!empty($forum_id) && $post->ID == $forum_id) { return true; } elseif (empty($forum_id)) { return true; } else { return false; } } elseif (bbp_is_topic($post->ID)) { if (!empty($forum_id) && $post->post_parent == $forum_id) { return true; } elseif (empty($forum_id)) { return true; } else { return false; } } elseif (bbp_is_reply($post->ID)) { if (!empty($forum_id) && in_array($forum_id, $post->ancestors)) { return true; } elseif (empty($forum_id)) { return true; } else { return false; } } else { return false; } }
/** * Return the author link of the post * * @since 2.0.0 bbPress (r2875) * * @param array $args Optional. If an integer, it is used as reply id. * @uses bbp_is_topic() To check if it's a topic page * @uses bbp_get_topic_author_link() To get the topic author link * @uses bbp_is_reply() To check if it's a reply page * @uses bbp_get_reply_author_link() To get the reply author link * @uses get_post_field() To get the post author * @uses bbp_is_reply_anonymous() To check if the reply is by an * anonymous user * @uses get_the_author_meta() To get the author name * @uses bbp_get_user_profile_url() To get the author profile url * @uses get_avatar() To get the author avatar * @uses apply_filters() Calls 'bbp_get_reply_author_link' with the * author link and args * @return string Author link of reply */ function bbp_get_author_link($args = array()) { $post_id = is_numeric($args) ? (int) $args : 0; // Parse arguments against default values $r = bbp_parse_args($args, array('post_id' => $post_id, 'link_title' => '', 'type' => 'both', 'size' => 80), 'get_author_link'); // Confirmed topic if (bbp_is_topic($r['post_id'])) { return bbp_get_topic_author_link($r); // Confirmed reply } elseif (bbp_is_reply($r['post_id'])) { return bbp_get_reply_author_link($r); } // Get the post author and proceed $user_id = get_post_field('post_author', $r['post_id']); // Neither a reply nor a topic, so could be a revision if (!empty($r['post_id'])) { // Generate title with the display name of the author if (empty($r['link_title'])) { $r['link_title'] = sprintf(!bbp_is_reply_anonymous($r['post_id']) ? __('View %s\'s profile', 'bbpress') : __('Visit %s\'s website', 'bbpress'), get_the_author_meta('display_name', $user_id)); } // Assemble some link bits $link_title = !empty($r['link_title']) ? ' title="' . esc_attr($r['link_title']) . '"' : ''; $anonymous = bbp_is_reply_anonymous($r['post_id']); // Declare empty array $author_links = array(); // Get avatar if ('avatar' === $r['type'] || 'both' === $r['type']) { $author_links[] = get_avatar($user_id, $r['size']); } // Get display name if ('name' === $r['type'] || 'both' === $r['type']) { $author_links[] = esc_html(get_the_author_meta('display_name', $user_id)); } // Add links if not anonymous if (empty($anonymous) && bbp_user_has_profile($user_id)) { $author_url = bbp_get_user_profile_url($user_id); foreach ($author_links as $link_text) { $author_link[] = sprintf('<a href="%1$s"%2$s>%3$s</a>', esc_url($author_url), $link_title, $link_text); } $author_link = implode(' ', $author_link); // No links if anonymous } else { $author_link = implode(' ', $author_links); } // No post so link is empty } else { $author_link = ''; } return apply_filters('bbp_get_author_link', $author_link, $r); }
/** * Ouput a notice on the front end when a reply has been reported * * @return null */ public function output_reply_notice() { global $post; $reply_id = get_the_ID(); // If post is a topic, return. (handled with 'output_topic_notice') if (bbp_is_topic($reply_id)) { return; } if (!$this->is_reply_reported($reply_id)) { return; } echo '<div class="error bbp-rc-reply-is-reported">'; echo '<p>'; echo apply_filters('bbp_rc_reply_notice', __('<em>This reply has been reported for inappropriate content.</em>', 'bbpress-report-content')); echo '</p>'; echo '</div>'; }
/** * Get the Post ID * Added support for sale of bbPress items. * @since 1.3.3.2 * @version 1.0 */ public function get_post_ID() { $post_id = $bbp_topic_id = $bbp_reply_id = 0; if (function_exists('bbpress')) { global $wp_query; $bbp = bbpress(); // Currently inside a topic loop if (!empty($bbp->topic_query->in_the_loop) && isset($bbp->topic_query->post->ID)) { $bbp_topic_id = $bbp->topic_query->post->ID; } elseif (!empty($bbp->search_query->in_the_loop) && isset($bbp->search_query->post->ID) && bbp_is_topic($bbp->search_query->post->ID)) { $bbp_topic_id = $bbp->search_query->post->ID; } elseif ((bbp_is_single_topic() || bbp_is_topic_edit()) && !empty($bbp->current_topic_id)) { $bbp_topic_id = $bbp->current_topic_id; } elseif ((bbp_is_single_topic() || bbp_is_topic_edit()) && isset($wp_query->post->ID)) { $bbp_topic_id = $wp_query->post->ID; } // So far, no topic found, check if we are in a reply if ($bbp_topic_id == 0) { // Currently inside a replies loop if (!empty($bbp->reply_query->in_the_loop) && isset($bbp->reply_query->post->ID)) { $bbp_reply_id = $bbp->reply_query->post->ID; } elseif (!empty($bbp->search_query->in_the_loop) && isset($bbp->search_query->post->ID) && bbp_is_reply($bbp->search_query->post->ID)) { $bbp_reply_id = $bbp->search_query->post->ID; } elseif ((bbp_is_single_reply() || bbp_is_reply_edit()) && !empty($bbp->current_reply_id)) { $bbp_reply_id = $bbp->current_reply_id; } elseif ((bbp_is_single_reply() || bbp_is_reply_edit()) && isset($wp_query->post->ID)) { $bbp_reply_id = $wp_query->post->ID; } if ($bbp_reply_id != 0) { $post_id = $bbp_reply_id; } } else { $post_id = $bbp_topic_id; } } if ($post_id == 0 && isset($GLOBALS['post'])) { $post_id = $GLOBALS['post']->ID; } return apply_filters('mycred_sell_this_get_post_ID', $post_id, $this); }
/** * Called after untrashing a topic * * @uses bbp_get_topic_id() To get the topic id * @uses bbp_is_topic() To check if the passed id is a topic * @uses do_action() Calls 'bbp_untrashed_topic' with the topic id */ function bbp_untrashed_topic($topic_id = 0) { $topic_id = bbp_get_topic_id($topic_id); if (empty($topic_id) || !bbp_is_topic($topic_id)) { return false; } do_action('bbp_untrashed_topic', $topic_id); }
/** * 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); }
/** * 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); } } } }
/** * 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); }
/** * 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); }
public static function user_has_cap($allcaps, $caps, $args, $user) { if (!in_array('upload_files', $caps)) { return $allcaps; } $can = isset($allcaps['upload_files']) ? $allcaps['upload_files'] : false; // async-upload.php, admin-ajax.php 를 통해서 업로드할 때 권한 체크가 어려움 $ajax_attachment_actions = apply_filters('bbpkr_ajax_attachment_actions', array('upload-attachment', 'query-attachments')); if ((isset($_REQUEST['post_id']) || !empty(self::$forum_id)) && empty($allcaps['upload_files']) && (defined('DOING_AJAX') && true === DOING_AJAX) && (isset($_REQUEST['action']) && in_array($_REQUEST['action'], $ajax_attachment_actions))) { if (isset($_REQUEST['post_id'])) { $the_id = (int) $_REQUEST['post_id']; if (bbp_is_forum($the_id)) { self::$forum_id = $the_id; } elseif (bbp_is_topic($the_id)) { self::$forum_id = (int) bbp_get_topic_forum_id($the_id); } elseif (bbp_is_reply($the_id)) { self::$forum_id = (int) bbp_get_reply_forum_id($the_id); } } if (!self::$forum_id) { return $allcaps; } $forum_id = self::$forum_id; // unset post_id to avoid edit_post check( DO NOT UNSET $_POST['post_id'] ) $_REQUEST['post_id'] = null; $allcaps['upload_files'] = self::can_upload($can, $forum_id); return $allcaps; } $allcaps['upload_files'] = self::can_upload($can); return $allcaps; }
/** * 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)); } // 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 // 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_forum_reply_count($ancestor); } } } } }
<?php /** * Replies Loop - Single Reply * * @package bbPress * @subpackage Theme */ ?> <section id="post-<?php bbp_reply_id(); ?> " class="bbp-reply"> <?php if (!bbp_is_topic(bbp_get_reply_id())) { ?> <header class="bbp-reply-header"> <div> <hgroup class="bbp-reply-meta"> <ul> <li class="bbp-reply-author"> <?php do_action('bbp_theme_before_reply_author_details'); ?> <?php bbp_reply_author_link(array('size' => 16, 'show_role' => true)); ?> <?php do_action('bbp_theme_after_reply_author_details'); ?>
function pg_get_author_link() { $user_id2 = wp_get_current_user()->ID; // Parse arguments against default values $r = bbp_parse_args($args, array('post_id' => $post_id, 'link_title' => '', 'type' => 'both', 'size' => 14), 'pg_get_author_link'); //confirmed topic if (bbp_is_topic($post_id)) { $topic = bbp_get_topic_post_type(); $forum_id_check = private_groups_get_forum_id_from_post_id($post_id, $topic); //now we can check if the user can view this if (!private_groups_can_user_view_post($user_id2, $forum_id_check)) { return; } return bbp_get_topic_author_link($r); // Confirmed reply } elseif (bbp_is_reply($post_id)) { $reply = bbp_get_reply_post_type(); $forum_id_check = private_groups_get_forum_id_from_post_id($post_id, $reply); //now we can check if the user can view this if (!private_groups_can_user_view_post($user_id2, $forum_id_check)) { return; } return bbp_get_reply_author_link($r); } // Neither a reply nor a topic, so could be a revision //if it isn't a topic or reply, not sure so better to just not display the author in this case //could be revised to look up the post_parent of this post and then churn that round the code above if required return ; return; }
/<?php echo bp_forums_root_slug(); ?> /" title="<?php _e('Forums', 'framemarket'); ?> "><?php _e('Forums', 'framemarket'); ?> </a> </li> <?php } elseif (function_exists('bbpress')) { ?> <li<?php if (bbp_is_forum($post->ID) || bbp_is_topic($post->ID)) { ?> class="selected"<?php } ?> > <a href="<?php bbp_forums_url(); ?> "><?php _e('Forums', 'framemarket'); ?> </a> </li> <?php }
/** * Output custom bbPress admin links * @version 2.0 */ function apoc_reply_admin_links($reply_id) { // Make sure it's a logged-in user if (!is_user_logged_in()) { return false; } // Get post id and setup desired links $links = array(); // Add common quote and reply links except on forum profiles if (!bp_is_forums_component()) { $links['quote'] = apoc_quote_button('reply', $reply_id); $links['reply'] = '<a class="scroll-respond button button-dark" href="#new-post" title="Quick Reply"><i class="fa fa-reply"></i>Reply</a>'; } // Topic admin links if (bbp_is_topic($reply_id)) { $links['edit'] = bbp_get_topic_edit_link(array('id' => $reply_id, 'edit_text' => '<i class="fa fa-pencil"></i>Edit')); $links['close'] = bbp_get_topic_close_link(array('id' => $reply_id, 'close_text' => '<i class="fa fa-lock"></i>Close', 'open_text' => '<i class="fa fa-unlock"></i>Open')); $links['stick'] = bbp_get_topic_stick_link(array('id' => $reply_id, 'stick_text' => '<i class="fa fa-thumb-tack"></i>Stick', 'unstick_text' => '<i class="fa fa-level-down"></i>Unstick', 'super_text' => '<i class="fa fa-paperclip"></i>Notice')); $links['merge'] = bbp_get_topic_merge_link(array('merge_text' => '<i class="fa fa-code-fork"></i>Merge')); $links['trash'] = bbp_get_topic_trash_link(array('id' => $reply_id, 'trash_text' => '<i class="fa fa-trash"></i>Trash', 'restore_text' => '<i class="fa fa-undo"></i>Restore', 'delete_text' => '<i class="fa fa-remove"></i>Delete', 'sep' => '')); // Reply admin links } else { $links['edit'] = bbp_get_reply_edit_link(array('id' => $reply_id, 'edit_text' => '<i class="fa fa-pencil"></i>Edit')); $links['move'] = bbp_get_reply_move_link(array('id' => $reply_id, 'split_text' => '<i class="fa fa-arrows"></i>Move')); $links['split'] = bbp_get_topic_split_link(array('id' => $reply_id, 'split_text' => '<i class="fa fa-code-fork"></i>Split')); $links['trash'] = bbp_get_reply_trash_link(array('id' => $reply_id, 'trash_text' => '<i class="fa fa-trash"></i>Trash', 'restore_text' => '<i class="fa fa-undo"></i>Restore', 'delete_text' => '<i class="fa fa-remove"></i>Delete', 'sep' => '')); } // Get the admin links! bbp_reply_admin_links(array('id' => $reply_id, 'before' => '', 'after' => '', 'sep' => '', 'links' => $links)); }
/** * Returns link to the most recent activity inside a forum. * * Returns a complete link with attributes and content. * * @since bbPress (r2625) * * @param int $forum_id Optional. Forum id * @uses bbp_get_forum_id() To get the forum id * @uses bbp_get_forum_last_active_id() To get the forum last active id * @uses bbp_get_forum_last_reply_id() To get the forum last reply id * @uses bbp_get_forum_last_topic_id() To get the forum last topic id * @uses bbp_get_forum_last_reply_url() To get the forum last reply url * @uses bbp_get_forum_last_reply_title() To get the forum last reply * title * @uses bbp_get_forum_last_topic_permalink() To get the forum last * topic permalink * @uses bbp_get_forum_last_topic_title() To get the forum last topic * title * @uses bbp_get_forum_last_active_time() To get the time when the forum * was last active * @uses apply_filters() Calls 'bbp_get_forum_freshness_link' with the * link and forum id */ function bbp_get_forum_freshness_link($forum_id = 0) { $forum_id = bbp_get_forum_id($forum_id); $active_id = bbp_get_forum_last_active_id($forum_id); if (empty($active_id)) { $active_id = bbp_get_forum_last_reply_id($forum_id); } if (empty($active_id)) { $active_id = bbp_get_forum_last_topic_id($forum_id); } if (bbp_is_topic($active_id)) { $link_url = bbp_get_forum_last_topic_permalink($forum_id); $title = bbp_get_forum_last_topic_title($forum_id); } elseif (bbp_is_reply($active_id)) { $link_url = bbp_get_forum_last_reply_url($forum_id); $title = bbp_get_forum_last_reply_title($forum_id); } $time_since = bbp_get_forum_last_active_time($forum_id); if (!empty($time_since) && !empty($link_url)) { $anchor = '<a href="' . $link_url . '" title="' . esc_attr($title) . '">' . $time_since . '</a>'; } else { $anchor = __('No Topics', 'bbpress'); } return apply_filters('bbp_get_forum_freshness_link', $anchor, $forum_id); }
/** * Display the contents of a specific topic 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_topic($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 $forum_id for clarity $topic_id = bbpress()->current_topic_id = $attr['id']; $forum_id = bbp_get_topic_forum_id($topic_id); // Bail if ID passed is not a topic if (!bbp_is_topic($topic_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 topics 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 topic_query attributes for topics loop to function $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type(); $bbp->topic_query->in_the_loop = true; $bbp->topic_query->post = get_post($topic_id); } // Start output buffer $this->start('bbp_single_topic'); // Check forum caps if (bbp_user_can_view_forum(array('forum_id' => $forum_id))) { bbp_get_template_part('content', 'single-topic'); // 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(); }
public function delete_post($id) { if (d4p_has_bbpress()) { if (bbp_is_reply($id) || bbp_is_topic($id)) { if ($this->o['delete_attachments'] == 'delete') { $files = d4p_get_post_attachments($id); if (is_array($files) && !empty($files)) { foreach ($files as $file) { wp_delete_attachment($file->ID); } } } else { if ($this->o['delete_attachments'] == 'detach') { global $wpdb; $wpdb->update($wpdb->posts, array('post_parent' => 0), array('post_parent' => $id, 'post_type' => 'attachment')); } } } } }
/** * Return the author link of the post * * @since bbPress (r2875) * * @param mixed $args Optional. If an integer, it is used as reply id. * @uses bbp_is_topic() To check if it's a topic page * @uses bbp_get_topic_author_link() To get the topic author link * @uses bbp_is_reply() To check if it's a reply page * @uses bbp_get_reply_author_link() To get the reply author link * @uses get_post_field() To get the post author * @uses bbp_is_reply_anonymous() To check if the reply is by an * anonymous user * @uses get_the_author_meta() To get the author name * @uses bbp_get_user_profile_url() To get the author profile url * @uses get_avatar() To get the author avatar * @uses apply_filters() Calls 'bbp_get_reply_author_link' with the * author link and args * @return string Author link of reply */ function bbp_get_author_link($args = '') { // Default arguments $defaults = array('post_id' => 0, 'link_title' => '', 'type' => 'both', 'size' => 80); $r = bbp_parse_args($args, $defaults, 'get_author_link'); extract($r); // Used as reply_id if (is_numeric($args)) { $post_id = $args; } // Confirmed topic if (bbp_is_topic($post_id)) { return bbp_get_topic_author_link($args); } elseif (bbp_is_reply($post_id)) { return bbp_get_reply_author_link($args); } else { $user_id = get_post_field('post_author', $post_id); } // Neither a reply nor a topic, so could be a revision if (!empty($post_id)) { // Generate title with the display name of the author if (empty($link_title)) { $link_title = sprintf(!bbp_is_reply_anonymous($post_id) ? __('View %s\'s profile', 'bbpress') : __('Visit %s\'s website', 'bbpress'), get_the_author_meta('display_name', $user_id)); } // Assemble some link bits $link_title = !empty($link_title) ? ' title="' . $link_title . '"' : ''; $author_url = bbp_get_user_profile_url($user_id); $anonymous = bbp_is_reply_anonymous($post_id); // Get avatar if ('avatar' == $type || 'both' == $type) { $author_links[] = get_avatar($user_id, $size); } // Get display name if ('name' == $type || 'both' == $type) { $author_links[] = get_the_author_meta('display_name', $user_id); } // Add links if not anonymous if (empty($anonymous)) { foreach ($author_links as $link_text) { $author_link[] = sprintf('<a href="%1$s"%2$s>%3$s</a>', $author_url, $link_title, $link_text); } $author_link = join(' ', $author_link); // No links if anonymous } else { $author_link = join(' ', $author_links); } // No post so link is empty } else { $author_link = ''; } return apply_filters('bbp_get_author_link', $author_link, $args); }
/** * Adjust the total hidden topic count of a forum (hidden includes trashed and spammed topics) * * @since bbPress (r2888) * * @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 wpdb::prepare() To prepare our sql query * @uses wpdb::get_col() To execute our query and get the column back * @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) { global $wpdb; // 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)) { $post_status = "'" . implode("','", array(bbp_get_trash_status_id(), bbp_get_spam_status_id())) . "'"; $topic_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';", $forum_id, bbp_get_topic_post_type())); } // Update the count update_post_meta($forum_id, '_bbp_topic_count_hidden', (int) $topic_count); } return (int) apply_filters('bbp_update_forum_topic_count_hidden', (int) $topic_count, $forum_id); }
/** * Custom function from bbp_get_author_link(), returns only author name * -------------------------------------------------------------------------------------------*/ function aq_get_author($post_id = 0) { // Confirmed topic if (bbp_is_topic($post_id)) { return bbp_get_topic_author($post_id); // Confirmed reply } elseif (bbp_is_reply($post_id)) { return bbp_get_reply_author($post_id); // Get the post author and proceed } else { $user_id = get_post_field('post_author', $post_id); } // Neither a reply nor a topic, so could be a revision if (!empty($post_id)) { // Assemble some link bits $anonymous = bbp_is_reply_anonymous($post_id); // Add links if not anonymous if (empty($anonymous) && bbp_user_has_profile($user_id)) { $author_link = get_the_author_meta('display_name', $user_id); // No links if anonymous } else { $author_link = join(' ', $author_links); } // No post so link is empty } else { $author_link = ''; } return $author_link; }
/** * Return the topic id * * @since 2.0.0 bbPress (r2485) * * @param $topic_id Optional. Used to check emptiness * @uses bbPress::topic_query::post::ID To get the topic id * @uses bbp_is_topic() To check if the search result is a topic * @uses bbp_is_single_topic() To check if it's a topic page * @uses bbp_is_topic_edit() To check if it's a topic edit page * @uses bbp_is_single_reply() To check if it it's a reply page * @uses bbp_is_reply_edit() To check if it's a reply edit page * @uses bbp_get_reply_topic_edit() To get the reply topic id * @uses get_post_field() To get the post's post type * @uses WP_Query::post::ID To get the topic id * @uses bbp_get_topic_post_type() To get the topic post type * @uses apply_filters() Calls 'bbp_get_topic_id' with the topic id and * supplied topic id * @return int The topic id */ function bbp_get_topic_id($topic_id = 0) { global $wp_query; $bbp = bbpress(); // Easy empty checking if (!empty($topic_id) && is_numeric($topic_id)) { $bbp_topic_id = $topic_id; // Currently inside a topic loop } elseif (!empty($bbp->topic_query->in_the_loop) && isset($bbp->topic_query->post->ID)) { $bbp_topic_id = $bbp->topic_query->post->ID; // Currently inside a search loop } elseif (!empty($bbp->search_query->in_the_loop) && isset($bbp->search_query->post->ID) && bbp_is_topic($bbp->search_query->post->ID)) { $bbp_topic_id = $bbp->search_query->post->ID; // Currently viewing/editing a topic, likely alone } elseif ((bbp_is_single_topic() || bbp_is_topic_edit()) && !empty($bbp->current_topic_id)) { $bbp_topic_id = $bbp->current_topic_id; // Currently viewing/editing a topic, likely in a loop } elseif ((bbp_is_single_topic() || bbp_is_topic_edit()) && isset($wp_query->post->ID)) { $bbp_topic_id = $wp_query->post->ID; // Currently viewing/editing a reply } elseif (bbp_is_single_reply() || bbp_is_reply_edit()) { $bbp_topic_id = bbp_get_reply_topic_id(); // Fallback } else { $bbp_topic_id = 0; } return (int) apply_filters('bbp_get_topic_id', (int) $bbp_topic_id, $topic_id); }
function firmasite_social_bbp_get_forum_freshness_link($forum_id = 0) { $forum_id = bbp_get_forum_id($forum_id); $active_id = bbp_get_forum_last_active_id($forum_id); if (empty($active_id)) { $active_id = bbp_get_forum_last_reply_id($forum_id); } if (empty($active_id)) { $active_id = bbp_get_forum_last_topic_id($forum_id); } if (bbp_is_topic($active_id)) { $link_url = bbp_get_forum_last_topic_permalink($forum_id); $title = bbp_get_forum_last_topic_title($forum_id); } elseif (bbp_is_reply($active_id)) { $link_url = bbp_get_forum_last_reply_url($forum_id); $title = bbp_get_forum_last_reply_title($forum_id); } $time_since = bbp_get_forum_last_active_time($forum_id); if (!empty($time_since) && !empty($link_url)) { $anchor = '<a href="' . $link_url . '" data-toggle="popover" data-rel="popover" data-placement="left" data-trigger="hover" data-html="true" data-original-title="' . __('Freshness', 'firmasite') . '" data-content="' . esc_attr($time_since) . '"><i class="icon-time"></i></a> ' . __('Freshness', 'firmasite') . ':'; } else { $anchor = __('No Topics', 'firmasite'); } return apply_filters('bbp_get_forum_freshness_link', $anchor, $forum_id); }