/** * Notify user roles on new topic */ public function notify_new_topic($topic_id = 0, $forum_id = 0, $anonymous_data = 0, $topic_author = 0) { $user_roles = Falcon::get_option('bbsub_topic_notification', array()); // bail out if no user roles found if (!$user_roles) { return; } $recipients = array(); foreach ($user_roles as $role) { $users = get_users(array('role' => $role, 'fields' => array('ID', 'user_email', 'display_name'))); $recipients = array_merge($recipients, $users); } // still no users? if (!$recipients) { return; } // subscribe the users automatically foreach ($recipients as $user) { bbp_add_user_subscription($user->ID, $topic_id); } // Sanitize the HTML into text $content = apply_filters('bbsub_html_to_text', bbp_get_topic_content($topic_id)); // Build email $text = "%1\$s\n\n"; $text .= "---\nReply to this email directly or view it online:\n%2\$s\n\n"; $text .= "You are receiving this email because you subscribed to it. Login and visit the topic to unsubscribe from these emails."; $text = sprintf($text, $content, bbp_get_topic_permalink($topic_id)); $text = apply_filters('bbsub_topic_email_message', $text, $topic_id, $content); $subject = apply_filters('bbsub_topic_email_subject', 'Re: [' . get_option('blogname') . '] ' . bbp_get_topic_title($topic_id), $topic_id); $options = array('author' => bbp_get_topic_author_display_name($topic_id), 'id' => $topic_id); $this->handler->send_mail($recipients, $subject, $text, $options); do_action('bbp_post_notify_topic_subscribers', $topic_id, $recipients); }
/** * Plugin Name: WP Slack bbPress * Plugin URI: https://github.com/rolfkleef/wp-slack-bbpress * Description: Send notifications to Slack channels for events in bbPress. * Version: 0.5 * Author: Rolf Kleef * Author URI: https://drostan.org * License: GPL2 * License URI: https://www.gnu.org/licenses/gpl-2.0.html * Text Domain: wp-slack-bbpress */ function wp_slack_bbpress($events) { $events['wp_slack_bbp_new_topic'] = array('action' => 'bbp_new_topic', 'description' => __('When a new topic is added in bbPress', 'wp-slack-bbpress'), 'message' => function ($topic_id, $forum_id, $anonymous_data, $topic_author) { return array(array('fallback' => sprintf(__('<%1$s|New topic "%2$s"> in forum <%3$s|%4$s>', 'wp-slack-bbpress'), bbp_get_topic_permalink($topic_id), bbp_get_topic_title($topic_id), bbp_get_forum_permalink($forum_id), bbp_get_forum_title($forum_id)), 'pretext' => sprintf(__('New topic in forum <%1$s|%2$s>', 'wp-slack-bbpress'), bbp_get_forum_permalink($forum_id), bbp_get_forum_title($forum_id)), 'author_name' => bbp_get_topic_author_display_name($topic_id), 'author_link' => bbp_get_topic_author_link($topic_id), 'author_icon' => get_avatar_url($topic_author, array('size' => 16)), 'title' => sprintf('%1$s', bbp_get_topic_title($topic_id)), 'title_link' => bbp_get_topic_permalink($topic_id), 'text' => html_entity_decode(bbp_get_topic_excerpt($topic_id, 150)))); }); $events['wp_slack_bbp_new_reply'] = array('action' => 'bbp_new_reply', 'description' => __('When a new reply is added in bbPress', 'wp-slack-bbpress'), 'message' => function ($reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, $bool, $reply_to) { return array(array('fallback' => sprintf(__('<%1$s|New reply> in forum <%2$s|%3$s> on topic <%4$s|%5$s>', 'wp-slack-bbpress'), bbp_get_reply_url($reply_id), bbp_get_forum_permalink($forum_id), bbp_get_forum_title($forum_id), bbp_get_topic_permalink($topic_id), bbp_get_topic_title($topic_id)), 'pretext' => sprintf(__('New reply in forum <%1$s|%2$s> on topic <%3$s|%4$s>', 'wp-slack-bbpress'), bbp_get_forum_permalink($forum_id), bbp_get_forum_title($forum_id), bbp_get_topic_permalink($topic_id), bbp_get_topic_title($topic_id)), 'author_name' => bbp_get_reply_author_display_name($reply_id), 'author_link' => bbp_get_reply_author_link($reply_id), 'author_icon' => get_avatar_url($reply_author, array('size' => 16)), 'title' => sprintf(__('New reply to "%1$s"', 'wp-slack-bbpress'), bbp_get_topic_title($topic_id)), 'title_link' => bbp_get_reply_url($reply_id), 'text' => html_entity_decode(bbp_get_reply_excerpt($reply_id, 150)))); }); return $events; }
/** * @covers ::bbp_topic_permalink * @covers ::bbp_get_topic_permalink */ public function test_bbp_get_topic_permalink() { if (is_multisite()) { $this->markTestSkipped('Skipping URL tests in multiste for now.'); } $f = $this->factory->forum->create(); $t = $this->factory->topic->create(array('post_title' => 'Topic 1', 'post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $topic_permalink = bbp_get_topic_permalink($t); $this->expectOutputString($topic_permalink); bbp_topic_permalink($t); $this->assertSame('http://' . WP_TESTS_DOMAIN . '/?topic=topic-1', $topic_permalink); }
public static function topic_message($message, $topic_id, $forum_id, $user_id) { $topic_content = strip_tags(bbp_get_topic_content($topic_id)); $topic_url = bbp_get_topic_permalink($topic_id); $topic_author = bbp_get_topic_author_display_name($topic_id); $custom_message = get_option('_bbp_topic_notice_body'); $message = $custom_message ? $custom_message : $message; $message = str_replace('{author}', $topic_author, $message); $message = str_replace('{content}', $topic_content, $message); $message = str_replace('{url}', $topic_url, $message); return $message; }
/** * Notify admins on new topic * * @param type $topic_id * @param type $forum_id * @param type $anonymous_data * @param type $topic_author * @return boolean */ public function notify_topic($topic_id, $forum_id, $anonymous_data, $topic_author) { $topic_id = bbp_get_topic_id($topic_id); $forum_id = bbp_get_forum_id($forum_id); remove_all_filters('bbp_get_topic_content'); remove_all_filters('bbp_get_topic_title'); $topic_title = strip_tags(bbp_get_topic_title($topic_id)); $topic_content = strip_tags(bbp_get_topic_content($topic_id)); $topic_url = bbp_get_topic_permalink($topic_id); $topic_author_name = bbp_get_topic_author_display_name($topic_id); $message = sprintf(__('%1$s created new topic: %2$s Topic Link: %3$s ----------- You are receiving this email because you askd for it. Login and visit the settings to disable these emails.', 'bbp-notify-admin'), $topic_author_name, $topic_content, $topic_url); $message = apply_filters('bbp_notify_admin_topic_mail_message', $message, $topic_id, $forum_id); if (empty($message)) { return; } $subject = apply_filters('bbp_notify_admin_reply_mail_title', $this->get_subject(__('New Topic: ', 'bbp-notify-admin') . $topic_title), $topic_id, $forum_id); if (empty($subject)) { return; } $headers = $this->get_headers(); //get the users to send an email $users = $this->get_users_to_notify('topic'); $users = apply_filters('bbp_notify_admin_topic_notifiable_users', $users); if (empty($users)) { return false; } //get all users emails $emails = $this->get_emails($users, 'topic'); if (empty($emails)) { return false; //no one to send to } $to_email = array_shift($emails); // Loop through users foreach ($emails as $email) { //add all other users as bcc(only applies in case we have more than 1 admin ) $headers[] = 'Bcc:' . $email; } //send email //even if an admin posts, It will notify everyone including him $this->notify(array('subject' => $subject, 'message' => $message, 'to' => $to_email, 'headers' => $headers)); }
/** * Load localizations for topic script. * * These localizations require information that may not be loaded even by init. * * @since bbPress (r2652) * * @uses bbp_is_single_topic() To check if it's the topic page * @uses bbp_get_current_user_id() To get the current user id * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_favorites_permalink() To get the favorites permalink * @uses bbp_is_user_favorite() To check if the topic is in user's favorites * @uses bbp_is_subscriptions_active() To check if the subscriptions are active * @uses bbp_is_user_subscribed() To check if the user is subscribed to topic * @uses bbp_get_topic_permalink() To get the topic permalink * @uses wp_localize_script() To localize the script */ function bbp_skeleton_topic_script_localization() { if (!bbp_is_single_topic()) { return; } $user_id = bbp_get_current_user_id(); $localizations = array('currentUserId' => $user_id, 'topicId' => bbp_get_topic_id()); // Favorites if (bbp_is_favorites_active()) { $localizations['favoritesActive'] = 1; $localizations['favoritesLink'] = bbp_get_favorites_permalink($user_id); $localizations['isFav'] = (int) bbp_is_user_favorite($user_id); $localizations['favLinkYes'] = __('favorites', 'bbpress'); $localizations['favLinkNo'] = __('?', 'bbpress'); $localizations['favYes'] = __('This topic is one of your %favLinkYes% [%favDel%]', 'bbpress'); $localizations['favNo'] = __('%favAdd% (%favLinkNo%)', 'bbpress'); $localizations['favDel'] = __('×', 'bbpress'); $localizations['favAdd'] = __('Add this topic to your favorites', 'bbpress'); } else { $localizations['favoritesActive'] = 0; } // Subscriptions if (bbp_is_subscriptions_active()) { $localizations['subsActive'] = 1; $localizations['isSubscribed'] = (int) bbp_is_user_subscribed($user_id); $localizations['subsSub'] = __('Subscribe', 'bbpress'); $localizations['subsUns'] = __('Unsubscribe', 'bbpress'); $localizations['subsLink'] = bbp_get_topic_permalink(); } else { $localizations['subsActive'] = 0; } wp_localize_script('bbp_topic', 'bbpTopicJS', $localizations); }
/** * Record an activity stream entry when a reply is created * * @since bbPress (r3395) * @param int $topic_id * @param int $forum_id * @param array $anonymous_data * @param int $topic_author_id * @uses bbp_get_reply_id() * @uses bbp_get_topic_id() * @uses bbp_get_forum_id() * @uses bbp_get_user_profile_link() * @uses bbp_get_reply_url() * @uses bbp_get_reply_content() * @uses bbp_get_topic_permalink() * @uses bbp_get_topic_title() * @uses bbp_get_forum_permalink() * @uses bbp_get_forum_title() * @uses bp_create_excerpt() * @uses apply_filters() * @return Bail early if topic is by anonywous user */ public function reply_create($reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author_id) { // Do not log activity of anonymous users if (!empty($anonymous_data)) { return; } // Bail if site is private if (!bbp_is_site_public()) { return; } // Validate activity data $user_id = $reply_author_id; $reply_id = bbp_get_reply_id($reply_id); $topic_id = bbp_get_topic_id($topic_id); $forum_id = bbp_get_forum_id($forum_id); // Bail if user is not active if (bbp_is_user_inactive($user_id)) { return; } // Bail if reply is not published if (!bbp_is_reply_published($reply_id)) { return; } // Setup links for activity stream $user_link = bbp_get_user_profile_link($user_id); // Reply $reply_url = bbp_get_reply_url($reply_id); $reply_content = get_post_field('post_content', $reply_id, 'raw'); // Topic $topic_permalink = bbp_get_topic_permalink($topic_id); $topic_title = get_post_field('post_title', $topic_id, 'raw'); $topic_link = '<a href="' . $topic_permalink . '" title="' . $topic_title . '">' . $topic_title . '</a>'; // Forum $forum_permalink = bbp_get_forum_permalink($forum_id); $forum_title = get_post_field('post_title', $forum_id, 'raw'); $forum_link = '<a href="' . $forum_permalink . '" title="' . $forum_title . '">' . $forum_title . '</a>'; // Activity action & text $activity_text = sprintf(__('%1$s replied to the topic %2$s in the forum %3$s', 'bbpress'), $user_link, $topic_link, $forum_link); $activity_action = apply_filters('bbp_activity_reply_create', $activity_text, $user_id, $reply_id, $topic_id); $activity_content = apply_filters('bbp_activity_reply_create_excerpt', bp_create_excerpt($reply_content), $reply_content); // Compile the activity stream results $activity = array('id' => $this->get_activity_id($reply_id), 'user_id' => $user_id, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $reply_url, 'type' => $this->reply_create, 'item_id' => $reply_id, 'secondary_item_id' => $topic_id, 'recorded_time' => get_post_time('Y-m-d H:i:s', true, $reply_id), 'hide_sitewide' => !bbp_is_forum_public($forum_id, false)); // Record the activity $activity_id = $this->record_activity($activity); // Add the activity entry ID as a meta value to the reply if (!empty($activity_id)) { update_post_meta($reply_id, '_bbp_activity_id', $activity_id); } }
function cupid_breadcrumb_get_bbpress_items() { $item = array(); $post_type_object = get_post_type_object(bbp_get_forum_post_type()); if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { $item[] = '<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '">' . bbp_get_forum_archive_title() . '</a></li>'; } if (bbp_is_forum_archive()) { $item['last'] = bbp_get_forum_archive_title(); } elseif (bbp_is_topic_archive()) { $item['last'] = bbp_get_topic_archive_title(); } elseif (bbp_is_single_view()) { $item['last'] = bbp_get_view_title(); } elseif (bbp_is_single_topic()) { $topic_id = get_queried_object_id(); $item = array_merge($item, cupid_breadcrumb_get_parents(bbp_get_topic_forum_id($topic_id))); if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $item[] = '<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . bbp_get_topic_permalink($topic_id) . '">' . bbp_get_topic_title($topic_id) . '</a></li>'; } else { $item['last'] = bbp_get_topic_title($topic_id); } if (bbp_is_topic_split()) { $item['last'] = __('Split', 'cupid'); } elseif (bbp_is_topic_merge()) { $item['last'] = __('Merge', 'cupid'); } elseif (bbp_is_topic_edit()) { $item['last'] = __('Edit', 'cupid'); } } elseif (bbp_is_single_reply()) { $reply_id = get_queried_object_id(); $item = array_merge($item, cupid_breadcrumb_get_parents(bbp_get_reply_topic_id($reply_id))); if (!bbp_is_reply_edit()) { $item['last'] = bbp_get_reply_title($reply_id); } else { $item[] = '<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . bbp_get_reply_url($reply_id) . '">' . bbp_get_reply_title($reply_id) . '</a></li>'; $item['last'] = __('Edit', 'cupid'); } } elseif (bbp_is_single_forum()) { $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); if (0 !== $forum_parent_id) { $item = array_merge($item, cupid_breadcrumb_get_parents($forum_parent_id)); } $item['last'] = bbp_get_forum_title($forum_id); } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $item[] = '<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . bbp_get_user_profile_url() . '">' . bbp_get_displayed_user_field('display_name') . '</a></li>'; $item['last'] = __('Edit', 'cupid'); } else { $item['last'] = bbp_get_displayed_user_field('display_name'); } } return apply_filters('cupid_breadcrumb_get_bbpress_items', $item); }
/** * Find all tickets that are 10 days old, close them, and send notices to the customer * * @since 2.1 * @return void */ function edd_bbp_close_old_tickets_and_notify() { $args = array('post_type' => 'topic', 'meta_query' => array('relation' => 'AND', array('key' => '_bbps_topic_status', 'value' => '1'), array('key' => '_bbp_last_active_time', 'value' => date('Y-n-d H:i:s', strtotime('-10 days')), 'compare' => '<=', 'type' => 'DATETIME'), array('key' => '_bbp_override_auto_close', 'compare' => 'NOT EXISTS'), array('key' => '_bbp_voice_count', 'value' => '1', 'compare' => '>')), 'posts_per_page' => 50, 'post_parent__not_in' => array(318)); $tickets = get_posts($args); if ($tickets) { $emails = EDD()->emails; $emails->__set('from_address', '*****@*****.**'); $emails->heading = 'Support Alert'; foreach ($tickets as $ticket) { $author_name = get_the_author_meta('display_name', $ticket->post_author); $author_email = get_the_author_meta('user_email', $ticket->post_author); $url = bbp_get_topic_permalink($ticket->ID); $to = array(); $to[] = $author_email; $to[] = '*****@*****.**'; $message = "Hello {$author_name},\n\n"; $message .= "This email is to alert you that your ticket titled {$ticket->post_title} at https://easydigitaldownloads.com has been automatically closed due to inactivity.\n\n"; $message .= "If you believe this is in error or you are still needing assistance with this issue, simply reply to the ticket again and let us know: \n\n"; $message .= "Ticket URL: {$url}"; $emails->send($to, 'Support Ticket Closed', $message); update_post_meta($ticket->ID, '_bbps_topic_status', '2'); } $emails->__set('from_address', false); } }
/** * Return the link to the last topic in a forum * * @since bbPress (r2464) * * @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_permalink() To get the topic's permalink * @uses apply_filters() Calls 'bbp_get_forum_last_topic_permalink' with * the topic link and forum id * @return string Permanent link to topic */ function bbp_get_forum_last_topic_permalink($forum_id = 0) { $forum_id = bbp_get_forum_id($forum_id); return apply_filters('bbp_get_forum_last_topic_permalink', bbp_get_topic_permalink(bbp_get_forum_last_topic_id($forum_id)), $forum_id); }
function mk_theme_breadcrumbs() { global $mk_options, $post; $post_id = global_get_post_id(); if ($post_id) { $local_skining = get_post_meta($post_id, '_enable_local_backgrounds', true); $breadcrumb_skin = get_post_meta($post_id, '_breadcrumb_skin', true); if ($local_skining == 'true' && !empty($breadcrumb_skin)) { $breadcrumb_skin_class = $breadcrumb_skin; } else { $breadcrumb_skin_class = $mk_options['breadcrumb_skin']; } } else { $breadcrumb_skin_class = $mk_options['breadcrumb_skin']; } $delimiter = ' / '; echo '<div id="mk-breadcrumbs"><div class="mk-breadcrumbs-inner ' . $breadcrumb_skin_class . '-skin">'; if (!is_front_page()) { echo '<a href="'; echo home_url(); echo '">' . __('Home', 'mk_framework'); echo "</a>" . $delimiter; } if (function_exists('is_woocommerce') && is_woocommerce() && is_archive()) { $shop_page_id = wc_get_page_id('shop'); $shop_page = get_post($shop_page_id); $permalinks = get_option('woocommerce_permalinks'); if ($shop_page_id && $shop_page && get_option('page_on_front') !== $shop_page_id) { echo '<a href="' . get_permalink($shop_page) . '">' . $shop_page->post_title . '</a> '; } } if (is_category() && !is_singular('portfolio')) { $category = get_the_category(); $ID = $category[0]->cat_ID; echo is_wp_error($cat_parents = get_category_parents($ID, TRUE, '', FALSE)) ? '' : '<span>' . $cat_parents . '</span>'; } else { if (is_singular('news')) { echo '<span>' . get_the_title() . '</span>'; } else { if (is_single() && !is_attachment()) { if (get_post_type() == 'product') { if ($terms = wc_get_product_terms($post->ID, 'product_cat', array('orderby' => 'parent', 'order' => 'DESC'))) { $main_term = $terms[0]; $ancestors = get_ancestors($main_term->term_id, 'product_cat'); $ancestors = array_reverse($ancestors); foreach ($ancestors as $ancestor) { $ancestor = get_term($ancestor, 'product_cat'); if (!is_wp_error($ancestor) && $ancestor) { echo '<a href="' . get_term_link($ancestor->slug, 'product_cat') . '">' . $ancestor->name . '</a>' . $delimiter; } } echo '<a href="' . get_term_link($main_term->slug, 'product_cat') . '">' . $main_term->name . '</a>' . $delimiter; } echo get_the_title(); } elseif (is_singular('portfolio')) { $portfolio_category = get_the_term_list($post->ID, 'portfolio_category', '', ' / '); if (!empty($portfolio_category)) { echo $portfolio_category . $delimiter; } echo '<span>' . get_the_title() . '</span>'; } elseif (get_post_type() != 'post') { if (function_exists('is_bbpress') && is_bbpress()) { } else { $post_type = get_post_type_object(get_post_type()); $slug = $post_type->rewrite; echo '<a href="' . get_post_type_archive_link(get_post_type()) . '">' . $post_type->labels->singular_name . '</a>' . $delimiter; echo get_the_title(); } } else { $cat = current(get_the_category()); echo get_category_parents($cat, true, $delimiter); echo get_the_title(); } } elseif (is_page() && !$post->post_parent) { echo get_the_title(); } elseif (is_page() && $post->post_parent) { $parent_id = $post->post_parent; $breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>'; $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); foreach ($breadcrumbs as $crumb) { echo $crumb . '' . $delimiter; } echo get_the_title(); } elseif (is_attachment()) { $parent = get_post($post->post_parent); $cat = get_the_category($parent->ID); $cat = $cat[0]; /* admin@innodron.com patch: Fix for Catchable fatal error: Object of class WP_Error could not be converted to string ref: https://wordpress.org/support/topic/catchable-fatal-error-object-of-class-wp_error-could-not-be-converted-to-string-11 */ echo is_wp_error($cat_parents = get_category_parents($cat, TRUE, '' . $delimiter . '')) ? '' : $cat_parents; /* end admin@innodron.com patch */ echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>' . $delimiter; echo get_the_title(); } elseif (is_search()) { echo __('Search results for “', 'mk_framework') . get_search_query() . '”'; } elseif (is_tag()) { echo __('Tag “', 'mk_framework') . single_tag_title('', false) . '”'; } elseif (is_author()) { $userdata = get_userdata(get_the_author_meta('ID')); echo __('Author:', 'mk_framework') . ' ' . $userdata->display_name; } elseif (is_day()) { echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $delimiter; echo '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a>' . $delimiter; echo get_the_time('d'); } elseif (is_month()) { echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $delimiter; echo get_the_time('F'); } elseif (is_year()) { echo get_the_time('Y'); } } } if (get_query_var('paged')) { echo ' (' . __('Page', 'mk_framework') . ' ' . get_query_var('paged') . ')'; } if (is_tax()) { $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); if (function_exists('is_woocommerce') && is_woocommerce() && is_archive()) { echo $delimiter; } echo '<span>' . $term->name . '</span>'; } if (function_exists('is_bbpress') && is_bbpress()) { $item = array(); $post_type_object = get_post_type_object(bbp_get_forum_post_type()); if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { $item[] = '<a href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '">' . bbp_get_forum_archive_title() . '</a>'; } if (bbp_is_forum_archive()) { $item[] = bbp_get_forum_archive_title(); } elseif (bbp_is_topic_archive()) { $item[] = bbp_get_topic_archive_title(); } elseif (bbp_is_single_view()) { $item[] = bbp_get_view_title(); } elseif (bbp_is_single_topic()) { $topic_id = get_queried_object_id(); $item = array_merge($item, mk_breadcrumbs_get_parents(bbp_get_topic_forum_id($topic_id))); if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $item[] = '<a href="' . bbp_get_topic_permalink($topic_id) . '">' . bbp_get_topic_title($topic_id) . '</a>'; } else { $item[] = bbp_get_topic_title($topic_id); } if (bbp_is_topic_split()) { $item[] = __('Split', 'mk_framework'); } elseif (bbp_is_topic_merge()) { $item[] = __('Merge', 'mk_framework'); } elseif (bbp_is_topic_edit()) { $item[] = __('Edit', 'mk_framework'); } } elseif (bbp_is_single_reply()) { $reply_id = get_queried_object_id(); $item = array_merge($item, mk_breadcrumbs_get_parents(bbp_get_reply_topic_id($reply_id))); if (!bbp_is_reply_edit()) { $item[] = bbp_get_reply_title($reply_id); } else { $item[] = '<a href="' . bbp_get_reply_url($reply_id) . '">' . bbp_get_reply_title($reply_id) . '</a>'; $item[] = __('Edit', 'mk_framework'); } } elseif (bbp_is_single_forum()) { $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); if (0 !== $forum_parent_id) { $item = array_merge($item, mk_breadcrumbs_get_parents($forum_parent_id)); } $item[] = bbp_get_forum_title($forum_id); } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $item[] = '<a href="' . bbp_get_user_profile_url() . '">' . bbp_get_displayed_user_field('display_name') . '</a>'; $item[] = __('Edit', 'mk_framework'); } else { $item[] = bbp_get_displayed_user_field('display_name'); } } echo implode($delimiter, $item); } echo "</div></div>"; }
/** * Gets the items for the breadcrumb item if bbPress is installed. * * @since 0.4 * * @param array $args Mixed arguments for the menu. * @return array List of items to be shown in the item. */ function breadcrumbs_plus_get_bbpress_items($args = array()) { $item = array(); $post_type_object = get_post_type_object(bbp_get_forum_post_type()); if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { if (function_exists('bp_is_active')) { global $bp; // we're outside the loop! // Assign some variables here $page1 = isset($bp->members->root_slug) ? $bp->members->root_slug : ''; // slug for the Members page. The BuddyPress default is 'members'. $page2 = isset($bp->groups->root_slug) ? $bp->groups->root_slug : ''; // slug for the Groups page. The BuddyPress default is 'groups'. $page3 = isset($bp->activity->root_slug) ? $bp->activity->root_slug : ''; // slug for the Activity page. The BuddyPress default is 'activity'. $page4 = isset($bp->forums->root_slug) ? $bp->forums->root_slug : ''; // slug for the Forums page. The BuddyPress default is 'forums'. $page5 = isset($bp->achievements->root_slug) ? $bp->achievements->root_slug : ''; // slug for the Achievements page. The BuddyPress default is 'achievements'. if (!bp_is_blog_page() && (is_page() || is_page($page1) || is_page($page2) || is_page($page3) || is_page($page4) || is_page($page5)) && !bp_is_user() && !bp_is_single_item() && !bp_is_register_page()) { $item[] = ''; } if (bp_is_user() && !bp_is_register_page()) { $item[] = ''; } } else { //$item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . get_post_type_archive_link( bbp_get_forum_post_type() ) . '" rel="v:url" property="v:title">' . bbp_get_forum_archive_title() . '</a></div>'; } } if (bbp_is_forum_archive()) { $item[] = bbp_get_forum_archive_title(); } else { $item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '" rel="v:url" property="v:title">' . bbp_get_forum_archive_title() . '</a></div>'; } if (bbp_is_topic_archive()) { $item[] = bbp_get_topic_archive_title(); } elseif (bbp_is_single_view()) { $item[] = bbp_get_view_title(); } elseif (bbp_is_single_topic()) { $topic_id = get_queried_object_id(); $item = array_merge($item, breadcrumbs_plus_get_parents(bbp_get_topic_forum_id($topic_id))); if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . bbp_get_topic_permalink($topic_id) . '" rel="v:url" property="v:title">' . bbp_get_topic_title($topic_id) . '</a></div>'; } else { $item[] = ''; } if (bbp_is_topic_split()) { $item[] = __('Split', 'framework'); } elseif (bbp_is_topic_merge()) { $item[] = __('Merge', 'framework'); } elseif (bbp_is_topic_edit()) { $item[] = __('Edit', 'framework'); } } elseif (bbp_is_single_reply()) { $reply_id = get_queried_object_id(); $item = array_merge($item, breadcrumbs_plus_get_parents(bbp_get_reply_topic_id($reply_id))); if (!bbp_is_reply_edit()) { $item[] = bbp_get_reply_title($reply_id); } else { $item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . bbp_get_reply_url($reply_id) . '" rel="v:url" property="v:title">' . bbp_get_reply_title($reply_id) . '</a></div>'; $item[] = __('Edit', 'framework'); } } elseif (bbp_is_single_forum()) { $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); if (0 !== $forum_parent_id) { $item = array_merge($item, breadcrumbs_plus_get_parents($forum_parent_id)); } $item[] = bbp_get_forum_title($forum_id); } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . bbp_get_user_profile_url() . '" rel="v:url" property="v:title">' . bbp_get_displayed_user_field('display_name') . '</a></div>'; $item[] = __('Edit', 'framework'); } else { $item[] = bbp_get_displayed_user_field('display_name'); } } return apply_filters('breadcrumbs_plus_get_bbpress_items', $item, $args); }
function hook_bbp_new_topic($topic_id) { $topic_url = bbp_get_topic_permalink($topic_id); //$dir = $this->get_folder() . '' . substr($topic_url, strlen(get_option('home'))) . '/'; $dir = $this->get_folder() . '/' . substr($topic_url, strpos($topic_url, '://') + 3) . '/'; $this->remove_dir($dir); $forum_id = bbp_get_topic_forum_id($topic_id); $forum_url = bbp_get_forum_permalink($forum_id); $dir = $this->get_folder() . '/' . substr($topic_url, strpos($forum_url, '://') + 3) . '/'; //$dir = $this->get_folder() . '' . substr($forum_url, strlen(get_option('home'))) . '/'; $this->remove_dir($dir); }
protected function _bbpress_items() { $item = array(); $post_type_object = get_post_type_object(bbp_get_forum_post_type()); if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { $item[] = '<span typeof="v:Breadcrumb"><a href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '" property="v:title" rel="v:url"><span>' . bbp_get_forum_archive_title() . '</span></a></span>'; } if (bbp_is_forum_archive()) { $item[] = bbp_get_forum_archive_title(); } elseif (bbp_is_topic_archive()) { $item[] = bbp_get_topic_archive_title(); } elseif (bbp_is_single_view()) { $item[] = bbp_get_view_title(); } elseif (bbp_is_single_topic()) { $topic_id = get_queried_object_id(); $item = array_merge($item, $this->_get_parents(bbp_get_topic_forum_id($topic_id))); if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $item[] = '<span typeof="v:Breadcrumb"><a href="' . bbp_get_topic_permalink($topic_id) . '" property="v:title" rel="v:url"><span>' . bbp_get_topic_title($topic_id) . '</span></a></span>'; } else { $item[] = bbp_get_topic_title($topic_id); } if (bbp_is_topic_split()) { $item[] = __('Split', DH_DOMAIN); } elseif (bbp_is_topic_merge()) { $item[] = __('Merge', DH_DOMAIN); } elseif (bbp_is_topic_edit()) { $item[] = __('Edit', DH_DOMAIN); } } elseif (bbp_is_single_reply()) { $reply_id = get_queried_object_id(); $item = array_merge($item, $this->_get_parents(bbp_get_reply_topic_id($reply_id))); if (!bbp_is_reply_edit()) { $item[] = bbp_get_reply_title($reply_id); } else { $item[] = '<span typeof="v:Breadcrumb"><a href="' . bbp_get_reply_url($reply_id) . '" property="v:title" rel="v:url"><span>' . bbp_get_reply_title($reply_id) . '</span></a></span>'; $item[] = __('Edit', DH_DOMAIN); } } elseif (bbp_is_single_forum()) { $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); if (0 !== $forum_parent_id) { $item = array_merge($item, $this->_get_parents($forum_parent_id)); } $item[] = bbp_get_forum_title($forum_id); } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $item[] = '<span typeof="v:Breadcrumb"><a href="' . bbp_get_user_profile_url() . '" property="v:title" rel="v:url" ><span>' . bbp_get_displayed_user_field('display_name') . '</span></a></span>'; $item[] = __('Edit', DH_DOMAIN); } else { $item[] = bbp_get_displayed_user_field('display_name'); } } return $item; }
/** * Public filter 'bbp_*' - Checks topics, replies by cleantalk * @param mixed[] $comment Comment string * @return mixed[] $comment Comment string */ function ct_bbp_new_pre_content($comment) { global $ct_options, $ct_data; $ct_options = ct_get_options(); $ct_data = ct_get_data(); if (ct_is_user_enable() === false || $ct_options['comments_test'] == 0 || is_user_logged_in()) { return $comment; } $checkjs = js_test('ct_checkjs', $_COOKIE, true); if ($checkjs === null) { $checkjs = js_test('ct_checkjs', $_POST, true); } $example = null; $sender_info = array('sender_url' => isset($_POST['bbp_anonymous_website']) ? $_POST['bbp_anonymous_website'] : null); $post_info['comment_type'] = 'bbpress_comment'; $post_info['post_url'] = bbp_get_topic_permalink(); $post_info = json_encode($post_info); if ($post_info === false) { $post_info = ''; } $ct_base_call_result = ct_base_call(array('message' => $comment, 'example' => $example, 'sender_email' => isset($_POST['bbp_anonymous_email']) ? $_POST['bbp_anonymous_email'] : null, 'sender_nickname' => isset($_POST['bbp_anonymous_name']) ? $_POST['bbp_anonymous_name'] : null, 'post_info' => $post_info, 'checkjs' => $checkjs, 'sender_info' => $sender_info)); $ct = $ct_base_call_result['ct']; $ct_result = $ct_base_call_result['ct_result']; if ($ct_result->stop_queue == 1 || $ct_result->spam == 1 || $ct_result->allow == 0 && $ct_result->stop_words !== null) { bbp_add_error('bbp_reply_content', $ct_result->comment); } return $comment; }
/** * @covers ::bbp_forum_last_topic_permalink * @covers ::bbp_get_forum_last_topic_permalink */ public function test_bbp_get_forum_last_topic_permalink() { if (is_multisite()) { $this->markTestSkipped('Skipping URL tests in multisite for now.'); } $c = $this->factory->forum->create(array('forum_meta' => array('forum_type' => 'category', 'status' => 'open'))); $f = $this->factory->forum->create(array('post_parent' => $c, 'forum_meta' => array('forum_id' => $c, 'forum_type' => 'forum', 'status' => 'open'))); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); // Get the forums last topic permalink. $forum_last_topic_permalink = bbp_get_forum_last_topic_permalink($f); $this->assertSame(bbp_get_topic_permalink($t), $forum_last_topic_permalink); // Get the categories last topic permalink. $forum_last_topic_permalink = bbp_get_forum_last_topic_permalink($c); $this->assertSame(bbp_get_topic_permalink($t), $forum_last_topic_permalink); }
/** * Handles the front end reporting/un-reporting of topics * * @since 1.0.0 * * @param string $action The requested action to compare this function to */ public function toggle_topic_handler($action = '') { // Bail if required GET actions aren't passed if (empty($_GET['topic_id'])) { return; } // Setup possible get actions $possible_actions = array('bbp_rc_toggle_topic_report'); // Bail if actions aren't meant for this function if (!in_array($action, $possible_actions)) { return; } $failure = ''; // Empty failure string $view_all = false; // Assume not viewing all $topic_id = (int) $_GET['topic_id']; // What's the topic id? $success = false; // Flag $post_data = array('ID' => $topic_id); // Prelim array $redirect = ''; // Empty redirect URL // Make sure topic exists $topic = bbp_get_topic($topic_id); if (empty($topic)) { return; } // Bail if non-logged-in user if (!is_user_logged_in()) { return; } // What action are we trying to perform? switch ($action) { // Toggle reported case 'bbp_rc_toggle_topic_report': check_ajax_referer('report-topic_' . $topic_id); $is_reported = $this->is_topic_reported($topic_id); $success = true === $is_reported ? $this->unreport_topic($topic_id) : $this->report_topic($topic_id); $failure = true === $is_reported ? __('<strong>ERROR</strong>: There was a problem unmarking the topic as reported.', 'bbpress-report-content') : __('<strong>ERROR</strong>: There was a problem reporting the topic.', 'bbpress-report-content'); // $view_all = !$is_reported; // Only need this if we want to hide it, like spam break; } // No errors if (false !== $success && !is_wp_error($success)) { // Redirect back to the topic's forum if (isset($sub_action) && 'delete' === $sub_action) { $redirect = bbp_get_forum_permalink($success->post_parent); // Redirect back to the topic } else { // Get the redirect destination $permalink = bbp_get_topic_permalink($topic_id); $redirect = bbp_add_view_all($permalink, $view_all); } wp_safe_redirect($redirect); // For good measure exit; // Handle errors } else { bbp_add_error('bbp_rc_toggle_topic', $failure); } }
/** * Runs through the various bbPress conditional tags to check the current page being viewed. Once * a condition is met, add items to the $items array. * * @since 0.6.0 * @access public * @return void */ public function do_trail_items() { /* Add the network and site home links. */ $this->do_network_home_link(); $this->do_site_home_link(); /* Get the forum post type object. */ $post_type_object = get_post_type_object(bbp_get_forum_post_type()); /* If not viewing the forum root/archive page and a forum archive exists, add it. */ if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { $this->items[] = '<a href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '">' . bbp_get_forum_archive_title() . '</a>'; } /* If viewing the forum root/archive. */ if (bbp_is_forum_archive()) { if (true === $this->args['show_title']) { $this->items[] = bbp_get_forum_archive_title(); } } elseif (bbp_is_topic_archive()) { if (true === $this->args['show_title']) { $this->items[] = bbp_get_topic_archive_title(); } } elseif (bbp_is_topic_tag()) { if (true === $this->args['show_title']) { $this->items[] = bbp_get_topic_tag_name(); } } elseif (bbp_is_topic_tag_edit()) { $this->items[] = '<a href="' . bbp_get_topic_tag_link() . '">' . bbp_get_topic_tag_name() . '</a>'; if (true === $this->args['show_title']) { $this->items[] = __('Edit', 'breadcrumb-trail'); } } elseif (bbp_is_single_view()) { if (true === $this->args['show_title']) { $this->items[] = bbp_get_view_title(); } } elseif (bbp_is_single_topic()) { /* Get the queried topic. */ $topic_id = get_queried_object_id(); /* Get the parent items for the topic, which would be its forum (and possibly forum grandparents). */ $this->do_post_parents(bbp_get_topic_forum_id($topic_id)); /* If viewing a split, merge, or edit topic page, show the link back to the topic. Else, display topic title. */ if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $this->items[] = '<a href="' . bbp_get_topic_permalink($topic_id) . '">' . bbp_get_topic_title($topic_id) . '</a>'; } elseif (true === $this->args['show_title']) { $this->items[] = bbp_get_topic_title($topic_id); } /* If viewing a topic split page. */ if (bbp_is_topic_split() && true === $this->args['show_title']) { $this->items[] = __('Split', 'breadcrumb-trail'); } elseif (bbp_is_topic_merge() && true === $this->args['show_title']) { $this->items[] = __('Merge', 'breadcrumb-trail'); } elseif (bbp_is_topic_edit() && true === $this->args['show_title']) { $this->items[] = __('Edit', 'breadcrumb-trail'); } } elseif (bbp_is_single_reply()) { /* Get the queried reply object ID. */ $reply_id = get_queried_object_id(); /* Get the parent items for the reply, which should be its topic. */ $this->do_post_parents(bbp_get_reply_topic_id($reply_id)); /* If viewing a reply edit page, link back to the reply. Else, display the reply title. */ if (bbp_is_reply_edit()) { $this->items[] = '<a href="' . bbp_get_reply_url($reply_id) . '">' . bbp_get_reply_title($reply_id) . '</a>'; if (true === $this->args['show_title']) { $this->items[] = __('Edit', 'breadcrumb-trail'); } } elseif (true === $this->args['show_title']) { $this->items[] = bbp_get_reply_title($reply_id); } } elseif (bbp_is_single_forum()) { /* Get the queried forum ID and its parent forum ID. */ $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); /* If the forum has a parent forum, get its parent(s). */ if (0 !== $forum_parent_id) { $this->do_post_parents($forum_parent_id); } /* Add the forum title to the end of the trail. */ if (true === $this->args['show_title']) { $this->items[] = bbp_get_forum_title($forum_id); } } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $this->items[] = '<a href="' . bbp_get_user_profile_url() . '">' . bbp_get_displayed_user_field('display_name') . '</a>'; if (true === $this->args['show_title']) { $this->items[] = __('Edit', 'breadcrumb-trail'); } } elseif (true === $this->args['show_title']) { $this->items[] = bbp_get_displayed_user_field('display_name'); } } /* Return the bbPress breadcrumb trail items. */ $this->items = apply_filters('breadcrumb_trail_get_bbpress_items', $this->items, $this->args); }
/** * User favorites link * * Return the link to make a topic favorite/remove a topic from * favorites * * @since bbPress (r2652) * * @param mixed $args This function supports these arguments: * - subscribe: Favorite text * - unsubscribe: Unfavorite text * - user_id: User id * - topic_id: Topic id * - before: Before the link * - after: After the link * @param int $user_id Optional. User id * @param int $topic_id Optional. Topic id * @param bool $wrap Optional. If you want to wrap the link in <span id="favorite-toggle">. See ajax_favorite() * @uses bbp_get_user_id() To get the user id * @uses current_user_can() If the current user can edit the user * @uses bbp_get_topic_id() To get the topic id * @uses bbp_is_user_favorite() To check if the topic is user's favorite * @uses bbp_get_favorites_permalink() To get the favorites permalink * @uses bbp_get_topic_permalink() To get the topic permalink * @uses bbp_is_favorites() Is it the favorites page? * @uses apply_filters() Calls 'bbp_get_user_favorites_link' with the * html, add args, remove args, user & topic id * @return string User favorites link */ function stachestack_bbp_get_user_favorites_link($args = '', $user_id = 0, $wrap = true) { if (!bbp_is_favorites_active()) { return false; } // Parse arguments against default values $r = bbp_parse_args($args, array('favorite' => __('Favorite', 'bbpress'), 'favorited' => __('Favorited', 'bbpress'), 'user_id' => 0, 'topic_id' => 0, 'before' => '', 'after' => ''), 'get_user_favorites_link'); // Validate user and topic ID's $user_id = bbp_get_user_id($r['user_id'], true, true); $topic_id = bbp_get_topic_id($r['topic_id']); if (empty($user_id) || empty($topic_id)) { return false; } // No link if you can't edit yourself if (!current_user_can('edit_user', (int) $user_id)) { return false; } // Decide which link to show $is_fav = bbp_is_user_favorite($user_id, $topic_id); if (!empty($is_fav)) { $text = $r['favorited']; $query_args = array('action' => 'bbp_favorite_remove', 'topic_id' => $topic_id); } else { $text = $r['favorite']; $query_args = array('action' => 'bbp_favorite_add', 'topic_id' => $topic_id); } // Create the link based where the user is and if the topic is // already the user's favorite if (bbp_is_favorites()) { $permalink = bbp_get_favorites_permalink($user_id); } elseif (bbp_is_single_topic() || bbp_is_single_reply()) { $permalink = bbp_get_topic_permalink($topic_id); } else { $permalink = get_permalink(); } $url = esc_url(wp_nonce_url(add_query_arg($query_args, $permalink), 'toggle-favorite_' . $topic_id)); $sub = $is_fav ? ' class="is-favorite"' : ''; $html = sprintf('%s<span id="favorite-%d" %s><a href="%s" class="btn btn-success btn-xs favorite-toggle" data-topic="%d">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $topic_id, $text, $r['after']); // Initial output is wrapped in a span, ajax output is hooked to this if (!empty($wrap)) { $html = '<span id="favorite-toggle">' . $html . '</span>'; } // Return the link return apply_filters('bbp_get_user_favorites_link', $html, $r, $user_id, $topic_id); }
/** * Return URL to the topic edit page * * @since 2.0.0 bbPress (r2753) * * @param int $topic_id Optional. Topic id * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_topic() To get the topic * @uses add_query_arg() To add custom args to the url * @uses apply_filters() Calls 'bbp_get_topic_edit_url' with the edit * url and topic id * @return string Topic edit url */ function bbp_get_topic_edit_url($topic_id = 0) { $topic = bbp_get_topic($topic_id); if (empty($topic)) { return; } // Remove view=all link from edit $topic_link = bbp_remove_view_all(bbp_get_topic_permalink($topic_id)); // Pretty permalinks if (bbp_use_pretty_urls()) { $url = trailingslashit($topic_link) . bbp_get_edit_rewrite_id(); $url = user_trailingslashit($url); // Unpretty permalinks } else { $url = add_query_arg(array(bbp_get_topic_post_type() => $topic->post_name, bbp_get_edit_rewrite_id() => '1'), $topic_link); } // Maybe add view=all $url = bbp_add_view_all($url); return apply_filters('bbp_get_topic_edit_url', $url, $topic_id); }
/** * Custom user feedback messages for reply post type * * @since 2.0.0 bbPress (r3080) * * @global int $post_ID * @uses bbp_get_topic_permalink() * @uses wp_post_revision_title() * @uses esc_url() * @uses add_query_arg() * * @param array $messages * * @return array */ public function updated_messages($messages) { global $post_ID; if ($this->bail()) { return $messages; } // URL for the current topic $topic_url = bbp_get_topic_permalink(bbp_get_reply_topic_id($post_ID)); // Current reply's post_date $post_date = bbp_get_global_post_field('post_date', 'raw'); // Messages array $messages[$this->post_type] = array(0 => '', 1 => sprintf(__('Reply updated. <a href="%s">View topic</a>', 'bbpress'), $topic_url), 2 => __('Custom field updated.', 'bbpress'), 3 => __('Custom field deleted.', 'bbpress'), 4 => __('Reply updated.', 'bbpress'), 5 => isset($_GET['revision']) ? sprintf(__('Reply restored to revision from %s', 'bbpress'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('Reply created. <a href="%s">View topic</a>', 'bbpress'), $topic_url), 7 => __('Reply saved.', 'bbpress'), 8 => sprintf(__('Reply submitted. <a target="_blank" href="%s">Preview topic</a>', 'bbpress'), esc_url(add_query_arg('preview', 'true', $topic_url))), 9 => sprintf(__('Reply scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview topic</a>', 'bbpress'), date_i18n(__('M j, Y @ G:i', 'bbpress'), strtotime($post_date)), $topic_url), 10 => sprintf(__('Reply draft updated. <a target="_blank" href="%s">Preview topic</a>', 'bbpress'), esc_url(add_query_arg('preview', 'true', $topic_url)))); return $messages; }
/** * Return a breadcrumb ( forum -> topic -> reply ) * * @since bbPress (r2589) * * @param string $sep Separator. Defaults to '←' * @param bool $current_page Include the current item * @param bool $root Include the root page if one exists * * @uses get_post() To get the post * @uses bbp_get_forum_permalink() To get the forum link * @uses bbp_get_topic_permalink() To get the topic link * @uses bbp_get_reply_permalink() To get the reply link * @uses get_permalink() To get the permalink * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses bbp_get_forum_title() To get the forum title * @uses bbp_get_topic_title() To get the topic title * @uses bbp_get_reply_title() To get the reply title * @uses get_the_title() To get the title * @uses apply_filters() Calls 'bbp_get_breadcrumb' with the crumbs * @return string Breadcrumbs */ function bbp_get_breadcrumb($args = array()) { // Turn off breadcrumbs if (apply_filters('bbp_no_breadcrumb', is_front_page())) { return; } // Define variables $front_id = $root_id = 0; $ancestors = $crumbs = $tag_data = array(); $pre_root_text = $pre_front_text = $pre_current_text = ''; $pre_include_root = $pre_include_home = $pre_include_current = true; /** Home Text *********************************************************/ // No custom home text if (empty($args['home_text'])) { // Set home text to page title $front_id = get_option('page_on_front'); if (!empty($front_id)) { $pre_front_text = get_the_title($front_id); // Default to 'Home' } else { $pre_front_text = __('Home', 'bbpress'); } } /** Root Text *********************************************************/ // No custom root text if (empty($args['root_text'])) { $page = bbp_get_page_by_path(bbp_get_root_slug()); if (!empty($page)) { $root_id = $page->ID; } $pre_root_text = bbp_get_forum_archive_title(); } /** Includes **********************************************************/ // Root slug is also the front page if (!empty($front_id) && $front_id == $root_id) { $pre_include_root = false; } // Don't show root if viewing forum archive if (bbp_is_forum_archive()) { $pre_include_root = false; } // Don't show root if viewing page in place of forum archive if (!empty($root_id) && ((is_single() || is_page()) && $root_id == get_the_ID())) { $pre_include_root = false; } /** Current Text ******************************************************/ // Forum archive if (bbp_is_forum_archive()) { $pre_current_text = bbp_get_forum_archive_title(); // Topic archive } elseif (bbp_is_topic_archive()) { $pre_current_text = bbp_get_topic_archive_title(); // View } elseif (bbp_is_single_view()) { $pre_current_text = bbp_get_view_title(); // Single Forum } elseif (bbp_is_single_forum()) { $pre_current_text = bbp_get_forum_title(); // Single Topic } elseif (bbp_is_single_topic()) { $pre_current_text = bbp_get_topic_title(); // Single Topic } elseif (bbp_is_single_reply()) { $pre_current_text = bbp_get_reply_title(); // Topic Tag (or theme compat topic tag) } elseif (bbp_is_topic_tag() || get_query_var('bbp_topic_tag') && !bbp_is_topic_tag_edit()) { // Always include the tag name $tag_data[] = bbp_get_topic_tag_name(); // If capable, include a link to edit the tag if (current_user_can('manage_topic_tags')) { $tag_data[] = '<a href="' . bbp_get_topic_tag_edit_link() . '" class="bbp-edit-topic-tag-link">' . __('(Edit)', 'bbpress') . '</a>'; } // Implode the results of the tag data $pre_current_text = sprintf(__('Topic Tag: %s', 'bbpress'), implode(' ', $tag_data)); // Edit Topic Tag } elseif (bbp_is_topic_tag_edit()) { $pre_current_text = __('Edit', 'bbpress'); // Single } else { $pre_current_text = get_the_title(); } /** Parse Args ********************************************************/ // Parse args $defaults = array('before' => '<div class="bbp-breadcrumb"><p>', 'after' => '</p></div>', 'sep' => __('›', 'bbpress'), 'pad_sep' => 1, 'include_home' => $pre_include_home, 'home_text' => $pre_front_text, 'include_root' => $pre_include_root, 'root_text' => $pre_root_text, 'include_current' => $pre_include_current, 'current_text' => $pre_current_text); $r = bbp_parse_args($args, $defaults, 'get_breadcrumb'); extract($r); /** Ancestors *********************************************************/ // Get post ancestors if (is_page() || is_single() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit()) { $ancestors = array_reverse(get_post_ancestors(get_the_ID())); } // Do we want to include a link to home? if (!empty($include_home) || empty($home_text)) { $crumbs[] = '<a href="' . trailingslashit(home_url()) . '" class="bbp-breadcrumb-home">' . $home_text . '</a>'; } // Do we want to include a link to the forum root? if (!empty($include_root) || empty($root_text)) { // Page exists at root slug path, so use its permalink $page = bbp_get_page_by_path(bbp_get_root_slug()); if (!empty($page)) { $root_url = get_permalink($page->ID); // Use the root slug } else { $root_url = get_post_type_archive_link(bbp_get_forum_post_type()); } // Add the breadcrumb $crumbs[] = '<a href="' . $root_url . '" class="bbp-breadcrumb-root">' . $root_text . '</a>'; } // Ancestors exist if (!empty($ancestors)) { // Loop through parents foreach ((array) $ancestors as $parent_id) { // Parents $parent = get_post($parent_id); // Switch through post_type to ensure correct filters are applied switch ($parent->post_type) { // Forum case bbp_get_forum_post_type(): $crumbs[] = '<a href="' . bbp_get_forum_permalink($parent->ID) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title($parent->ID) . '</a>'; break; // Topic // Topic case bbp_get_topic_post_type(): $crumbs[] = '<a href="' . bbp_get_topic_permalink($parent->ID) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title($parent->ID) . '</a>'; break; // Reply (Note: not in most themes) // Reply (Note: not in most themes) case bbp_get_reply_post_type(): $crumbs[] = '<a href="' . bbp_get_reply_permalink($parent->ID) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title($parent->ID) . '</a>'; break; // WordPress Post/Page/Other // WordPress Post/Page/Other default: $crumbs[] = '<a href="' . get_permalink($parent->ID) . '" class="bbp-breadcrumb-item">' . get_the_title($parent->ID) . '</a>'; break; } } // Edit topic tag } elseif (bbp_is_topic_tag_edit()) { $crumbs[] = '<a href="' . get_term_link(bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id()) . '" class="bbp-breadcrumb-topic-tag">' . sprintf(__('Topic Tag: %s', 'bbpress'), bbp_get_topic_tag_name()) . '</a>'; } /** Current ***********************************************************/ // Add current page to breadcrumb if (!empty($include_current) || empty($pre_current_text)) { $crumbs[] = '<span class="bbp-breadcrumb-current">' . $current_text . '</span>'; } /** Separator *********************************************************/ // Wrap the separator in a span before padding and filter if (!empty($sep)) { $sep = '<span class="bbp-breadcrumb-separator">' . $sep . '</span>'; } // Pad the separator if (!empty($pad_sep)) { $sep = str_pad($sep, strlen($sep) + (int) $pad_sep * 2, ' ', STR_PAD_BOTH); } /** Finish Up *********************************************************/ // Filter the separator and breadcrumb $sep = apply_filters('bbp_breadcrumb_separator', $sep); $crumbs = apply_filters('bbp_breadcrumbs', $crumbs); // Build the trail $trail = !empty($crumbs) ? $before . implode($sep, $crumbs) . $after : ''; return apply_filters('bbp_get_breadcrumb', $trail, $crumbs, $r); }
/** * Redirect if unathorized user is attempting to edit a topic * * @since bbPress (r3605) * * @uses bbp_is_topic_edit() * @uses current_user_can() * @uses bbp_get_topic_id() * @uses wp_safe_redirect() * @uses bbp_get_topic_permalink() */ function bbp_check_topic_edit() { // Bail if not editing a topic if (!bbp_is_topic_edit()) { return; } // User cannot edit topic, so redirect back to topic if (!current_user_can('edit_topic', bbp_get_topic_id())) { wp_safe_redirect(bbp_get_topic_permalink()); exit; } }
/** * Return the paginated url to the reply in the reply loop * * @since bbPress (r2679) * * @param int $reply_id Optional. Reply id * @param $string $redirect_to Optional. Pass a redirect value for use with * shortcodes and other fun things. * @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_topic_permalink() To get the topic permalink * @uses bbp_get_reply_position() To get the reply position * @uses get_option() To get the replies per page option * @uses WP_Rewrite::using_permalinks() To check if the blog uses * permalinks * @uses add_query_arg() To add custom args to the url * @uses apply_filters() Calls 'bbp_get_reply_url' with the reply url, * reply id and bool count hidden * @return string Link to reply relative to paginated topic */ function bbp_get_reply_url($reply_id = 0, $redirect_to = '') { // Set needed variables $reply_id = bbp_get_reply_id($reply_id); $topic_id = bbp_get_reply_topic_id($reply_id); // Hierarchical reply page if (bbp_thread_replies()) { $reply_page = 1; // Standard reply page } else { $reply_page = ceil((int) bbp_get_reply_position($reply_id, $topic_id) / (int) bbp_get_replies_per_page()); } $reply_hash = '#post-' . $reply_id; $topic_link = bbp_get_topic_permalink($topic_id, $redirect_to); $topic_url = remove_query_arg('view', $topic_link); // Don't include pagination if on first page if (1 >= $reply_page) { $url = trailingslashit($topic_url) . $reply_hash; // Include pagination } else { global $wp_rewrite; // Pretty permalinks if ($wp_rewrite->using_permalinks()) { $url = trailingslashit($topic_url) . trailingslashit($wp_rewrite->pagination_base) . trailingslashit($reply_page) . $reply_hash; // Yucky links } else { $url = add_query_arg('paged', $reply_page, $topic_url) . $reply_hash; } } // Add topic view query arg back to end if it is set if (bbp_get_view_all()) { $url = bbp_add_view_all($url); } return apply_filters('bbp_get_reply_url', $url, $reply_id, $redirect_to); }
function build_html() { // Store everything in an output buffer ob_start(); ?> <div class="widget showcase-widget"> <header class="widget-header"> <h3 class="widget-title">Recent Discussion</h3> </header> <ul class="recent-discussion-list"> <?php // Iterate topics while (bp_activities()) { bp_the_activity(); // Get the activity user $user = new Apoc_User(bp_get_activity_user_id(), 'directory', 40); // Get the activity type $type = bp_get_activity_type(); // Format activity based on context switch ($type) { case 'bbp_topic_create': $topic_id = bp_get_activity_item_id(); $link = '<a href="' . bbp_get_topic_permalink($topic_id) . '" title="Read topic" target="_blank">' . bbp_get_topic_title($topic_id) . '</a>'; $verb = 'created topic'; break; case 'bbp_reply_create': $reply_id = bp_get_activity_secondary_item_id(); $link = '<a href="' . bbp_get_topic_last_reply_url($reply_id) . '" title="Read reply" target="_blank">' . bbp_get_topic_title($reply_id) . '</a>'; $verb = 'replied to'; break; case 'new_blog_comment': $comment_id = bp_get_activity_secondary_item_id(); $comment = get_comment($comment_id); $link = '<a href="' . get_comment_link($comment_id) . '" title="Read reply" target="_blank">' . get_the_title($comment->comment_post_ID) . '</a>'; $verb = 'commented on'; break; } // Get the activity time $time = bp_core_time_since(bp_get_activity_date_recorded()); // Output the HTML ?> <li class="recent-discussion double-border"> <?php echo $user->avatar; ?> <div class="recent-discussion-content"> <span class="recent-discussion-title"><?php echo $user->link . ' ' . $verb . ' ' . $link; ?> </span> <span class="recent-discussion-time"><?php echo $time; ?> </div> </li> <?php } ?> </ul> </div><?php // Get the contents of the buffer $html = ob_get_contents(); ob_end_clean(); // Return the html to the class return $html; }
/** * Handles the front end subscribing and unsubscribing topics * * @uses bbp_is_subscriptions_active() To check if the subscriptions are active * @uses bbp_get_user_id() To get the user id * @uses bbp_verify_nonce_request() To verify the nonce and check the request * @uses current_user_can() To check if the current user can edit the user * @uses bbPress:errors:add() To log the error messages * @uses bbp_is_user_subscribed() To check if the topic is in user's * subscriptions * @uses bbp_remove_user_subscription() To remove the user subscription * @uses bbp_add_user_subscription() To add the user subscription * @uses do_action() Calls 'bbp_subscriptions_handler' with success, user id, * topic id and action * @uses bbp_is_subscription() To check if it's the subscription page * @uses bbp_get_subscription_link() To get the subscription page link * @uses bbp_get_topic_permalink() To get the topic permalink * @uses wp_safe_redirect() To redirect to the url */ function bbp_subscriptions_handler() { if (!bbp_is_subscriptions_active()) { return false; } // Bail if not a GET action if ('GET' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } // Bail if required GET actions aren't passed if (empty($_GET['topic_id']) || empty($_GET['action'])) { return; } // Setup possible get actions $possible_actions = array('bbp_subscribe', 'bbp_unsubscribe'); // Bail if actions aren't meant for this function if (!in_array($_GET['action'], $possible_actions)) { return; } // Get required data $action = $_GET['action']; $user_id = bbp_get_user_id(0, true, true); $topic_id = intval($_GET['topic_id']); // Check for empty topic if (empty($topic_id)) { bbp_add_error('bbp_subscription_topic_id', __('<strong>ERROR</strong>: No topic was found! Which topic are you subscribing/unsubscribing to?', 'bbpress')); // Check nonce } elseif (!bbp_verify_nonce_request('toggle-subscription_' . $topic_id)) { bbp_add_error('bbp_subscription_topic_id', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress')); // Check current user's ability to edit the user } elseif (!current_user_can('edit_user', $user_id)) { bbp_add_error('bbp_subscription_permissions', __('<strong>ERROR</strong>: You don\'t have the permission to edit favorites of that user!', 'bbpress')); } // Bail if we have errors if (bbp_has_errors()) { return; } /** No errors *************************************************************/ $is_subscription = bbp_is_user_subscribed($user_id, $topic_id); $success = false; if (true == $is_subscription && 'bbp_unsubscribe' == $action) { $success = bbp_remove_user_subscription($user_id, $topic_id); } elseif (false == $is_subscription && 'bbp_subscribe' == $action) { $success = bbp_add_user_subscription($user_id, $topic_id); } // Do additional subscriptions actions do_action('bbp_subscriptions_handler', $success, $user_id, $topic_id, $action); // Success! if (true == $success) { // Redirect back from whence we came if (bbp_is_subscriptions()) { $redirect = bbp_get_subscriptions_permalink($user_id); } elseif (bbp_is_single_user()) { $redirect = bbp_get_user_profile_url(); } elseif (is_singular(bbp_get_topic_post_type())) { $redirect = bbp_get_topic_permalink($topic_id); } elseif (is_single() || is_page()) { $redirect = get_permalink(); } wp_safe_redirect($redirect); // For good measure exit; // Fail! Handle errors } elseif (true == $is_subscription && 'bbp_unsubscribe' == $action) { bbp_add_error('bbp_unsubscribe', __('<strong>ERROR</strong>: There was a problem unsubscribing from that topic!', 'bbpress')); } elseif (false == $is_subscription && 'bbp_subscribe' == $action) { bbp_add_error('bbp_subscribe', __('<strong>ERROR</strong>: There was a problem subscribing to that topic!', 'bbpress')); } }
/** * send_notification() * * Send the notification e-mails to the addresses defined in options */ function send_notification($topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0) { // Grab stuff we will be needing for the email $recipients = $this->get_recipients(); $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $topic_title = html_entity_decode(strip_tags(bbp_get_topic_title($topic_id)), ENT_NOQUOTES, 'UTF-8'); $topic_content = html_entity_decode(strip_tags(bbp_get_topic_content($topic_id)), ENT_NOQUOTES, 'UTF-8'); $topic_excerpt = html_entity_decode(strip_tags(bbp_get_topic_excerpt($topic_id, 100)), ENT_NOQUOTES, 'UTF-8'); $topic_author = bbp_get_topic_author($topic_id); $topic_url = bbp_get_topic_permalink($topic_id); // Get the template $email_template = get_option('ja_bbp_notification_email_template'); // Swap out the shortcodes with useful information :) $find = array('[topic-title]', '[topic-content]', '[topic-excerpt]', '[topic-author]', '[topic-url]'); $replace = array($topic_title, $topic_content, $topic_excerpt, $topic_author, $topic_url); $email_body = str_replace($find, $replace, $email_template); $email_subject = $blogname . __(' new topic', 'ja_bbp_notifications') . ' - ' . $topic_title; if (!empty($recipients)) { // Send email to each user foreach ($recipients as $recipient) { @wp_mail($recipient, $email_subject, $email_body); } } }
/** * Return the link to subscribe/unsubscribe from a forum or topic * * @since 2.0.0 bbPress (r2668) * * @param array $args This function supports these arguments: * - subscribe: Subscribe text * - unsubscribe: Unsubscribe text * - user_id: User id * - topic_id: Topic id * - forum_id: Forum id * - before: Before the link * - after: After the link * @param int $user_id Optional. User id * @param bool $wrap Optional. If you want to wrap the link in <span id="subscription-toggle">. * @uses bbp_is_subscriptions_active() to check if subscriptions are active * @uses bbp_get_user_id() To get the user id * @uses bbp_get_user_id() To get the user id * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_forum_id() To get the forum id * @uses current_user_can() To check if the current user can edit user * @uses bbp_is_user_subscribed_to_forum() To check if the user is subscribed to the forum * @uses bbp_is_user_subscribed_to_topic() To check if the user is subscribed to the topic * @uses bbp_is_subscriptions() To check if it's the subscriptions page * @uses bbp_get_subscriptions_permalink() To get subscriptions link * @uses bbp_get_topic_permalink() To get topic link * @uses apply_filters() Calls 'bbp_get_user_subscribe_link' with the * link, args, user id & topic id * @return string Permanent link to topic */ function bbp_get_user_subscribe_link($args = array(), $user_id = 0, $wrap = true) { if (!bbp_is_subscriptions_active()) { return; } // Parse arguments against default values $r = bbp_parse_args($args, array('subscribe' => __('Subscribe', 'bbpress'), 'unsubscribe' => __('Unsubscribe', 'bbpress'), 'user_id' => 0, 'topic_id' => 0, 'forum_id' => 0, 'before' => ' | ', 'after' => ''), 'get_user_subscribe_link'); // Validate user and object ID's $user_id = bbp_get_user_id($r['user_id'], true, true); $topic_id = bbp_get_topic_id($r['topic_id']); $forum_id = bbp_get_forum_id($r['forum_id']); if (empty($user_id) || empty($topic_id) && empty($forum_id)) { return false; } // No link if you can't edit yourself if (!current_user_can('edit_user', $user_id)) { return false; } // Check if viewing a single forum if (empty($topic_id) && !empty($forum_id)) { // Decide which link to show $is_subscribed = bbp_is_user_subscribed_to_forum($user_id, $forum_id); if (!empty($is_subscribed)) { $text = $r['unsubscribe']; $query_args = array('action' => 'bbp_unsubscribe', 'forum_id' => $forum_id); } else { $text = $r['subscribe']; $query_args = array('action' => 'bbp_subscribe', 'forum_id' => $forum_id); } // Create the link based where the user is and if the user is // subscribed already if (bbp_is_subscriptions()) { $permalink = bbp_get_subscriptions_permalink($user_id); } elseif (bbp_is_single_forum() || bbp_is_single_reply()) { $permalink = bbp_get_forum_permalink($forum_id); } else { $permalink = get_permalink(); } $url = esc_url(wp_nonce_url(add_query_arg($query_args, $permalink), 'toggle-subscription_' . $forum_id)); $sub = $is_subscribed ? ' class="is-subscribed"' : ''; $html = sprintf('%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-forum="%d">%s</a></span>%s', $r['before'], $forum_id, $sub, $url, $forum_id, $text, $r['after']); // Initial output is wrapped in a span, ajax output is hooked to this if (!empty($wrap)) { $html = '<span id="subscription-toggle">' . $html . '</span>'; } } else { // Decide which link to show $is_subscribed = bbp_is_user_subscribed_to_topic($user_id, $topic_id); if (!empty($is_subscribed)) { $text = $r['unsubscribe']; $query_args = array('action' => 'bbp_unsubscribe', 'topic_id' => $topic_id); } else { $text = $r['subscribe']; $query_args = array('action' => 'bbp_subscribe', 'topic_id' => $topic_id); } // Create the link based where the user is and if the user is // subscribed already if (bbp_is_subscriptions()) { $permalink = bbp_get_subscriptions_permalink($user_id); } elseif (bbp_is_single_topic() || bbp_is_single_reply()) { $permalink = bbp_get_topic_permalink($topic_id); } else { $permalink = get_permalink(); } $url = esc_url(wp_nonce_url(add_query_arg($query_args, $permalink), 'toggle-subscription_' . $topic_id)); $sub = $is_subscribed ? ' class="is-subscribed"' : ''; $html = sprintf('%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-topic="%d">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $topic_id, $text, $r['after']); // Initial output is wrapped in a span, ajax output is hooked to this if (!empty($wrap)) { $html = '<span id="subscription-toggle">' . $html . '</span>'; } } // Return the link return apply_filters('bbp_get_user_subscribe_link', $html, $r, $user_id, $topic_id); }
/** * Move reply handler * * Handles the front end move reply submission * * @since bbPress (r4521) * * @param string $action The requested action to compare this function to * @uses bbp_add_error() To add an error message * @uses bbp_get_reply() To get the reply * @uses bbp_get_topic() To get the topics * @uses bbp_verify_nonce_request() To verify the nonce and check the request * @uses current_user_can() To check if the current user can edit the reply and topics * @uses bbp_get_topic_post_type() To get the topic post type * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error} * @uses do_action() Calls 'bbp_pre_move_reply' with the from reply id, source * and destination topic ids * @uses bbp_get_reply_post_type() To get the reply post type * @uses wpdb::prepare() To prepare our sql query * @uses wpdb::get_results() To execute the sql query and get results * @uses wp_update_post() To update the replies * @uses bbp_update_reply_topic_id() To update the reply topic id * @uses bbp_get_topic_forum_id() To get the topic forum id * @uses bbp_update_reply_forum_id() To update the reply forum id * @uses do_action() Calls 'bbp_split_topic_reply' with the reply id and * destination topic id * @uses bbp_update_topic_last_reply_id() To update the topic last reply id * @uses bbp_update_topic_last_active_time() To update the topic last active meta * @uses do_action() Calls 'bbp_post_split_topic' with the destination and * source topic ids and source topic's forum id * @uses bbp_get_topic_permalink() To get the topic permalink * @uses wp_safe_redirect() To redirect to the topic link */ function bbp_move_reply_handler($action = '') { // Bail if action is not 'bbp-move-reply' if ('bbp-move-reply' !== $action) { return; } // Prevent debug notices $move_reply_id = $destination_topic_id = 0; $destination_topic_title = ''; $destination_topic = $move_reply = $source_topic = ''; /** Move Reply ***********************************************************/ if (empty($_POST['bbp_reply_id'])) { bbp_add_error('bbp_move_reply_reply_id', __('<strong>ERROR</strong>: Reply ID to move not found!', 'bbpress')); } else { $move_reply_id = (int) $_POST['bbp_reply_id']; } $move_reply = bbp_get_reply($move_reply_id); // Reply exists if (empty($move_reply)) { bbp_add_error('bbp_mover_reply_r_not_found', __('<strong>ERROR</strong>: The reply you want to move was not found.', 'bbpress')); } /** Topic to Move From ***************************************************/ // Get the reply's current topic $source_topic = bbp_get_topic($move_reply->post_parent); // No topic if (empty($source_topic)) { bbp_add_error('bbp_move_reply_source_not_found', __('<strong>ERROR</strong>: The topic you want to move from was not found.', 'bbpress')); } // Nonce check failed if (!bbp_verify_nonce_request('bbp-move-reply_' . $move_reply->ID)) { bbp_add_error('bbp_move_reply_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress')); return; } // Use cannot edit topic if (!current_user_can('edit_topic', $source_topic->ID)) { bbp_add_error('bbp_move_reply_source_permission', __('<strong>ERROR</strong>: You do not have the permissions to edit the source topic.', 'bbpress')); } // How to move if (!empty($_POST['bbp_reply_move_option'])) { $move_option = (string) trim($_POST['bbp_reply_move_option']); } // Invalid move option if (empty($move_option) || !in_array($move_option, array('existing', 'topic'))) { bbp_add_error('bbp_move_reply_option', __('<strong>ERROR</strong>: You need to choose a valid move option.', 'bbpress')); // Valid move option } else { // What kind of move switch ($move_option) { // Into an existing topic case 'existing': // Get destination topic id if (empty($_POST['bbp_destination_topic'])) { bbp_add_error('bbp_move_reply_destination_id', __('<strong>ERROR</strong>: Destination topic ID not found!', 'bbpress')); } else { $destination_topic_id = (int) $_POST['bbp_destination_topic']; } // Get the destination topic $destination_topic = bbp_get_topic($destination_topic_id); // No destination topic if (empty($destination_topic)) { bbp_add_error('bbp_move_reply_destination_not_found', __('<strong>ERROR</strong>: The topic you want to move to was not found!', 'bbpress')); } // User cannot edit the destination topic if (!current_user_can('edit_topic', $destination_topic->ID)) { bbp_add_error('bbp_move_reply_destination_permission', __('<strong>ERROR</strong>: You do not have the permissions to edit the destination topic!', 'bbpress')); } // Bump the reply position $reply_position = bbp_get_topic_reply_count($destination_topic->ID) + 1; // Update the reply wp_update_post(array('ID' => $move_reply->ID, 'post_title' => sprintf(__('Reply To: %s', 'bbpress'), $destination_topic->post_title), 'post_name' => false, 'post_parent' => $destination_topic->ID, 'menu_order' => $reply_position, 'guid' => '')); // Adjust reply meta values bbp_update_reply_topic_id($move_reply->ID, $destination_topic->ID); bbp_update_reply_forum_id($move_reply->ID, bbp_get_topic_forum_id($destination_topic->ID)); break; // Move reply to a new topic // Move reply to a new topic case 'topic': default: // User needs to be able to publish topics if (current_user_can('publish_topics')) { // Use the new title that was passed if (!empty($_POST['bbp_reply_move_destination_title'])) { $destination_topic_title = esc_attr(strip_tags($_POST['bbp_reply_move_destination_title'])); // Use the source topic title } else { $destination_topic_title = $source_topic->post_title; } // Update the topic $destination_topic_id = wp_update_post(array('ID' => $move_reply->ID, 'post_title' => $destination_topic_title, 'post_name' => false, 'post_type' => bbp_get_topic_post_type(), 'post_parent' => $source_topic->post_parent, 'guid' => '')); $destination_topic = bbp_get_topic($destination_topic_id); // Make sure the new topic knows its a topic bbp_update_topic_topic_id($move_reply->ID); // Shouldn't happen if (false === $destination_topic_id || is_wp_error($destination_topic_id) || empty($destination_topic)) { bbp_add_error('bbp_move_reply_destination_reply', __('<strong>ERROR</strong>: There was a problem converting the reply into the topic. Please try again.', 'bbpress')); } // User cannot publish posts } else { bbp_add_error('bbp_move_reply_destination_permission', __('<strong>ERROR</strong>: You do not have the permissions to create new topics. The reply could not be converted into a topic.', 'bbpress')); } break; } } // Bail if there are errors if (bbp_has_errors()) { return; } /** No Errors - Clean Up **************************************************/ // Update counts, etc... do_action('bbp_pre_move_reply', $move_reply->ID, $source_topic->ID, $destination_topic->ID); /** Date Check ************************************************************/ // Check if the destination topic is older than the move reply if (strtotime($move_reply->post_date) < strtotime($destination_topic->post_date)) { // Set destination topic post_date to 1 second before from reply $destination_post_date = date('Y-m-d H:i:s', strtotime($move_reply->post_date) - 1); // Update destination topic wp_update_post(array('ID' => $destination_topic_id, 'post_date' => $destination_post_date, 'post_date_gmt' => get_gmt_from_date($destination_post_date))); } // Set the last reply ID and freshness to the move_reply $last_reply_id = $move_reply->ID; $freshness = $move_reply->post_date; // Get the reply to $parent = bbp_get_reply_to($move_reply->ID); // Fix orphaned children $children = get_posts(array('post_type' => bbp_get_reply_post_type(), 'meta_key' => '_bbp_reply_to', 'meta_value' => $move_reply->ID)); foreach ($children as $child) { bbp_update_reply_to($child->ID, $parent); } // Remove reply_to from moved reply delete_post_meta($move_reply->ID, '_bbp_reply_to'); // It is a new topic and we need to set some default metas to make // the topic display in bbp_has_topics() list if ('topic' === $move_option) { bbp_update_topic_last_reply_id($destination_topic->ID, $last_reply_id); bbp_update_topic_last_active_id($destination_topic->ID, $last_reply_id); bbp_update_topic_last_active_time($destination_topic->ID, $freshness); // Otherwise update the existing destination topic } else { bbp_update_topic_last_reply_id($destination_topic->ID); bbp_update_topic_last_active_id($destination_topic->ID); bbp_update_topic_last_active_time($destination_topic->ID); } // Update source topic ID last active bbp_update_topic_last_reply_id($source_topic->ID); bbp_update_topic_last_active_id($source_topic->ID); bbp_update_topic_last_active_time($source_topic->ID); /** Successful Move ******************************************************/ // Update counts, etc... do_action('bbp_post_move_reply', $move_reply->ID, $source_topic->ID, $destination_topic->ID); // Redirect back to the topic wp_safe_redirect(bbp_get_topic_permalink($destination_topic->ID)); // For good measure exit; }
function new_reply_notification($reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0, $is_edit = false, $reply_to = 0) { $admin_email = get_option('admin_email'); $user_id = (int) $reply_author_id; $reply_id = bbp_get_reply_id($reply_id); $topic_id = bbp_get_topic_id($topic_id); $forum_id = bbp_get_forum_id($forum_id); $email_subject = get_option('bbpress_notify_newreply_email_subject'); $email_body = get_option('bbpress_notify_newreply_email_body'); $blog_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $topic_title = html_entity_decode(strip_tags(bbp_get_topic_title($topic_id)), ENT_NOQUOTES, 'UTF-8'); $topic_content = html_entity_decode(strip_tags(bbp_get_topic_content($topic_id)), ENT_NOQUOTES, 'UTF-8'); $topic_excerpt = html_entity_decode(strip_tags(bbp_get_topic_excerpt($topic_id, 100)), ENT_NOQUOTES, 'UTF-8'); $topic_author = bbp_get_topic_author($topic_id); $topic_url = bbp_get_topic_permalink($topic_id); $topic_reply = bbp_get_reply_url($topic_id); $reply_url = bbp_get_reply_url($reply_id); $reply_content = get_post_field('post_content', $reply_id, 'raw'); $reply_author = bbp_get_topic_author($user_id); $email_subject = $blog_name . " New Reply Alert: " . $topic_title; $email_body = $blog_name . ": {$topic_title}\n\r"; $email_body .= $reply_content; $email_body .= "\n\r--------------------------------\n\r"; $email_body .= "Reply Url: " . $reply_url . "\n\rAuthor: {$reply_author}" . "\n\rYou can reply at: {$reply_url}"; @wp_mail($admin_email, $email_subject, $email_body); }