function td_bbp_change_avatar_size($author_avatar, $topic_id, $size) { $author_avatar = ''; if ($size == 14) { $size = 40; } $topic_id = bbp_get_topic_id($topic_id); if (!empty($topic_id)) { if (!bbp_is_topic_anonymous($topic_id)) { $author_avatar = get_avatar(bbp_get_topic_author_id($topic_id), $size); } else { $author_avatar = get_avatar(get_post_meta($topic_id, '_bbp_anonymous_email', true), $size); } } return $author_avatar; }
/** * @covers ::bbp_topic_author_id * @covers ::bbp_get_topic_author_id */ public function test_bbp_get_topic_author_id() { $u = $this->factory->user->create(); $t = $this->factory->topic->create(array('post_author' => $u)); $topic = bbp_get_topic_author_id($t); $this->assertSame($u, $topic); }
function bbps_voting_is_admin() { global $current_user; $current_user = wp_get_current_user(); $user_id = $current_user->ID; $topic_author_id = bbp_get_topic_author_id(); $permissions = get_option('_bbps_status_permissions'); $can_edit = ""; //check the users permission this is easy if ($permissions['admin'] == 1 && current_user_can('administrator') || $permissions['mod'] == 1 && current_user_can('bbp_moderator')) { $can_edit = true; } return $can_edit; }
/** * New Reply * @since 0.1 * @version 1.5 */ public function new_reply($reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author) { // Check if user is excluded if ($this->core->exclude_user($reply_author)) { return; } // Check if topic author gets points for their own replies if ((bool) $this->prefs['new_reply']['author'] === false && bbp_get_topic_author_id($topic_id) == $reply_author) { return; } // Limit if ($this->over_hook_limit('new_reply', 'new_forum_reply', $reply_author)) { return; } // Make sure this is unique event if ($this->has_entry('new_forum_reply', $reply_id, $reply_author)) { return; } // Execute $this->core->add_creds('new_forum_reply', $reply_author, $this->prefs['new_reply']['creds'], $this->prefs['new_reply']['log'], $reply_id, array('ref_type' => 'post'), $this->mycred_type); }
/** * Sends the new reply notification email to moderators on private replies * * @since 1.2 * * @param $message string The email message * @param $reply_id int The ID of the reply * @param $topic_id int The ID of the reply's topic * * @return void */ public function subscription_email($message, $reply_id, $topic_id) { if (!$this->is_private($reply_id)) { return false; // reply isn't private so do nothing } $topic_author = bbp_get_topic_author_id($topic_id); $reply_author = bbp_get_reply_author_id($reply_id); $reply_author_name = bbp_get_reply_author_display_name($reply_id); // Strip tags from text and setup mail data $topic_title = strip_tags(bbp_get_topic_title($topic_id)); $reply_content = strip_tags(bbp_get_reply_content($reply_id)); $reply_url = bbp_get_reply_url($reply_id); $blog_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $do_not_reply = '<noreply@' . ltrim(get_home_url(), '^(http|https)://') . '>'; $subject = apply_filters('bbp_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $reply_id, $topic_id); // Array to hold BCC's $headers = array(); // Setup the From header $headers[] = 'From: ' . get_bloginfo('name') . ' ' . $do_not_reply; // Get topic subscribers and bail if empty $user_ids = bbp_get_topic_subscribers($topic_id, true); if (empty($user_ids)) { return false; } // Loop through users foreach ((array) $user_ids as $user_id) { // Don't send notifications to the person who made the post if (!empty($reply_author) && (int) $user_id === (int) $reply_author) { continue; } if (user_can($user_id, 'moderate') || (int) $topic_author === (int) $user_id) { // Get email address of subscribed user $headers[] = 'Bcc: ' . get_userdata($user_id)->user_email; } } wp_mail($do_not_reply, $subject, $message, $headers); }
/** * Pass the topic attributes for processing * * @since 2.0.0 bbPress (r2746) * * @param int $topic_id Topic id * @uses current_user_can() To check if the current user is capable of * editing the topic * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the * topic id and parent id * @return int Parent id */ public function attributes_metabox_save($topic_id) { if ($this->bail()) { return $topic_id; } // Bail if doing an autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $topic_id; } // Bail if not a post request if (!bbp_is_post_request()) { return $topic_id; } // Nonce check if (empty($_POST['bbp_topic_metabox']) || !wp_verify_nonce($_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save')) { return $topic_id; } // Bail if current user cannot edit this topic if (!current_user_can('edit_topic', $topic_id)) { return $topic_id; } // Get the forum ID $forum_id = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0; // Get topic author data $anonymous_data = bbp_filter_anonymous_post_data(); $author_id = bbp_get_topic_author_id($topic_id); $is_edit = isset($_POST['hidden_post_status']) && $_POST['hidden_post_status'] !== 'draft'; // Formally update the topic bbp_update_topic($topic_id, $forum_id, $anonymous_data, $author_id, $is_edit); // Stickies if (!empty($_POST['bbp_stick_topic']) && in_array($_POST['bbp_stick_topic'], array('stick', 'super', 'unstick'))) { // What's the haps? switch ($_POST['bbp_stick_topic']) { // Sticky in this forum case 'stick': bbp_stick_topic($topic_id); break; // Super sticky in all forums // Super sticky in all forums case 'super': bbp_stick_topic($topic_id, true); break; // Normal // Normal case 'unstick': default: bbp_unstick_topic($topic_id); break; } } // Allow other fun things to happen do_action('bbp_topic_attributes_metabox_save', $topic_id, $forum_id); do_action('bbp_author_metabox_save', $topic_id, $anonymous_data); return $topic_id; }
/** * Pass the topic attributes for processing * * @since 2.0.0 bbPress (r2746) * * @param int $topic_id Topic id * @uses current_user_can() To check if the current user is capable of * editing the topic * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the * topic id and parent id * @return int Parent id */ public function save_meta_boxes($topic_id) { if ($this->bail()) { return $topic_id; } // Bail if doing an autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $topic_id; } // Bail if not a post request if (!bbp_is_post_request()) { return $topic_id; } // Nonce check if (empty($_POST['bbp_topic_metabox']) || !wp_verify_nonce($_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save')) { return $topic_id; } // Bail if current user cannot edit this topic if (!current_user_can('edit_topic', $topic_id)) { return $topic_id; } // Get the forum ID $forum_id = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0; // Get topic author data $anonymous_data = bbp_filter_anonymous_post_data(); $author_id = bbp_get_topic_author_id($topic_id); $is_edit = isset($_POST['hidden_post_status']) && $_POST['hidden_post_status'] !== 'draft'; // Formally update the topic bbp_update_topic($topic_id, $forum_id, $anonymous_data, $author_id, $is_edit); // Allow other fun things to happen do_action('bbp_topic_attributes_metabox_save', $topic_id, $forum_id); do_action('bbp_author_metabox_save', $topic_id, $anonymous_data); return $topic_id; }
/** * Return the row class of a topic * * @since 2.0.0 bbPress (r2667) * * @param int $topic_id Optional. Topic id * @param array Extra classes you can pass when calling this function * @uses bbp_is_topic_sticky() To check if the topic is a sticky * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky * @uses bbp_get_topic_forum_id() To get the topic forum id * @uses get_post_class() To get the topic classes * @uses apply_filters() Calls 'bbp_get_topic_class' with the classes * and topic id * @return string Row class of a topic */ function bbp_get_topic_class($topic_id = 0, $classes = array()) { $bbp = bbpress(); $topic_id = bbp_get_topic_id($topic_id); $count = isset($bbp->topic_query->current_post) ? $bbp->topic_query->current_post : 1; $classes = (array) $classes; $classes[] = (int) $count % 2 ? 'even' : 'odd'; $classes[] = bbp_is_topic_sticky($topic_id, false) ? 'sticky' : ''; $classes[] = bbp_is_topic_super_sticky($topic_id) ? 'super-sticky' : ''; $classes[] = 'bbp-parent-forum-' . bbp_get_topic_forum_id($topic_id); $classes[] = 'user-id-' . bbp_get_topic_author_id($topic_id); $classes = array_filter($classes); $classes = get_post_class($classes, $topic_id); $classes = apply_filters('bbp_get_topic_class', $classes, $topic_id); $retval = 'class="' . implode(' ', $classes) . '"'; return $retval; }
/** * Reset main query vars and filter 'the_content' to output a bbPress * template part as needed. * * @since 2.0.0 bbPress (r3032) * * @param string $template * @uses bbp_is_single_user() To check if page is single user * @uses bbp_get_single_user_template() To get user template * @uses bbp_is_single_user_edit() To check if page is single user edit * @uses bbp_get_single_user_edit_template() To get user edit template * @uses bbp_is_single_view() To check if page is single view * @uses bbp_get_single_view_template() To get view template * @uses bbp_is_search() To check if page is search * @uses bbp_get_search_template() To get search template * @uses bbp_is_forum_edit() To check if page is forum edit * @uses bbp_get_forum_edit_template() To get forum edit template * @uses bbp_is_topic_merge() To check if page is topic merge * @uses bbp_get_topic_merge_template() To get topic merge template * @uses bbp_is_topic_split() To check if page is topic split * @uses bbp_get_topic_split_template() To get topic split template * @uses bbp_is_topic_edit() To check if page is topic edit * @uses bbp_get_topic_edit_template() To get topic edit template * @uses bbp_is_reply_move() To check if page is reply move * @uses bbp_get_reply_move_template() To get reply move template * @uses bbp_is_reply_edit() To check if page is reply edit * @uses bbp_get_reply_edit_template() To get reply edit template * @uses bbp_set_theme_compat_template() To set the global theme compat template */ function bbp_template_include_theme_compat($template = '') { /** * Bail if a root template was already found. This prevents unintended * recursive filtering of 'the_content'. * * @link https://bbpress.trac.wordpress.org/ticket/2429 */ if (bbp_is_template_included()) { return $template; } /** * If BuddyPress is activated at a network level, the action order is * reversed, which causes the template integration to fail. If we're looking * at a BuddyPress page here, bail to prevent the extra processing. * * This is a bit more brute-force than is probably necessary, but gets the * job done while we work towards something more elegant. */ if (function_exists('is_buddypress') && is_buddypress()) { return $template; } // Define local variable(s) $bbp_shortcodes = bbpress()->shortcodes; // Bail if shortcodes are unset somehow if (!is_a($bbp_shortcodes, 'BBP_Shortcodes')) { return $template; } /** Users *************************************************************/ if (bbp_is_single_user_edit() || bbp_is_single_user()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => bbp_buffer_template_part('content', 'single-user', false), 'post_type' => '', 'post_title' => bbp_get_displayed_user_field('display_name'), 'post_status' => bbp_get_public_status_id(), 'is_single' => true, 'is_archive' => false, 'comment_status' => 'closed')); /** Forums ************************************************************/ // Forum archive } elseif (bbp_is_forum_archive()) { // Page exists where this archive should be $page = bbp_get_page_by_path(bbp_get_root_slug()); // Should we replace the content... if (empty($page->post_content)) { // Use the topics archive if ('topics' === bbp_show_on_root()) { $new_content = $bbp_shortcodes->display_topic_index(); // No page so show the archive } else { $new_content = $bbp_shortcodes->display_forum_index(); } // ...or use the existing page content? } else { $new_content = apply_filters('the_content', $page->post_content); } // Should we replace the title... if (empty($page->post_title)) { // Use the topics archive if ('topics' === bbp_show_on_root()) { $new_title = bbp_get_topic_archive_title(); // No page so show the archive } else { $new_title = bbp_get_forum_archive_title(); } // ...or use the existing page title? } else { $new_title = apply_filters('the_title', $page->post_title); } // Reset post bbp_theme_compat_reset_post(array('ID' => !empty($page->ID) ? $page->ID : 0, 'post_title' => $new_title, 'post_author' => 0, 'post_date' => 0, 'post_content' => $new_content, 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed')); // Single Forum } elseif (bbp_is_forum_edit()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_forum_id(), 'post_title' => bbp_get_forum_title(), 'post_author' => bbp_get_forum_author_id(), 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_forum_form(), 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_forum_visibility(), 'is_single' => true, 'comment_status' => 'closed')); } elseif (bbp_is_single_forum()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_forum_id(), 'post_title' => bbp_get_forum_title(), 'post_author' => bbp_get_forum_author_id(), 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_forum(array('id' => bbp_get_forum_id())), 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_forum_visibility(), 'is_single' => true, 'comment_status' => 'closed')); /** Topics ************************************************************/ // Topic archive } elseif (bbp_is_topic_archive()) { // Page exists where this archive should be $page = bbp_get_page_by_path(bbp_get_topic_archive_slug()); // Should we replace the content... if (empty($page->post_content)) { $new_content = $bbp_shortcodes->display_topic_index(); // ...or use the existing page content? } else { $new_content = apply_filters('the_content', $page->post_content); } // Should we replace the title... if (empty($page->post_title)) { $new_title = bbp_get_topic_archive_title(); // ...or use the existing page title? } else { $new_title = apply_filters('the_title', $page->post_title); } // Reset post bbp_theme_compat_reset_post(array('ID' => !empty($page->ID) ? $page->ID : 0, 'post_title' => bbp_get_topic_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => $new_content, 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed')); // Single Topic } elseif (bbp_is_topic_edit() || bbp_is_single_topic()) { // Split if (bbp_is_topic_split()) { $new_content = bbp_buffer_template_part('form', 'topic-split', false); // Merge } elseif (bbp_is_topic_merge()) { $new_content = bbp_buffer_template_part('form', 'topic-merge', false); // Edit } elseif (bbp_is_topic_edit()) { $new_content = $bbp_shortcodes->display_topic_form(); // Single } else { $new_content = $bbp_shortcodes->display_topic(array('id' => bbp_get_topic_id())); } // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_topic_id(), 'post_title' => bbp_get_topic_title(), 'post_author' => bbp_get_topic_author_id(), 'post_date' => 0, 'post_content' => $new_content, 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_topic_status(), 'is_single' => true, 'comment_status' => 'closed')); /** Replies ***********************************************************/ // Reply archive } elseif (is_post_type_archive(bbp_get_reply_post_type())) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => __('Replies', 'bbpress'), 'post_author' => 0, 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_reply_index(), 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); // Single Reply } elseif (bbp_is_reply_edit() || bbp_is_single_reply()) { // Move if (bbp_is_reply_move()) { $new_content = bbp_buffer_template_part('form', 'reply-move', false); // Edit } elseif (bbp_is_reply_edit()) { $new_content = $bbp_shortcodes->display_reply_form(); // Single } else { $new_content = $bbp_shortcodes->display_reply(array('id' => get_the_ID())); } // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_reply_id(), 'post_title' => bbp_get_reply_title(), 'post_author' => bbp_get_reply_author_id(), 'post_date' => 0, 'post_content' => $new_content, 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_reply_status(), 'comment_status' => 'closed')); /** Views *************************************************************/ } elseif (bbp_is_single_view()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_view_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_view(array('id' => get_query_var(bbp_get_view_rewrite_id()))), 'post_type' => '', 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); /** Search ************************************************************/ } elseif (bbp_is_search()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_search_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_search(array('search' => get_query_var(bbp_get_search_rewrite_id()))), 'post_type' => '', 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); /** Topic Tags ********************************************************/ // Topic Tag Edit } elseif (bbp_is_topic_tag_edit() || bbp_is_topic_tag()) { // Stash the current term in a new var set_query_var('bbp_topic_tag', get_query_var('term')); // Show topics of tag if (bbp_is_topic_tag()) { $new_content = $bbp_shortcodes->display_topics_of_tag(array('id' => bbp_get_topic_tag_id())); // Edit topic tag } elseif (bbp_is_topic_tag_edit()) { $new_content = $bbp_shortcodes->display_topic_tag_form(); } // Reset the post with our new title bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => $new_content, 'post_type' => '', 'post_title' => sprintf(__('Topic Tag: %s', 'bbpress'), '<span>' . bbp_get_topic_tag_name() . '</span>'), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed', 'is_tax' => true)); } /** * Bail if the template already matches a bbPress template. This includes * archive-* and single-* WordPress post_type matches (allowing * themes to use the expected format) as well as all bbPress-specific * template files for users, topics, forums, etc... * * We do this after the above checks to prevent incorrect 404 body classes * and header statuses, as well as to set the post global as needed. * * @see https://bbpress.trac.wordpress.org/ticket/1478/ */ if (bbp_is_template_included()) { return $template; /** * If we are relying on bbPress's built in theme compatibility to load * the proper content, we need to intercept the_content, replace the * output, and display ours instead. * * To do this, we first remove all filters from 'the_content' and hook * our own function into it, which runs a series of checks to determine * the context, and then uses the built in shortcodes to output the * correct results from inside an output buffer. * * Uses bbp_get_theme_compat_templates() to provide fall-backs that * should be coded without superfluous mark-up and logic (prev/next * navigation, comments, date/time, etc...) * * Hook into the 'bbp_get_bbpress_template' to override the array of * possible templates, or 'bbp_bbpress_template' to override the result. */ } elseif (bbp_is_theme_compat_active()) { bbp_remove_all_filters('the_content'); $template = bbp_get_theme_compat_templates(); } return apply_filters('bbp_template_include_theme_compat', $template); }
function bbps_modify_title($title, $topic_id = 0) { $topic_id = bbp_get_topic_id($topic_id); $title = ""; $topic_author_id = bbp_get_topic_author_id(); global $current_user; get_currentuserinfo(); $user_id = $current_user->ID; $claimed_user_id = get_post_meta($topic_id, '_bbps_topic_claimed', true); if ($claimed_user_id > 0) { $user_info = get_userdata($claimed_user_id); $claimed_user_name = $user_info->user_login; } //2 is the resolved status ID if (get_post_meta($topic_id, '_bbps_topic_status', true) == 2) { echo '<span class="resolved"> [Resolved] </span>'; } //we only want to display the urgent topic status to admin and moderators if (get_post_meta($topic_id, '_bbps_urgent_topic', true) == 1 && (current_user_can('administrator') || current_user_can('bbp_moderator'))) { echo '<span class="urgent"> [Urgent] </span>'; } //claimed topics also only get shown to admin and moderators and the person who owns the topic if (get_post_meta($topic_id, '_bbps_topic_claimed', true) > 0 && (current_user_can('administrator') || current_user_can('bbp_moderator') || $topic_author_id == $user_id)) { //if this option == 1 we display the users name not [claimed] if (get_option('_bbps_claim_topic_display') == 1) { echo '<span class="claimed">[' . $claimed_user_name . ']</span>'; } else { echo '<span class="claimed"> [Claimed] </span>'; } } }
function ntwb_bbpress_topic_css_role() { $role = strtolower(bbp_get_user_display_role(bbp_get_topic_author_id($topic_id))); $args['class'] = 'bbp-author-role bbp-author-role-' . $role; $args['before'] = ''; $args['after'] = ''; return $args; }
/** * Prevent users from favoriting their own posts * @version 2.0 */ function no_self_favorite($html, $r, $user_id, $topic_id) { // Prevent a topic author from favoriting him/herself if ($user_id == bbp_get_topic_author_id()) { return false; } else { return $html; } }
<?php if ($postUser->has_cap('bbp_keymaster')) { echo "<small>(Администратор форума)</small>"; } elseif ($postUser->has_cap('bbp_moderator')) { echo "<small>(Преподаватель)</small>"; } ?> </div> <div class="date"><?php echo get_post_time('j F ', false, bbp_get_topic_id(), true) . __('at', 'qode') . get_post_time(' H:i', false, bbp_get_topic_id(), true); ?> </div> </div> <?php if (bbp_get_topic_author_id() == get_current_user_id()) { ?> <a href="#" class="addi_actions_open"></a> <div class="addi_actions" style="display:none"> <ul> <li><a class="edit_action" href="#">Редактировать</a> </li> <li><a class="remove_action" href="#">Удалить</a></li> </ul> </div> <?php } ?> </div> <div class="single_topic_content">
/** * Helper function used to decrease (by one) the count of topics for a user when * a topic is unpublished. * * @since 2.6.0 bbPress (r5309) * * @param $topic_id */ function bbp_decrease_user_topic_count($topic_id = 0) { $user_id = bbp_get_topic_author_id($topic_id); return bbp_bump_user_topic_count($user_id, -1); }
/** * Retrieve the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post. * * @since 2.5.0 * @since 4.2.0 Optional `$args` parameter added. * * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, * user email, WP_User object, WP_Post object, or comment object. * @param int $size Optional. Height and width of the avatar image file in pixels. Default 96. * @param string $default Optional. URL for the default image or a default type. Accepts '404' * (return a 404 instead of a default image), 'retro' (8bit), 'monsterid' * (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"), * 'mystery', 'mm', or 'mysterman' (The Oyster Man), 'blank' (transparent GIF), * or 'gravatar_default' (the Gravatar logo). Default is the value of the * 'avatar_default' option, with a fallback of 'mystery'. * @param string $alt Optional. Alternative text to use in <img> tag. Default empty. * @param array $args { * Optional. Extra arguments to retrieve the avatar. * * @type int $height Display height of the avatar in pixels. Defaults to $size. * @type int $width Display width of the avatar in pixels. Defaults to $size. * @type bool $force_default Whether to always show the default image, never the Gravatar. Default false. * @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are * judged in that order. Default is the value of the 'avatar_rating' option. * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. * Default null. * @type array|string $class Array or string of additional classes to add to the <img> element. * Default null. * @type bool $force_display Whether to always show the avatar - ignores the show_avatars option. * Default false. * @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. Default empty. * } * @return false|string `<img>` tag for the user's avatar. False on failure. */ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args = null) { $defaults = array('size' => 96, 'height' => null, 'width' => null, 'default' => get_option('avatar_default', 'mystery'), 'force_default' => false, 'rating' => get_option('avatar_rating'), 'scheme' => null, 'alt' => '', 'class' => null, 'force_display' => false, 'extra_attr' => ''); if (empty($args)) { $args = array(); } $args['size'] = (int) $size; $args['default'] = $default; $args['alt'] = $alt; $args = wp_parse_args($args, $defaults); if (empty($args['height'])) { $args['height'] = $args['size']; } if (empty($args['width'])) { $args['width'] = $args['size']; } /** * Filter whether to retrieve the avatar URL early. * * Passing a non-null value will effectively short-circuit get_avatar(), passing * the value through the {@see 'pre_get_avatar'} filter and returning early. * * @since 4.2.0 * * @param string $avatar HTML for the user's avatar. Default null. * @param int|object|string $id_or_email A user ID, email address, or comment object. * @param array $args Arguments passed to get_avatar_url(), after processing. */ $avatar = apply_filters('pre_get_avatar', null, $id_or_email, $args); if (!is_null($avatar)) { /** This filter is documented in wp-includes/pluggable.php */ return apply_filters('get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args); } if (!$args['force_display'] && !get_option('show_avatars')) { return false; } $url2x = get_avatar_url($id_or_email, array_merge($args, array('size' => $args['size'] * 2))); $args = get_avatar_data($id_or_email, $args); $url = $args['url']; if (!$url || is_wp_error($url)) { return false; } $class = array('avatar', 'avatar-' . (int) $args['size'], 'photo'); if (!$args['found_avatar'] || $args['force_default']) { $class[] = 'avatar-default'; } if ($args['class']) { if (is_array($args['class'])) { $class = array_merge($class, $args['class']); } else { $class[] = $args['class']; } } // Author : John Robert jerodiaz - Roy ================================================================= $current_user = wp_get_current_user(); $current_id = $current_user->ID; $avtar_image = get_user_meta(bbp_get_topic_author_id(), 'avtar_image'); /*$user_info = get_userdata($current_id); $user_description = $user_info->user_description;*/ $avatar = sprintf("<img alt='%s' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>", esc_attr($args['alt']), esc_url(isset($avtar_image[0]) ? $avtar_image[0] : ''), esc_attr("{$url2x} 2x"), esc_attr(join(' ', $class)), (int) $args['height'], (int) $args['width'], $args['extra_attr']); // End of file by John Robert Jerodiaz ================================================================= /** * Filter the avatar to retrieve. * * @since 2.5.0 * @since 4.2.0 The `$args` parameter was added. * * @param string $avatar <img> tag for the user's avatar. * @param int|object|string $id_or_email A user ID, email address, or comment object. * @param int $size Square avatar width and height in pixels to retrieve. * @param string $alt Alternative text to use in the avatar image tag. * Default empty. * @param array $args Arguments passed to get_avatar_data(), after processing. */ return apply_filters('get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args); }
/** * Return the author ID of the last topic of a forum * * @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_topic_id() To get the forum's last topic id * @uses bbp_get_topic_author_id() To get the topic's author id * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author' with the author * id and forum id * @return int Forum's last topic's author id */ function bbp_get_forum_last_topic_author_id($forum_id = 0) { $forum_id = bbp_get_forum_id($forum_id); $author_id = bbp_get_topic_author_id(bbp_get_forum_last_topic_id($forum_id)); return (int) apply_filters('bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id); }
/** * Reset main query vars and filter 'the_content' to output a bbPress * template part as needed. * * @since bbPress (r3032) * @param string $template * @uses bbp_is_single_user() To check if page is single user * @uses bbp_get_single_user_template() To get user template * @uses bbp_is_single_user_edit() To check if page is single user edit * @uses bbp_get_single_user_edit_template() To get user edit template * @uses bbp_is_single_view() To check if page is single view * @uses bbp_get_single_view_template() To get view template * @uses bbp_is_forum_edit() To check if page is forum edit * @uses bbp_get_forum_edit_template() To get forum edit template * @uses bbp_is_topic_merge() To check if page is topic merge * @uses bbp_get_topic_merge_template() To get topic merge template * @uses bbp_is_topic_split() To check if page is topic split * @uses bbp_get_topic_split_template() To get topic split template * @uses bbp_is_topic_edit() To check if page is topic edit * @uses bbp_get_topic_edit_template() To get topic edit template * @uses bbp_is_reply_edit() To check if page is reply edit * @uses bbp_get_reply_edit_template() To get reply edit template * @uses bbp_set_theme_compat_template() To set the global theme compat template */ function bbp_template_include_theme_compat($template = '') { // Bail if the template already matches a bbPress template. This includes // archive-* and single-* WordPress post_type matches (allowing // themes to use the expected format) as well as all bbPress-specific // template files for users, topics, forums, etc... if (!empty(bbpress()->theme_compat->bbpress_template)) { return $template; } /** Users *************************************************************/ if (bbp_is_single_user_edit() || bbp_is_single_user()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_title' => esc_attr(bbp_get_displayed_user_field('display_name')), 'post_status' => bbp_get_public_status_id(), 'is_archive' => false, 'comment_status' => 'closed')); /** Forums ************************************************************/ // Forum archive } elseif (bbp_is_forum_archive()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_forum_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed')); // Single Forum } elseif (bbp_is_forum_edit() || bbp_is_single_forum()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_forum_id(), 'post_title' => bbp_get_forum_title(), 'post_author' => bbp_get_forum_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_forum_id()), 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_forum_visibility(), 'is_single' => true, 'comment_status' => 'closed')); /** Topics ************************************************************/ // Topic archive } elseif (bbp_is_topic_archive()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_topic_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed')); // Single Topic } elseif (bbp_is_topic_edit() || bbp_is_single_topic()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_topic_id(), 'post_title' => bbp_get_topic_title(), 'post_author' => bbp_get_topic_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_topic_id()), 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_topic_status(), 'is_single' => true, 'comment_status' => 'closed')); /** Replies ***********************************************************/ // Reply archive } elseif (is_post_type_archive(bbp_get_reply_post_type())) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => __('Replies', 'bbpress'), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); // Single Reply } elseif (bbp_is_reply_edit() || bbp_is_single_reply()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_reply_id(), 'post_title' => bbp_get_reply_title(), 'post_author' => bbp_get_reply_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_reply_id()), 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_reply_status(), 'comment_status' => 'closed')); /** Views *************************************************************/ } elseif (bbp_is_single_view()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_view_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); /** Topic Tags ********************************************************/ // Topic Tag Edit } elseif (bbp_is_topic_tag_edit() || bbp_is_topic_tag()) { // Stash the current term in a new var set_query_var('bbp_topic_tag', get_query_var('term')); // Reset the post with our new title bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_title' => sprintf(__('Topic Tag: %s', 'bbpress'), '<span>' . bbp_get_topic_tag_name() . '</span>'), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); } /** * If we are relying on bbPress's built in theme compatibility to load * the proper content, we need to intercept the_content, replace the * output, and display ours instead. * * To do this, we first remove all filters from 'the_content' and hook * our own function into it, which runs a series of checks to determine * the context, and then uses the built in shortcodes to output the * correct results from inside an output buffer. * * Uses bbp_get_theme_compat_templates() to provide fall-backs that * should be coded without superfluous mark-up and logic (prev/next * navigation, comments, date/time, etc...) * * Hook into the 'bbp_get_bbpress_template' to override the array of * possible templates, or 'bbp_bbpress_template' to override the result. */ if (bbp_is_theme_compat_active()) { // Remove all filters from the_content bbp_remove_all_filters('the_content'); // Add a filter on the_content late, which we will later remove add_filter('the_content', 'bbp_replace_the_content'); // Find the appropriate template file $template = bbp_get_theme_compat_templates(); } return apply_filters('bbp_template_include_theme_compat', $template); }
/** * Update the activity stream entry when a topic status changes * * @param int $post_id * @param obj $post * @uses get_post_type() * @uses bbp_get_topic_post_type() * @uses bbp_get_topic_id() * @uses bbp_is_topic_anonymous() * @uses bbp_get_public_status_id() * @uses bbp_get_closed_status_id() * @uses bbp_get_topic_forum_id() * @uses bbp_get_topic_author_id() * @return Bail early if not a topic, or topic is by anonymous user */ public function topic_update($topic_id, $post) { // Bail early if not a topic if (get_post_type($post) != bbp_get_topic_post_type()) { return; } $topic_id = bbp_get_topic_id($topic_id); // Bail early if topic is by anonymous user if (bbp_is_topic_anonymous($topic_id)) { return; } $anonymous_data = array(); // Action based on new status if (in_array($post->post_status, array(bbp_get_public_status_id(), bbp_get_closed_status_id()))) { // Validate topic data $forum_id = bbp_get_topic_forum_id($topic_id); $topic_author_id = bbp_get_topic_author_id($topic_id); $this->topic_create($topic_id, $forum_id, $anonymous_data, $topic_author_id); } else { $this->topic_delete($topic_id); } }
/** * Return the row class of a reply * * @since bbPress (r2678) * * @param int $reply_id Optional. Reply ID * @param array Extra classes you can pass when calling this function * @uses bbp_get_reply_id() To validate the reply id * @uses bbp_get_reply_forum_id() To get the reply's forum id * @uses bbp_get_reply_topic_id() To get the reply's topic id * @uses get_post_class() To get all the classes including ours * @uses apply_filters() Calls 'bbp_get_reply_class' with the classes * @return string Row class of the reply */ function bbp_get_reply_class($reply_id = 0, $classes = array()) { $bbp = bbpress(); $reply_id = bbp_get_reply_id($reply_id); $count = isset($bbp->reply_query->current_post) ? $bbp->reply_query->current_post : 1; $classes = (array) $classes; $classes[] = (int) $count % 2 ? 'even' : 'odd'; $classes[] = 'bbp-parent-forum-' . bbp_get_reply_forum_id($reply_id); $classes[] = 'bbp-parent-topic-' . bbp_get_reply_topic_id($reply_id); $classes[] = 'bbp-reply-position-' . bbp_get_reply_position($reply_id); $classes[] = 'user-id-' . bbp_get_reply_author_id($reply_id); $classes[] = bbp_get_reply_author_id($reply_id) === bbp_get_topic_author_id(bbp_get_reply_topic_id($reply_id)) ? 'topic-author' : ''; $classes = array_filter($classes); $classes = get_post_class($classes, $reply_id); $classes = apply_filters('bbp_get_reply_class', $classes, $reply_id); $retval = 'class="' . implode(' ', $classes) . '"'; return $retval; }
/** * Hooked into the new reply function, this notification action is responsible * for notifying topic and hierarchical reply authors of topic replies. * * @since 2.5.0 bbPress (r5156) * * @param int $reply_id * @param int $topic_id * @param int $forum_id (not used) * @param array $anonymous_data (not used) * @param int $author_id * @param bool $is_edit Used to bail if this gets hooked to an edit action * @param int $reply_to */ function bbp_buddypress_add_notification($reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0) { // Bail if somehow this is hooked to an edit action if (!empty($is_edit)) { return; } // Get autohr information $topic_author_id = bbp_get_topic_author_id($topic_id); $secondary_item_id = $author_id; // Hierarchical replies if (!empty($reply_to)) { $reply_to_item_id = bbp_get_topic_author_id($reply_to); } // Get some reply information $args = array('user_id' => $topic_author_id, 'item_id' => $topic_id, 'component_name' => bbp_get_component_name(), 'component_action' => 'bbp_new_reply', 'date_notified' => get_post($reply_id)->post_date); // Notify the topic author if not the current reply author if ($author_id !== $topic_author_id) { $args['secondary_item_id'] = $secondary_item_id; bp_notifications_add_notification($args); } // Notify the immediate reply author if not the current reply author if (!empty($reply_to) && $author_id !== $reply_to_item_id) { $args['secondary_item_id'] = $reply_to_item_id; bp_notifications_add_notification($args); } }
function load_more_topics() { $content = ''; ob_start(); $forum_id = $_POST['forum']; if ($topics = bbp_has_topics(array('post_parent' => $forum_id, 'posts_per_page' => 11, 'paged' => $_POST['list']))) { $counter = 0; while (bbp_topics()) { bbp_the_topic(); if (++$counter == 12) { break; } ?> <div class="topics_list_single_topic <?php $postUser = new WP_User(bbp_get_topic_author_id()); echo $postUser->has_cap('bbp_keymaster') || $postUser->has_cap('bbp_moderator') ? "isAdmin" : ""; ?> " id="topic-<?php echo bbp_get_topic_id(); ?> " data-bbp_forum_id="<?php echo $forum_id; ?> " data-id="<?php echo bbp_get_topic_id(); ?> "> <div class="single_topic_header"> <div class="photo"> <a href="<?php echo bp_core_get_user_domain(bbp_get_topic_author_id()); ?> "><?php echo bp_core_fetch_avatar(array('item_id' => bbp_get_topic_author_id(), 'height' => 40, 'width' => 40)); ?> </a> </div> <div class="info"> <div class="name"> <a href="<?php echo bp_core_get_user_domain(bbp_get_topic_author_id()); ?> "><?php echo bbp_get_topic_author_display_name(bbp_get_topic_id()); ?> </a> <?php if ($postUser->has_cap('bbp_keymaster')) { echo "<small>(Администратор форума)</small>"; } elseif ($postUser->has_cap('bbp_moderator')) { echo "<small>(Преподаватель)</small>"; } ?> </div> <div class="date"><?php echo get_post_time('j F ', false, bbp_get_topic_id(), true) . __('at', 'qode') . get_post_time(' H:i', false, bbp_get_topic_id(), true); ?> </div> </div> <?php if (bbp_get_topic_author_id() == get_current_user_id()) { ?> <a href="#" class="addi_actions_open"></a> <div class="addi_actions" style="display: none"> <ul> <li><a class="edit_action" href="#">Редактировать</a></li> <li><a class="remove_action" href="#">Удалить</a></li> </ul> </div> <?php } ?> </div> <div class="single_topic_content"> <?php $content = bbp_get_topic_content(); if (mb_strlen($content) > 500) { echo '<div class="show">' . mb_substr($content, 0, 500) . '... <a href="#" class="show_all">' . __('More', 'qode') . '</a></div>'; ?> <div class="hide"><?php echo $content; ?> </div> <?php } else { echo $content; } ?> </div> <div style="display: none" class="single_topic_content_edit"> <textarea class="edit_content"><?php echo get_post_field('post_content', bbp_get_topic_id()); ?> </textarea> <div class="edit_actions"> <button class="cancel"><?php _e('Cancel', 'qode'); ?> </button> <button class="save"><?php _e('Save', 'qode'); ?> </button> </div> </div> <div class="single_topic_replies_container"> <div class="single_topic_replies"> <?php $replies = get_posts($default = array('post_type' => bbp_get_reply_post_type(), 'post_parent' => bbp_get_topic_id(), 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true)); // Stickies not supported $i = count($replies); if ($i == 5) { $count = new WP_Query($default = array('numberposts' => -1, 'post_type' => bbp_get_reply_post_type(), 'post_parent' => bbp_get_topic_id(), 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true)); // Stickies not supported $count = $count->found_posts - 4; ?> <a href="#" class="load_all_replies"><i class="comments_img"></i>Просмотреть еще <?php echo $count . ' ' . custom_plural_form($count, 'комментарий', 'комментария', 'комментариев'); ?> </a> <?php } $replies = array_reverse($replies); //array_shift ( $replies ); foreach ($replies as $reply) { ?> <div class="single_topic_reply <?php $postUser = new WP_User($reply->post_author); echo $postUser->has_cap('bbp_keymaster') || $postUser->has_cap('bbp_moderator') ? "isAdmin" : ""; ?> " data-id="<?php echo $reply->ID; ?> "> <div class="photo"> <a href="<?php echo bp_core_get_user_domain($reply->post_author); ?> "><?php echo bp_core_fetch_avatar(array('item_id' => $reply->post_author, 'height' => 32, 'width' => 32)); ?> </a> </div> <div class="content_wrapper"> <div class="reply_content"> <a class="author-link" href="<?php echo bp_core_get_user_domain($reply->post_author); ?> "><?php echo bbp_get_reply_author_display_name($reply->ID); ?> </a> <?php if ($postUser->has_cap('bbp_keymaster')) { echo "<small>(Администратор форума)</small>"; } elseif ($postUser->has_cap('bbp_moderator')) { echo "<small>(Преподаватель)</small>"; } ?> <?php echo bbp_get_reply_content($reply->ID); ?> </div> <div style="display: none" class="reply_content_edit"> <textarea class="reply_content_edit_textarea"><?php echo get_post_field('post_content', $reply->ID); ?> </textarea> <div class="edit_actions"> <a class="cancel" href="#">Отменить</a> </div> </div> <div class="date"> <?php echo get_post_time('j F ', false, $reply->ID, true) . __('at', 'qode') . get_post_time(' H:i', false, $reply->ID, true); ?> </span><?php $like = get_post_meta($reply->ID, 'like_' . get_current_user_id(), true); ?> </div> </div> <?php if ($reply->post_author == get_current_user_id()) { ?> <a class="addi_actions_open" href="#"></a> <div class="addi_actions" style="display: none"> <ul> <li><a class="edit_action" href="#">Редактировать</a></li> <li><a class="remove_action" href="#">Удалить</a></li> </ul> </div> <?php } ?> </div> <?php } $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; ?> </div> <div class="single_topic_reply_form"> <form action="<?php echo $url; ?> #topic-<?php echo bbp_get_topic_id(); ?> " data-bbp_forum_id="<?php echo $forum_id; ?> " data-bbp_topic_id="<?php echo bbp_get_topic_id(); ?> " method="post"> <div class="photo"> <a href="<?php echo bp_core_get_user_domain(get_current_user_id()); ?> "><?php echo bp_core_fetch_avatar(array('item_id' => get_current_user_id(), 'height' => 32, 'width' => 32)); ?> </a> </div> <div class="reply-form"> <textarea placeholder="<?php _e('Введите текст сообщения...', 'qode'); ?> " name="content"></textarea> </div> <input type="hidden" name="bbp_forum_id" value="<?php echo $forum_id; ?> "> <input type="hidden" name="bbp_topic_id" value="<?php echo bbp_get_topic_id(); ?> "> <input type="hidden" name="action" value="custom-bbp-reply-create"> <input type="hidden" name="security" value="<?php echo wp_create_nonce('custom-bbp-reply-create'); ?> "> </form> </div> </div> </div> <?php } if ($counter == 11) { ?> <a class="load_more_topics" href="#"><?php _e('Load more discussions', 'qode'); ?> </a> <?php } } $content = ob_get_contents(); ob_end_clean(); die(json_encode(array('result' => 'OK', 'content' => $content))); }
/** * @covers ::bbp_check_for_blacklist */ public function test_should_return_false_when_html_wrapped_content_matches_blacklist_keys() { $u = $this->factory->user->create(); $t = $this->factory->topic->create(array('post_author' => $u, 'post_title' => 'Sting', 'post_content' => 'Beware, there maybe bees <strong>hiber</strong><em>nating</em>.')); $anonymous_data = false; $author_id = bbp_get_topic_author_id($t); $title = bbp_get_topic_title($t); $content = bbp_get_topic_content($t); update_option('blacklist_keys', "hibernating\nfoo"); $result = bbp_check_for_blacklist($anonymous_data, $author_id, $title, $content); $this->assertFalse($result); }
<tr> <td class="message60"> <p><a class="bbp-topic-permalink" href="<?php bbp_topic_permalink(); ?> "><?php bbp_topic_title(); ?> </a></p> <p><?php bbp_topic_excerpt(); ?> </p> </td> <?php $auth = get_userdata(bbp_get_topic_author_id())->ID; ?> <?php $pro = get_field('associated_profile', "user_{$auth}"); ?> <td class="message15"><p><a href="<?php echo get_permalink($pro); ?> "><?php echo get_the_title($pro); ?> </a></p></td> <td class="message10"><?php bbp_show_lead_topic() ? bbp_topic_reply_count() : bbp_topic_post_count(); ?> </td>
/** * Handles the front end edit topic submission * * @param string $action The requested action to compare this function to * @uses bbp_add_error() To add an error message * @uses bbp_get_topic() To get the topic * @uses bbp_verify_nonce_request() To verify the nonce and check the request * @uses bbp_is_topic_anonymous() To check if topic is by an anonymous user * @uses current_user_can() To check if the current user can edit the topic * @uses bbp_filter_anonymous_post_data() To filter anonymous data * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error} * @uses esc_attr() For sanitization * @uses bbp_is_forum_category() To check if the forum is a category * @uses bbp_is_forum_closed() To check if the forum is closed * @uses bbp_is_forum_private() To check if the forum is private * @uses remove_filter() To remove kses filters if needed * @uses apply_filters() Calls 'bbp_edit_topic_pre_title' with the title and * topic id * @uses apply_filters() Calls 'bbp_edit_topic_pre_content' with the content * and topic id * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors * @uses wp_save_post_revision() To save a topic revision * @uses bbp_update_topic_revision_log() To update the topic revision log * @uses bbp_stick_topic() To stick or super stick the topic * @uses bbp_unstick_topic() To unstick the topic * @uses wp_update_post() To update the topic * @uses do_action() Calls 'bbp_edit_topic' with the topic id, forum id, * anonymous data and reply author * @uses bbp_move_topic_handler() To handle movement of a topic from one forum * to another * @uses bbp_get_topic_permalink() To get the topic permalink * @uses wp_safe_redirect() To redirect to the topic link * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error * messages */ function bbp_edit_topic_handler($action = '') { // Bail if action is not bbp-edit-topic if ('bbp-edit-topic' !== $action) { return; } // Define local variable(s) $revisions_removed = false; $topic = $topic_id = $topic_author = $forum_id = $anonymous_data = 0; $topic_title = $topic_content = $topic_edit_reason = ''; /** Topic *****************************************************************/ // Topic id was not passed if (empty($_POST['bbp_topic_id'])) { bbp_add_error('bbp_edit_topic_id', __('<strong>ERROR</strong>: Topic ID not found.', 'bbpress')); return; // Topic id was passed } elseif (is_numeric($_POST['bbp_topic_id'])) { $topic_id = (int) $_POST['bbp_topic_id']; $topic = bbp_get_topic($topic_id); } // Topic does not exist if (empty($topic)) { bbp_add_error('bbp_edit_topic_not_found', __('<strong>ERROR</strong>: The topic you want to edit was not found.', 'bbpress')); return; // Topic exists } else { // Check users ability to create new topic if (!bbp_is_topic_anonymous($topic_id)) { // User cannot edit this topic if (!current_user_can('edit_topic', $topic_id)) { bbp_add_error('bbp_edit_topic_permissions', __('<strong>ERROR</strong>: You do not have permission to edit that topic.', 'bbpress')); } // Set topic author $topic_author = bbp_get_topic_author_id($topic_id); // It is an anonymous post } else { // Filter anonymous data $anonymous_data = bbp_filter_anonymous_post_data(array(), true); } } // Nonce check if (!bbp_verify_nonce_request('bbp-edit-topic_' . $topic_id)) { bbp_add_error('bbp_edit_topic_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress')); return; } // Remove kses filters from title and content for capable users and if the nonce is verified if (current_user_can('unfiltered_html') && !empty($_POST['_bbp_unfiltered_html_topic']) && wp_create_nonce('bbp-unfiltered-html-topic_' . $topic_id) === $_POST['_bbp_unfiltered_html_topic']) { remove_filter('bbp_edit_topic_pre_title', 'wp_filter_kses'); remove_filter('bbp_edit_topic_pre_content', 'bbp_encode_bad', 10); remove_filter('bbp_edit_topic_pre_content', 'bbp_filter_kses', 30); } /** Topic Forum ***********************************************************/ // Forum id was not passed if (empty($_POST['bbp_forum_id'])) { bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum ID is missing.', 'bbpress')); // Forum id was passed } elseif (is_numeric($_POST['bbp_forum_id'])) { $forum_id = (int) $_POST['bbp_forum_id']; } // Current forum this topic is in $current_forum_id = bbp_get_topic_forum_id($topic_id); // Forum exists if (!empty($forum_id) && $forum_id !== $current_forum_id) { // Forum is a category if (bbp_is_forum_category($forum_id)) { bbp_add_error('bbp_edit_topic_forum_category', __('<strong>ERROR</strong>: This forum is a category. No topics can be created in it.', 'bbpress')); // Forum is not a category } else { // Forum is closed and user cannot access if (bbp_is_forum_closed($forum_id) && !current_user_can('edit_forum', $forum_id)) { bbp_add_error('bbp_edit_topic_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new topics.', 'bbpress')); } // Forum is private and user cannot access if (bbp_is_forum_private($forum_id)) { if (!current_user_can('read_private_forums')) { bbp_add_error('bbp_edit_topic_forum_private', __('<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress')); } // Forum is hidden and user cannot access } elseif (bbp_is_forum_hidden($forum_id)) { if (!current_user_can('read_hidden_forums')) { bbp_add_error('bbp_edit_topic_forum_hidden', __('<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress')); } } } } /** Topic Title ***********************************************************/ if (!empty($_POST['bbp_topic_title'])) { $topic_title = esc_attr(strip_tags($_POST['bbp_topic_title'])); } // Filter and sanitize $topic_title = apply_filters('bbp_edit_topic_pre_title', $topic_title, $topic_id); // No topic title if (empty($topic_title)) { bbp_add_error('bbp_edit_topic_title', __('<strong>ERROR</strong>: Your topic needs a title.', 'bbpress')); } /** Topic Content *********************************************************/ if (!empty($_POST['bbp_topic_content'])) { $topic_content = $_POST['bbp_topic_content']; } // Filter and sanitize $topic_content = apply_filters('bbp_edit_topic_pre_content', $topic_content, $topic_id); // No topic content if (empty($topic_content)) { bbp_add_error('bbp_edit_topic_content', __('<strong>ERROR</strong>: Your topic cannot be empty.', 'bbpress')); } /** Topic Blacklist *******************************************************/ if (!bbp_check_for_blacklist($anonymous_data, $topic_author, $topic_title, $topic_content)) { bbp_add_error('bbp_topic_blacklist', __('<strong>ERROR</strong>: Your topic cannot be edited at this time.', 'bbpress')); } /** Topic Status **********************************************************/ // Maybe put into moderation if (!bbp_check_for_moderation($anonymous_data, $topic_author, $topic_title, $topic_content)) { // Set post status to pending if public or closed if (in_array($topic->post_status, array(bbp_get_public_status_id(), bbp_get_closed_status_id()))) { $topic_status = bbp_get_pending_status_id(); } // Check a whitelist of possible topic status ID's } elseif (!empty($_POST['bbp_topic_status']) && in_array($_POST['bbp_topic_status'], array_keys(bbp_get_topic_statuses()))) { $topic_status = $_POST['bbp_topic_status']; // Use existing post_status } else { $topic_status = $topic->post_status; } /** Topic Tags ************************************************************/ // Either replace terms if (bbp_allow_topic_tags() && current_user_can('assign_topic_tags') && !empty($_POST['bbp_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); // ...or remove them. } elseif (isset($_POST['bbp_topic_tags'])) { $terms = array(bbp_get_topic_tag_tax_id() => array()); // Existing terms } else { $terms = array(bbp_get_topic_tag_tax_id() => explode(',', bbp_get_topic_tag_names($topic_id, ','))); } /** Additional Actions (Before Save) **************************************/ do_action('bbp_edit_topic_pre_extras', $topic_id); // Bail if errors if (bbp_has_errors()) { return; } /** No Errors *************************************************************/ // Add the content of the form to $topic_data as an array // Just in time manipulation of topic data before being edited $topic_data = apply_filters('bbp_edit_topic_pre_insert', array('ID' => $topic_id, 'post_title' => $topic_title, 'post_content' => $topic_content, 'post_status' => $topic_status, 'post_parent' => $forum_id, 'post_author' => $topic_author, 'post_type' => bbp_get_topic_post_type(), 'tax_input' => $terms)); // Toggle revisions to avoid duplicates if (post_type_supports(bbp_get_topic_post_type(), 'revisions')) { $revisions_removed = true; remove_post_type_support(bbp_get_topic_post_type(), 'revisions'); } // Insert topic $topic_id = wp_update_post($topic_data); // Toggle revisions back on if (true === $revisions_removed) { $revisions_removed = false; add_post_type_support(bbp_get_topic_post_type(), 'revisions'); } /** No Errors *************************************************************/ if (!empty($topic_id) && !is_wp_error($topic_id)) { // Update counts, etc... do_action('bbp_edit_topic', $topic_id, $forum_id, $anonymous_data, $topic_author, true); /** Revisions *********************************************************/ // Revision Reason if (!empty($_POST['bbp_topic_edit_reason'])) { $topic_edit_reason = esc_attr(strip_tags($_POST['bbp_topic_edit_reason'])); } // Update revision log if (!empty($_POST['bbp_log_topic_edit']) && "1" === $_POST['bbp_log_topic_edit']) { $revision_id = wp_save_post_revision($topic_id); if (!empty($revision_id)) { bbp_update_topic_revision_log(array('topic_id' => $topic_id, 'revision_id' => $revision_id, 'author_id' => bbp_get_current_user_id(), 'reason' => $topic_edit_reason)); } } /** Move Topic ********************************************************/ // If the new forum id is not equal to the old forum id, run the // bbp_move_topic action and pass the topic's forum id as the // first arg and topic id as the second to update counts. if ($forum_id !== $topic->post_parent) { bbp_move_topic_handler($topic_id, $topic->post_parent, $forum_id); } /** Stickies **********************************************************/ if (!empty($_POST['bbp_stick_topic']) && in_array($_POST['bbp_stick_topic'], array_keys(bbp_get_topic_types()))) { // What's the caps? if (current_user_can('moderate')) { // What's the haps? switch ($_POST['bbp_stick_topic']) { // Sticky in forum case 'stick': bbp_stick_topic($topic_id); break; // Sticky in all forums // Sticky in all forums case 'super': bbp_stick_topic($topic_id, true); break; // Normal // Normal case 'unstick': default: bbp_unstick_topic($topic_id); break; } } } /** Additional Actions (After Save) ***********************************/ do_action('bbp_edit_topic_post_extras', $topic_id); /** Redirect **********************************************************/ // Redirect to $redirect_to = bbp_get_redirect_to(); // View all? $view_all = bbp_get_view_all(); // Get the topic URL $topic_url = bbp_get_topic_permalink($topic_id, $redirect_to); // Add view all? if (!empty($view_all)) { $topic_url = bbp_add_view_all($topic_url); } // Allow to be filtered $topic_url = apply_filters('bbp_edit_topic_redirect_to', $topic_url, $view_all, $redirect_to); /** Successful Edit ***************************************************/ // Redirect back to new topic wp_safe_redirect($topic_url); // For good measure exit; /** Errors ****************************************************************/ } else { $append_error = is_wp_error($topic_id) && $topic_id->get_error_message() ? $topic_id->get_error_message() . ' ' : ''; bbp_add_error('bbp_topic_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your topic:' . $append_error . 'Please try again.', 'bbpress')); } }
<span><?php _e('Last post: ', 'framework'); ?> </span> <?php do_action('bbp_theme_after_topic_meta'); ?> <?php do_action('bbp_theme_before_topic_freshness_author'); ?> <span class="bbp-topic-freshness-author"> <?php if (class_exists('userpro_api')) { global $userpro; $link = preg_replace("/(?<=href=(\"|'))[^\"']+(?=(\"|'))/", $userpro->permalink(bbp_get_topic_author_id(bbp_get_topic_last_active_id())), bbp_get_author_link(array('post_id' => bbp_get_topic_last_active_id(), 'size' => 30))); } else { bbp_author_link(array('post_id' => bbp_get_topic_last_active_id(), 'type' => 'name')); } ?> </span> - <?php do_action('bbp_theme_after_topic_freshness_author'); ?> <?php do_action('bbp_theme_before_topic_freshness_link'); ?> <?php
<?php do_action('bbp_theme_before_topic_form_subscriptions'); ?> <p> <input name="bbp_topic_subscription" id="bbp_topic_subscription" type="checkbox" value="bbp_subscribe" <?php bbp_form_topic_subscribed(); ?> tabindex="<?php bbp_tab_index(); ?> " /> <?php if (bbp_is_topic_edit() && bbp_get_topic_author_id() !== bbp_get_current_user_id()) { ?> <label for="bbp_topic_subscription"><?php _e('Notify the author of follow-up replies via email', 'bbpress'); ?> </label> <?php } else { ?> <label for="bbp_topic_subscription"><?php _e('Notify me of follow-up replies via email', 'bbpress'); ?> </label>
function gpbbp_display_user_brand_with_username_topic($author_name, $topic_id) { $author_id = bbp_get_topic_author_id(); $author_brand = gpbbp_get_author_brand($author_id); $author_name_brand_display = $author_name . '<br>' . $author_brand; return $author_name_brand_display; }