示例#1
0
/**
 * Return the trash link of the topic
 *
 * @since 2.0.0 bbPress (r2727)
 *
 * @param array $args This function supports these args:
 *  - id: Optional. Topic id
 *  - link_before: Before the link
 *  - link_after: After the link
 *  - sep: Links separator
 *  - trash_text: Trash text
 *  - restore_text: Restore text
 *  - delete_text: Delete text
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_topic() To get the topic
 * @uses current_user_can() To check if the current user can delete the
 *                           topic
 * @uses bbp_is_topic_trash() To check if the topic is trashed
 * @uses bbp_get_topic_status() To get the topic status
 * @uses add_query_arg() To add custom args to the url
 * @uses wp_nonce_url() To nonce the url
 * @uses esc_url() To escape the url
 * @uses apply_filters() Calls 'bbp_get_topic_trash_link' with the link
 *                        and args
 * @return string Topic trash link
 */
function bbp_get_topic_trash_link($args = array())
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('id' => 0, 'link_before' => '', 'link_after' => '', 'sep' => ' | ', 'trash_text' => esc_html__('Trash', 'bbpress'), 'restore_text' => esc_html__('Restore', 'bbpress'), 'delete_text' => esc_html__('Delete', 'bbpress')), 'get_topic_trash_link');
    $topic = bbp_get_topic($r['id']);
    if (empty($topic) || !current_user_can('delete_topic', $topic->ID)) {
        return;
    }
    $actions = array();
    if (bbp_is_topic_trash($topic->ID)) {
        $actions['untrash'] = '<a title="' . esc_attr__('Restore this item from the Trash', 'bbpress') . '" href="' . esc_url(wp_nonce_url(add_query_arg(array('action' => 'bbp_toggle_topic_trash', 'sub_action' => 'untrash', 'topic_id' => $topic->ID)), 'untrash-' . $topic->post_type . '_' . $topic->ID)) . '" class="bbp-topic-restore-link">' . $r['restore_text'] . '</a>';
    } elseif (EMPTY_TRASH_DAYS) {
        $actions['trash'] = '<a title="' . esc_attr__('Move this item to the Trash', 'bbpress') . '" href="' . esc_url(wp_nonce_url(add_query_arg(array('action' => 'bbp_toggle_topic_trash', 'sub_action' => 'trash', 'topic_id' => $topic->ID)), 'trash-' . $topic->post_type . '_' . $topic->ID)) . '" class="bbp-topic-trash-link">' . $r['trash_text'] . '</a>';
    }
    if (bbp_is_topic_trash($topic->ID) || !EMPTY_TRASH_DAYS) {
        $actions['delete'] = '<a title="' . esc_attr__('Delete this item permanently', 'bbpress') . '" href="' . esc_url(wp_nonce_url(add_query_arg(array('action' => 'bbp_toggle_topic_trash', 'sub_action' => 'delete', 'topic_id' => $topic->ID)), 'delete-' . $topic->post_type . '_' . $topic->ID)) . '" onclick="return confirm(\'' . esc_js(__('Are you sure you want to delete that permanently?', 'bbpress')) . '\' );" class="bbp-topic-delete-link">' . $r['delete_text'] . '</a>';
    }
    // Process the admin links
    $retval = $r['link_before'] . implode($r['sep'], $actions) . $r['link_after'];
    return apply_filters('bbp_get_topic_trash_link', $retval, $r, $args);
}
/**
 * Handles the front end reply submission
 *
 * @since bbPress (r2574)
 *
 * @param string $action The requested action to compare this function to
 * @uses bbp_add_error() To add an error message
 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
 * @uses bbp_is_anonymous() To check if an anonymous post is being made
 * @uses current_user_can() To check if the current user can publish replies
 * @uses bbp_get_current_user_id() To get the current user id
 * @uses bbp_filter_anonymous_post_data() To filter anonymous data
 * @uses bbp_set_current_anonymous_user_data() To set the anonymous user
 *                                                cookies
 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
 * @uses remove_filter() To remove kses filters if needed
 * @uses esc_attr() For sanitization
 * @uses bbp_check_for_flood() To check for flooding
 * @uses bbp_check_for_duplicate() To check for duplicates
 * @uses apply_filters() Calls 'bbp_new_reply_pre_title' with the title
 * @uses apply_filters() Calls 'bbp_new_reply_pre_content' with the content
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses wp_set_post_terms() To set the topic tags
 * @uses wp_insert_post() To insert the reply
 * @uses do_action() Calls 'bbp_new_reply' with the reply id, topic id, forum
 *                    id, anonymous data, reply author, edit (false), and
 *                    the reply to id
 * @uses bbp_get_reply_url() To get the paginated url to the reply
 * @uses wp_safe_redirect() To redirect to the reply url
 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error
 *                                              message
 */
function bbp_new_reply_handler($action = '')
{
    // Bail if action is not bbp-new-reply
    if ('bbp-new-reply' !== $action) {
        return;
    }
    // Nonce check
    if (!bbp_verify_nonce_request('bbp-new-reply')) {
        bbp_add_error('bbp_new_reply_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
        return;
    }
    // Define local variable(s)
    $topic_id = $forum_id = $reply_author = $anonymous_data = $reply_to = 0;
    $reply_title = $reply_content = $terms = '';
    /** Reply Author **********************************************************/
    // User is anonymous
    if (bbp_is_anonymous()) {
        // Filter anonymous data
        $anonymous_data = bbp_filter_anonymous_post_data();
        // Anonymous data checks out, so set cookies, etc...
        if (!empty($anonymous_data) && is_array($anonymous_data)) {
            bbp_set_current_anonymous_user_data($anonymous_data);
        }
        // User is logged in
    } else {
        // User cannot create replies
        if (!current_user_can('publish_replies')) {
            bbp_add_error('bbp_reply_permissions', __('<strong>ERROR</strong>: You do not have permission to reply.', 'bbpress'));
        }
        // Reply author is current user
        $reply_author = bbp_get_current_user_id();
    }
    /** Topic ID **************************************************************/
    // Topic id was not passed
    if (empty($_POST['bbp_topic_id'])) {
        bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic ID is missing.', 'bbpress'));
        // Topic id is not a number
    } elseif (!is_numeric($_POST['bbp_topic_id'])) {
        bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic ID must be a number.', 'bbpress'));
        // Topic id might be valid
    } else {
        // Get the topic id
        $posted_topic_id = intval($_POST['bbp_topic_id']);
        // Topic id is a negative number
        if (0 > $posted_topic_id) {
            bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic ID cannot be a negative number.', 'bbpress'));
            // Topic does not exist
        } elseif (!bbp_get_topic($posted_topic_id)) {
            bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic does not exist.', 'bbpress'));
            // Use the POST'ed topic id
        } else {
            $topic_id = $posted_topic_id;
        }
    }
    /** Forum ID **************************************************************/
    // Try to use the forum id of the topic
    if (!isset($_POST['bbp_forum_id']) && !empty($topic_id)) {
        $forum_id = bbp_get_topic_forum_id($topic_id);
        // Error check the POST'ed forum id
    } elseif (isset($_POST['bbp_forum_id'])) {
        // Empty Forum id was passed
        if (empty($_POST['bbp_forum_id'])) {
            bbp_add_error('bbp_reply_forum_id', __('<strong>ERROR</strong>: Forum ID is missing.', 'bbpress'));
            // Forum id is not a number
        } elseif (!is_numeric($_POST['bbp_forum_id'])) {
            bbp_add_error('bbp_reply_forum_id', __('<strong>ERROR</strong>: Forum ID must be a number.', 'bbpress'));
            // Forum id might be valid
        } else {
            // Get the forum id
            $posted_forum_id = intval($_POST['bbp_forum_id']);
            // Forum id is empty
            if (0 === $posted_forum_id) {
                bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum ID is missing.', 'bbpress'));
                // Forum id is a negative number
            } elseif (0 > $posted_forum_id) {
                bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum ID cannot be a negative number.', 'bbpress'));
                // Forum does not exist
            } elseif (!bbp_get_forum($posted_forum_id)) {
                bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum does not exist.', 'bbpress'));
                // Use the POST'ed forum id
            } else {
                $forum_id = $posted_forum_id;
            }
        }
    }
    // Forum exists
    if (!empty($forum_id)) {
        // Forum is a category
        if (bbp_is_forum_category($forum_id)) {
            bbp_add_error('bbp_new_reply_forum_category', __('<strong>ERROR</strong>: This forum is a category. No replies can be created in this forum.', '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_new_reply_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new replies.', '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_new_reply_forum_private', __('<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new replies 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_new_reply_forum_hidden', __('<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress'));
                }
            }
        }
    }
    /** Unfiltered HTML *******************************************************/
    // 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_reply']) && wp_create_nonce('bbp-unfiltered-html-reply_' . $topic_id) === $_POST['_bbp_unfiltered_html_reply']) {
        remove_filter('bbp_new_reply_pre_title', 'wp_filter_kses');
        remove_filter('bbp_new_reply_pre_content', 'bbp_encode_bad', 10);
        remove_filter('bbp_new_reply_pre_content', 'bbp_filter_kses', 30);
    }
    /** Reply Title ***********************************************************/
    if (!empty($_POST['bbp_reply_title'])) {
        $reply_title = esc_attr(strip_tags($_POST['bbp_reply_title']));
    }
    // Filter and sanitize
    $reply_title = apply_filters('bbp_new_reply_pre_title', $reply_title);
    /** Reply Content *********************************************************/
    if (!empty($_POST['bbp_reply_content'])) {
        $reply_content = $_POST['bbp_reply_content'];
    }
    // Filter and sanitize
    $reply_content = apply_filters('bbp_new_reply_pre_content', $reply_content);
    // No reply content
    if (empty($reply_content)) {
        bbp_add_error('bbp_reply_content', __('<strong>ERROR</strong>: Your reply cannot be empty.', 'bbpress'));
    }
    /** Reply Flooding ********************************************************/
    if (!bbp_check_for_flood($anonymous_data, $reply_author)) {
        bbp_add_error('bbp_reply_flood', __('<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress'));
    }
    /** Reply Duplicate *******************************************************/
    if (!bbp_check_for_duplicate(array('post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data))) {
        bbp_add_error('bbp_reply_duplicate', __('<strong>ERROR</strong>: Duplicate reply detected; it looks as though you&#8217;ve already said that!', 'bbpress'));
    }
    /** Reply Blacklist *******************************************************/
    if (!bbp_check_for_blacklist($anonymous_data, $reply_author, $reply_title, $reply_content)) {
        bbp_add_error('bbp_reply_blacklist', __('<strong>ERROR</strong>: Your reply cannot be created at this time.', 'bbpress'));
    }
    /** Reply Status **********************************************************/
    // Maybe put into moderation
    if (!bbp_check_for_moderation($anonymous_data, $reply_author, $reply_title, $reply_content)) {
        $reply_status = bbp_get_pending_status_id();
        // Default
    } else {
        $reply_status = bbp_get_public_status_id();
    }
    /** Reply To **************************************************************/
    // Handle Reply To of the reply; $_REQUEST for non-JS submissions
    if (isset($_REQUEST['bbp_reply_to'])) {
        $reply_to = bbp_validate_reply_to($_REQUEST['bbp_reply_to']);
    }
    /** Topic Closed **********************************************************/
    // If topic is closed, moderators can still reply
    if (bbp_is_topic_closed($topic_id) && !current_user_can('moderate')) {
        bbp_add_error('bbp_reply_topic_closed', __('<strong>ERROR</strong>: Topic is closed.', 'bbpress'));
    }
    /** Topic Tags ************************************************************/
    // Either replace terms
    if (bbp_allow_topic_tags() && current_user_can('assign_topic_tags') && !empty($_POST['bbp_topic_tags'])) {
        $terms = esc_attr(strip_tags($_POST['bbp_topic_tags']));
        // ...or remove them.
    } elseif (isset($_POST['bbp_topic_tags'])) {
        $terms = '';
        // Existing terms
    } else {
        $terms = bbp_get_topic_tag_names($topic_id);
    }
    /** Additional Actions (Before Save) **************************************/
    do_action('bbp_new_reply_pre_extras', $topic_id, $forum_id);
    // Bail if errors
    if (bbp_has_errors()) {
        return;
    }
    /** No Errors *************************************************************/
    // Add the content of the form to $reply_data as an array
    // Just in time manipulation of reply data before being created
    $reply_data = apply_filters('bbp_new_reply_pre_insert', array('post_author' => $reply_author, 'post_title' => $reply_title, 'post_content' => $reply_content, 'post_status' => $reply_status, 'post_parent' => $topic_id, 'post_type' => bbp_get_reply_post_type(), 'comment_status' => 'closed', 'menu_order' => bbp_get_topic_reply_count($topic_id, false) + 1));
    // Insert reply
    $reply_id = wp_insert_post($reply_data);
    /** No Errors *************************************************************/
    // Check for missing reply_id or error
    if (!empty($reply_id) && !is_wp_error($reply_id)) {
        /** Topic Tags ********************************************************/
        // Just in time manipulation of reply terms before being edited
        $terms = apply_filters('bbp_new_reply_pre_set_terms', $terms, $topic_id, $reply_id);
        // Insert terms
        $terms = wp_set_post_terms($topic_id, $terms, bbp_get_topic_tag_tax_id(), false);
        // Term error
        if (is_wp_error($terms)) {
            bbp_add_error('bbp_reply_tags', __('<strong>ERROR</strong>: There was a problem adding the tags to the topic.', 'bbpress'));
        }
        /** Trash Check *******************************************************/
        // If this reply starts as trash, add it to pre_trashed_replies
        // for the topic, so it is properly restored.
        if (bbp_is_topic_trash($topic_id) || $reply_data['post_status'] === bbp_get_trash_status_id()) {
            // Trash the reply
            wp_trash_post($reply_id);
            // Only add to pre-trashed array if topic is trashed
            if (bbp_is_topic_trash($topic_id)) {
                // Get pre_trashed_replies for topic
                $pre_trashed_replies = get_post_meta($topic_id, '_bbp_pre_trashed_replies', true);
                // Add this reply to the end of the existing replies
                $pre_trashed_replies[] = $reply_id;
                // Update the pre_trashed_reply post meta
                update_post_meta($topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies);
            }
            /** Spam Check ********************************************************/
            // If reply or topic are spam, officially spam this reply
        } elseif (bbp_is_topic_spam($topic_id) || $reply_data['post_status'] === bbp_get_spam_status_id()) {
            add_post_meta($reply_id, '_bbp_spam_meta_status', bbp_get_public_status_id());
            // Only add to pre-spammed array if topic is spam
            if (bbp_is_topic_spam($topic_id)) {
                // Get pre_spammed_replies for topic
                $pre_spammed_replies = get_post_meta($topic_id, '_bbp_pre_spammed_replies', true);
                // Add this reply to the end of the existing replies
                $pre_spammed_replies[] = $reply_id;
                // Update the pre_spammed_replies post meta
                update_post_meta($topic_id, '_bbp_pre_spammed_replies', $pre_spammed_replies);
            }
        }
        /** Update counts, etc... *********************************************/
        do_action('bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, false, $reply_to);
        /** Additional Actions (After Save) ***********************************/
        do_action('bbp_new_reply_post_extras', $reply_id);
        /** Redirect **********************************************************/
        // Redirect to
        $redirect_to = bbp_get_redirect_to();
        // Get the reply URL
        $reply_url = bbp_get_reply_url($reply_id, $redirect_to);
        // Allow to be filtered
        $reply_url = apply_filters('bbp_new_reply_redirect_to', $reply_url, $redirect_to, $reply_id);
        /** Successful Save ***************************************************/
        // Redirect back to new reply
        wp_safe_redirect($reply_url);
        // For good measure
        exit;
        /** Errors ****************************************************************/
    } else {
        $append_error = is_wp_error($reply_id) && $reply_id->get_error_message() ? $reply_id->get_error_message() . ' ' : '';
        bbp_add_error('bbp_reply_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your reply:' . $append_error . 'Please try again.', 'bbpress'));
    }
}
示例#3
0
/**
 * Return admin links for reply
 *
 * @since bbPress (r2667)
 *
 * @param array $args This function supports these arguments:
 *  - id: Optional. Reply id
 *  - before: HTML before the links. Defaults to
 *             '<span class="bbp-admin-links">'
 *  - after: HTML after the links. Defaults to '</span>'
 *  - sep: Separator. Defaults to ' | '
 *  - links: Array of the links to display. By default, edit, trash,
 *            spam, reply move, and topic split links are displayed
 * @uses bbp_is_topic() To check if it's the topic page
 * @uses bbp_is_reply() To check if it's the reply page
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_edit_link() To get the reply edit link
 * @uses bbp_get_reply_trash_link() To get the reply trash link
 * @uses bbp_get_reply_spam_link() To get the reply spam link
 * @uses bbp_get_reply_move_link() To get the reply move link
 * @uses bbp_get_topic_split_link() To get the topic split link
 * @uses current_user_can() To check if the current user can edit or
 *                           delete the reply
 * @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the
 *                        reply admin links and args
 * @return string Reply admin links
 */
function bbp_get_reply_admin_links($args = array())
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('id' => 0, 'before' => '<span class="bbp-admin-links">', 'after' => '</span>', 'sep' => ' | ', 'links' => array()), 'get_reply_admin_links');
    $r['id'] = bbp_get_reply_id((int) $r['id']);
    // If post is a topic, return the topic admin links instead
    if (bbp_is_topic($r['id'])) {
        return bbp_get_topic_admin_links($args);
    }
    // If post is not a reply, return
    if (!bbp_is_reply($r['id'])) {
        return;
    }
    // If topic is trashed, do not show admin links
    if (bbp_is_topic_trash(bbp_get_reply_topic_id($r['id']))) {
        return;
    }
    // If no links were passed, default to the standard
    if (empty($r['links'])) {
        $r['links'] = apply_filters('bbp_reply_admin_links', array('edit' => bbp_get_reply_edit_link($r), 'move' => bbp_get_reply_move_link($r), 'split' => bbp_get_topic_split_link($r), 'trash' => bbp_get_reply_trash_link($r), 'spam' => bbp_get_reply_spam_link($r), 'reply' => bbp_get_reply_to_link($r)), $r['id']);
    }
    // See if links need to be unset
    $reply_status = bbp_get_reply_status($r['id']);
    if (in_array($reply_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()))) {
        // Spam link shouldn't be visible on trashed topics
        if (bbp_get_trash_status_id() === $reply_status) {
            unset($r['links']['spam']);
            // Trash link shouldn't be visible on spam topics
        } elseif (bbp_get_spam_status_id() === $reply_status) {
            unset($r['links']['trash']);
        }
    }
    // Process the admin links
    $links = implode($r['sep'], array_filter($r['links']));
    $retval = $r['before'] . $links . $r['after'];
    return apply_filters('bbp_get_reply_admin_links', $retval, $r, $args);
}
示例#4
0
 /**
  * Topic Row actions
  *
  * Remove the quick-edit action link under the topic title and add the
  * content and close/stick/spam links
  *
  * @since 2.0.0 bbPress (r2485)
  *
  * @param array $actions Actions
  * @param array $topic Topic object
  * @uses bbp_get_topic_post_type() To get the topic post type
  * @uses bbp_topic_content() To output topic content
  * @uses bbp_get_topic_permalink() To get the topic link
  * @uses bbp_get_topic_title() To get the topic title
  * @uses current_user_can() To check if the current user can edit or
  *                           delete the topic
  * @uses bbp_is_topic_open() To check if the topic is open
  * @uses bbp_is_topic_spam() To check if the topic is marked as spam
  * @uses bbp_is_topic_sticky() To check if the topic is a sticky or a
  *                              super sticky
  * @uses get_post_type_object() To get the topic post type object
  * @uses add_query_arg() To add custom args to the url
  * @uses remove_query_arg() To remove custom args from the url
  * @uses wp_nonce_url() To nonce the url
  * @uses get_delete_post_link() To get the delete post link of the topic
  * @return array $actions Actions
  */
 public function row_actions($actions, $topic)
 {
     if ($this->bail()) {
         return $actions;
     }
     unset($actions['inline hide-if-no-js']);
     // Show view link if it's not set, the topic is trashed and the user can view trashed topics
     if (empty($actions['view']) && bbp_get_trash_status_id() === $topic->post_status && current_user_can('view_trash')) {
         $actions['view'] = '<a href="' . esc_url(bbp_get_topic_permalink($topic->ID)) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;', 'bbpress'), bbp_get_topic_title($topic->ID))) . '" rel="permalink">' . esc_html__('View', 'bbpress') . '</a>';
     }
     // Only show the actions if the user is capable of viewing them :)
     if (current_user_can('moderate', $topic->ID)) {
         // Pending
         // Show the 'approve' and 'view' link on pending posts only and 'unapprove' on published posts only
         $approve_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_approve'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'approve-topic_' . $topic->ID);
         if (bbp_is_topic_published($topic->ID)) {
             $actions['unapproved'] = '<a href="' . esc_url($approve_uri) . '" title="' . esc_attr__('Unapprove this topic', 'bbpress') . '">' . _x('Unapprove', 'Unapprove Topic', 'bbpress') . '</a>';
         } elseif (!bbp_is_topic_private($topic->ID)) {
             $actions['approved'] = '<a href="' . esc_url($approve_uri) . '" title="' . esc_attr__('Approve this topic', 'bbpress') . '">' . _x('Approve', 'Approve Topic', 'bbpress') . '</a>';
             $actions['view'] = '<a href="' . esc_url(bbp_get_topic_permalink($topic->ID)) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;', 'bbpress'), bbp_get_topic_title($topic->ID))) . '" rel="permalink">' . esc_html__('View', 'bbpress') . '</a>';
         }
         // Close
         // Show the 'close' and 'open' link on published and closed posts only
         if (in_array($topic->post_status, array(bbp_get_public_status_id(), bbp_get_closed_status_id()))) {
             $close_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_close'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'close-topic_' . $topic->ID);
             if (bbp_is_topic_open($topic->ID)) {
                 $actions['closed'] = '<a href="' . esc_url($close_uri) . '" title="' . esc_attr__('Close this topic', 'bbpress') . '">' . _x('Close', 'Close a Topic', 'bbpress') . '</a>';
             } else {
                 $actions['closed'] = '<a href="' . esc_url($close_uri) . '" title="' . esc_attr__('Open this topic', 'bbpress') . '">' . _x('Open', 'Open a Topic', 'bbpress') . '</a>';
             }
         }
         // Sticky
         // Dont show sticky if topic links is spam, trash or pending
         if (!bbp_is_topic_spam($topic->ID) && !bbp_is_topic_trash($topic->ID) && !bbp_is_topic_pending($topic->ID)) {
             $stick_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'stick-topic_' . $topic->ID);
             if (bbp_is_topic_sticky($topic->ID)) {
                 $actions['stick'] = '<a href="' . esc_url($stick_uri) . '" title="' . esc_attr__('Unstick this topic', 'bbpress') . '">' . esc_html__('Unstick', 'bbpress') . '</a>';
             } else {
                 $super_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick', 'super' => '1'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'stick-topic_' . $topic->ID);
                 $actions['stick'] = '<a href="' . esc_url($stick_uri) . '" title="' . esc_attr__('Stick this topic to its forum', 'bbpress') . '">' . esc_html__('Stick', 'bbpress') . '</a> <a href="' . esc_url($super_uri) . '" title="' . esc_attr__('Stick this topic to front', 'bbpress') . '">' . esc_html__('(to front)', 'bbpress') . '</a>';
             }
         }
         // Spam
         $spam_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_spam'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'spam-topic_' . $topic->ID);
         if (bbp_is_topic_spam($topic->ID)) {
             $actions['spam'] = '<a href="' . esc_url($spam_uri) . '" title="' . esc_attr__('Mark the topic as not spam', 'bbpress') . '">' . esc_html__('Not spam', 'bbpress') . '</a>';
         } else {
             $actions['spam'] = '<a href="' . esc_url($spam_uri) . '" title="' . esc_attr__('Mark this topic as spam', 'bbpress') . '">' . esc_html__('Spam', 'bbpress') . '</a>';
         }
     }
     // Do not show trash links for spam topics, or spam links for trashed topics
     if (current_user_can('delete_topic', $topic->ID)) {
         if (bbp_get_trash_status_id() === $topic->post_status) {
             $post_type_object = get_post_type_object(bbp_get_topic_post_type());
             $actions['untrash'] = "<a title='" . esc_attr__('Restore this item from the Trash', 'bbpress') . "' href='" . wp_nonce_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_topic_post_type()), admin_url('edit.php'))), admin_url(sprintf($post_type_object->_edit_link . '&amp;action=untrash', $topic->ID))), 'untrash-' . $topic->post_type . '_' . $topic->ID) . "'>" . esc_html__('Restore', 'bbpress') . "</a>";
         } elseif (EMPTY_TRASH_DAYS) {
             $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__('Move this item to the Trash', 'bbpress') . "' href='" . esc_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_topic_post_type()), admin_url('edit.php'))), get_delete_post_link($topic->ID))) . "'>" . esc_html__('Trash', 'bbpress') . "</a>";
         }
         if (bbp_get_trash_status_id() === $topic->post_status || !EMPTY_TRASH_DAYS) {
             $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__('Delete this item permanently', 'bbpress') . "' href='" . esc_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_topic_post_type()), admin_url('edit.php'))), get_delete_post_link($topic->ID, '', true))) . "'>" . esc_html__('Delete Permanently', 'bbpress') . "</a>";
         } elseif (bbp_get_spam_status_id() === $topic->post_status) {
             unset($actions['trash']);
         }
     }
     return $actions;
 }
示例#5
0
/**
 * Return the trash link of the topic
 *
 * @since bbPress (r2727)
 *
 * @param mixed $args This function supports these args:
 *  - id: Optional. Topic id
 *  - link_before: Before the link
 *  - link_after: After the link
 *  - sep: Links separator
 *  - trash_text: Trash text
 *  - restore_text: Restore text
 *  - delete_text: Delete text
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_topic() To get the topic
 * @uses current_user_can() To check if the current user can delete the
 *                           topic
 * @uses bbp_is_topic_trash() To check if the topic is trashed
 * @uses bbp_get_topic_status() To get the topic status
 * @uses add_query_arg() To add custom args to the url
 * @uses wp_nonce_url() To nonce the url
 * @uses esc_url() To escape the url
 * @uses apply_filters() Calls 'bbp_get_topic_trash_link' with the link
 *                        and args
 * @return string Topic trash link
 */
function bbp_get_topic_trash_link($args = '')
{
    $defaults = array('id' => 0, 'link_before' => '', 'link_after' => '', 'sep' => ' | ', 'trash_text' => __('Trash', 'bbpress'), 'restore_text' => __('Restore', 'bbpress'), 'delete_text' => __('Delete', 'bbpress'));
    $r = bbp_parse_args($args, $defaults, 'get_topic_trash_link');
    extract($r);
    $actions = array();
    $topic = bbp_get_topic(bbp_get_topic_id((int) $id));
    if (empty($topic) || !current_user_can('delete_topic', $topic->ID)) {
        return;
    }
    if (bbp_is_topic_trash($topic->ID)) {
        $actions['untrash'] = '<a title="' . esc_attr__('Restore this item from the Trash', 'bbpress') . '" href="' . esc_url(wp_nonce_url(add_query_arg(array('action' => 'bbp_toggle_topic_trash', 'sub_action' => 'untrash', 'topic_id' => $topic->ID)), 'untrash-' . $topic->post_type . '_' . $topic->ID)) . '">' . esc_html($restore_text) . '</a>';
    } elseif (EMPTY_TRASH_DAYS) {
        $actions['trash'] = '<a title="' . esc_attr__('Move this item to the Trash', 'bbpress') . '" href="' . esc_url(wp_nonce_url(add_query_arg(array('action' => 'bbp_toggle_topic_trash', 'sub_action' => 'trash', 'topic_id' => $topic->ID)), 'trash-' . $topic->post_type . '_' . $topic->ID)) . '">' . esc_html($trash_text) . '</a>';
    }
    if (bbp_is_topic_trash($topic->ID) || !EMPTY_TRASH_DAYS) {
        $actions['delete'] = '<a title="' . esc_attr__('Delete this item permanently', 'bbpress') . '" href="' . esc_url(wp_nonce_url(add_query_arg(array('action' => 'bbp_toggle_topic_trash', 'sub_action' => 'delete', 'topic_id' => $topic->ID)), 'delete-' . $topic->post_type . '_' . $topic->ID)) . '" onclick="return confirm(\'' . esc_js(__('Are you sure you want to delete that permanently?', 'bbpress')) . '\' );">' . esc_html($delete_text) . '</a>';
    }
    // Process the admin links
    $retval = $link_before . implode($sep, $actions) . $link_after;
    return apply_filters('bbp_get_topic_trash_link', $retval, $args);
}
示例#6
0
/**
 * Handles the front end reply submission
 *
 * @since bbPress (r2574)
 *
 * @uses bbp_add_error() To add an error message
 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
 * @uses bbp_is_anonymous() To check if an anonymous post is being made
 * @uses current_user_can() To check if the current user can publish replies
 * @uses bbp_get_current_user_id() To get the current user id
 * @uses bbp_filter_anonymous_post_data() To filter anonymous data
 * @uses bbp_set_current_anonymous_user_data() To set the anonymous user
 *                                                cookies
 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
 * @uses remove_filter() To remove 'wp_filter_kses' filters if needed
 * @uses esc_attr() For sanitization
 * @uses bbp_check_for_flood() To check for flooding
 * @uses bbp_check_for_duplicate() To check for duplicates
 * @uses apply_filters() Calls 'bbp_new_reply_pre_title' with the title
 * @uses apply_filters() Calls 'bbp_new_reply_pre_content' with the content
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses wp_set_post_terms() To set the topic tags
 * @uses wp_insert_post() To insert the reply
 * @uses do_action() Calls 'bbp_new_reply' with the reply id, topic id, forum
 *                    id, anonymous data and reply author
 * @uses bbp_get_reply_url() To get the paginated url to the reply
 * @uses wp_safe_redirect() To redirect to the reply url
 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error
 *                                              message
 */
function bbp_new_reply_handler()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if action is not bbp-new-reply
    if (empty($_POST['action']) || 'bbp-new-reply' !== $_POST['action']) {
        return;
    }
    // Nonce check
    if (!bbp_verify_nonce_request('bbp-new-reply')) {
        bbp_add_error('bbp_rew_reply_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
        return;
    }
    // Define local variable(s)
    $topic_id = $forum_id = $reply_author = $anonymous_data = 0;
    $reply_title = $reply_content = $terms = '';
    /** Reply Author **********************************************************/
    // User is anonymous
    if (bbp_is_anonymous()) {
        // Filter anonymous data
        $anonymous_data = bbp_filter_anonymous_post_data();
        // Anonymous data checks out, so set cookies, etc...
        if (!empty($anonymous_data) && is_array($anonymous_data)) {
            bbp_set_current_anonymous_user_data($anonymous_data);
        }
        // User is logged in
    } else {
        // User cannot create replies
        if (!current_user_can('publish_replies')) {
            bbp_add_error('bbp_reply_permissions', __('<strong>ERROR</strong>: You do not have permission to reply.', 'bbpress'));
        }
        // Reply author is current user
        $reply_author = bbp_get_current_user_id();
    }
    /** Topic ID **************************************************************/
    // Handle Topic ID to append reply to
    if (isset($_POST['bbp_topic_id'])) {
        $topic_id = (int) $_POST['bbp_topic_id'];
    } else {
        bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic ID is missing.', 'bbpress'));
    }
    /** Forum ID **************************************************************/
    // Handle Forum ID to adjust counts of
    if (isset($_POST['bbp_forum_id'])) {
        $forum_id = (int) $_POST['bbp_forum_id'];
    } elseif (!empty($topic_id)) {
        $forum_id = bbp_get_topic_forum_id($topic_id);
    } else {
        bbp_add_error('bbp_reply_forum_id', __('<strong>ERROR</strong>: Forum ID is missing.', 'bbpress'));
    }
    /** Unfiltered HTML *******************************************************/
    // Remove wp_filter_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_reply']) && wp_create_nonce('bbp-unfiltered-html-reply_' . $topic_id) == $_POST['_bbp_unfiltered_html_reply']) {
        remove_filter('bbp_new_reply_pre_title', 'wp_filter_kses');
        remove_filter('bbp_new_reply_pre_content', 'wp_filter_kses');
    }
    /** Reply Title ***********************************************************/
    if (!empty($_POST['bbp_reply_title'])) {
        $reply_title = esc_attr(strip_tags($_POST['bbp_reply_title']));
    }
    // Filter and sanitize
    $reply_title = apply_filters('bbp_new_reply_pre_title', $reply_title);
    // No reply title
    if (empty($reply_title)) {
        bbp_add_error('bbp_reply_title', __('<strong>ERROR</strong>: Your reply needs a title.', 'bbpress'));
    }
    /** Reply Content *********************************************************/
    if (!empty($_POST['bbp_reply_content'])) {
        $reply_content = $_POST['bbp_reply_content'];
    }
    // Filter and sanitize
    $reply_content = apply_filters('bbp_new_reply_pre_content', $reply_content);
    // No reply content
    if (empty($reply_content)) {
        bbp_add_error('bbp_reply_content', __('<strong>ERROR</strong>: Your reply cannot be empty.', 'bbpress'));
    }
    /** Reply Flooding ********************************************************/
    if (!bbp_check_for_flood($anonymous_data, $reply_author)) {
        bbp_add_error('bbp_reply_flood', __('<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress'));
    }
    /** Reply Duplicate *******************************************************/
    if (!bbp_check_for_duplicate(array('post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data))) {
        bbp_add_error('bbp_reply_duplicate', __('<strong>ERROR</strong>: Duplicate reply detected; it looks as though you&#8217;ve already said that!', 'bbpress'));
    }
    /** Reply Blacklist *******************************************************/
    if (!bbp_check_for_blacklist($anonymous_data, $reply_author, $reply_title, $reply_content)) {
        bbp_add_error('bbp_reply_blacklist', __('<strong>ERROR</strong>: Your reply cannot be created at this time.', 'bbpress'));
    }
    /** Reply Moderation ******************************************************/
    $post_status = bbp_get_public_status_id();
    if (!bbp_check_for_moderation($anonymous_data, $reply_author, $reply_title, $reply_content)) {
        $post_status = bbp_get_pending_status_id();
    }
    /** Topic Tags ************************************************************/
    if (!empty($_POST['bbp_topic_tags'])) {
        $terms = esc_attr(strip_tags($_POST['bbp_topic_tags']));
    }
    /** Additional Actions (Before Save) **************************************/
    do_action('bbp_new_reply_pre_extras', $topic_id, $forum_id);
    // Bail if errors
    if (bbp_has_errors()) {
        return;
    }
    /** No Errors *************************************************************/
    // Add the content of the form to $reply_data as an array
    // Just in time manipulation of reply data before being created
    $reply_data = apply_filters('bbp_new_reply_pre_insert', array('post_author' => $reply_author, 'post_title' => $reply_title, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'post_status' => $post_status, 'post_type' => bbp_get_reply_post_type(), 'comment_status' => 'closed', 'menu_order' => (int) (bbp_get_topic_reply_count($topic_id) + 1)));
    // Insert reply
    $reply_id = wp_insert_post($reply_data);
    /** No Errors *************************************************************/
    // Check for missing reply_id or error
    if (!empty($reply_id) && !is_wp_error($reply_id)) {
        /** Topic Tags ********************************************************/
        // Just in time manipulation of reply terms before being edited
        $terms = apply_filters('bbp_new_reply_pre_set_terms', $terms, $topic_id, $reply_id);
        // Insert terms
        $terms = wp_set_post_terms($topic_id, $terms, bbp_get_topic_tag_tax_id(), false);
        // Term error
        if (is_wp_error($terms)) {
            bbp_add_error('bbp_reply_tags', __('<strong>ERROR</strong>: There was a problem adding the tags to the topic.', 'bbpress'));
        }
        /** Trash Check *******************************************************/
        // If this reply starts as trash, add it to pre_trashed_replies
        // for the topic, so it is properly restored.
        if (bbp_is_topic_trash($topic_id) || $reply_data['post_status'] == bbp_get_trash_status_id()) {
            // Trash the reply
            wp_trash_post($reply_id);
            // Get pre_trashed_replies for topic
            $pre_trashed_replies = get_post_meta($topic_id, '_bbp_pre_trashed_replies', true);
            // Add this reply to the end of the existing replies
            $pre_trashed_replies[] = $reply_id;
            // Update the pre_trashed_reply post meta
            update_post_meta($topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies);
        }
        /** Spam Check ********************************************************/
        // If reply or topic are spam, officially spam this reply
        if (bbp_is_topic_spam($topic_id) || $reply_data['post_status'] == bbp_get_spam_status_id()) {
            add_post_meta($reply_id, '_bbp_spam_meta_status', bbp_get_public_status_id());
        }
        /** Update counts, etc... *********************************************/
        do_action('bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author);
        /** Additional Actions (After Save) ***********************************/
        do_action('bbp_new_reply_post_extras', $reply_id);
        /** Redirect **********************************************************/
        // Redirect to
        $redirect_to = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '';
        // Get the reply URL
        $reply_url = bbp_get_reply_url($reply_id, $redirect_to);
        // Allow to be filtered
        $reply_url = apply_filters('bbp_new_reply_redirect_to', $reply_url, $redirect_to, $reply_id);
        /** Successful Save ***************************************************/
        // Redirect back to new reply
        wp_safe_redirect($reply_url);
        // For good measure
        exit;
        /** Errors ****************************************************************/
    } else {
        $append_error = is_wp_error($reply_id) && $reply_id->get_error_message() ? $reply_id->get_error_message() . ' ' : '';
        bbp_add_error('bbp_reply_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your reply:' . $append_error . 'Please try again.', 'bbpress'));
    }
}
示例#7
0
/**
 * Return admin links for reply
 *
 * @since bbPress (r2667)
 *
 * @param mixed $args This function supports these arguments:
 *  - id: Optional. Reply id
 *  - before: HTML before the links. Defaults to
 *             '<span class="bbp-admin-links">'
 *  - after: HTML after the links. Defaults to '</span>'
 *  - sep: Separator. Defaults to ' | '
 *  - links: Array of the links to display. By default, edit, trash,
 *            spam and topic split links are displayed
 * @uses bbp_is_topic() To check if it's the topic page
 * @uses bbp_is_reply() To check if it's the reply page
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_edit_link() To get the reply edit link
 * @uses bbp_get_reply_trash_link() To get the reply trash link
 * @uses bbp_get_reply_spam_link() To get the reply spam link
 * @uses bbp_get_topic_split_link() To get the topic split link
 * @uses current_user_can() To check if the current user can edit or
 *                           delete the reply
 * @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the
 *                        reply admin links and args
 * @return string Reply admin links
 */
function bbp_get_reply_admin_links($args = '')
{
    $defaults = array('id' => 0, 'before' => '<span class="bbp-admin-links">', 'after' => '</span>', 'sep' => ' | ', 'links' => array());
    $r = bbp_parse_args($args, $defaults, 'get_reply_admin_links');
    $r['id'] = bbp_get_reply_id((int) $r['id']);
    // If post is a topic, return the topic admin links instead
    if (bbp_is_topic($r['id'])) {
        return bbp_get_topic_admin_links($args);
    }
    // If post is not a reply, return
    if (!bbp_is_reply($r['id'])) {
        return;
    }
    // Make sure user can edit this reply
    if (!current_user_can('edit_reply', $r['id'])) {
        return;
    }
    // If topic is trashed, do not show admin links
    if (bbp_is_topic_trash(bbp_get_reply_topic_id($r['id']))) {
        return;
    }
    // If no links were passed, default to the standard
    if (empty($r['links'])) {
        $r['links'] = array('edit' => bbp_get_reply_edit_link($r), 'split' => bbp_get_topic_split_link($r), 'trash' => bbp_get_reply_trash_link($r), 'spam' => bbp_get_reply_spam_link($r));
    }
    // Check caps for trashing the topic
    if (!current_user_can('delete_reply', $r['id']) && !empty($r['links']['trash'])) {
        unset($r['links']['trash']);
    }
    // See if links need to be unset
    $reply_status = bbp_get_reply_status($r['id']);
    if (in_array($reply_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()))) {
        // Spam link shouldn't be visible on trashed topics
        if ($reply_status == bbp_get_trash_status_id()) {
            unset($r['links']['spam']);
            // Trash link shouldn't be visible on spam topics
        } elseif (isset($r['links']['trash']) && bbp_get_spam_status_id() == $reply_status) {
            unset($r['links']['trash']);
        }
    }
    // Process the admin links
    $links = implode($r['sep'], array_filter($r['links']));
    $retval = $r['before'] . $links . $r['after'];
    return apply_filters('bbp_get_reply_admin_links', $retval, $args);
}
 /**
  * Post by email handler.
  *
  * For bbPress, the logic in this method is the same as {@link bbp_new_reply_handler()}.
  * It's duplicated because bbPress doesn't utilize hooks for verifying replies.
  *
  * @param bool $retval True by default.
  * @param array $data {
  *     An array of arguments.
  *
  *     @type array $headers Email headers.
  *     @type string $content The email body content.
  *     @type string $subject The email subject line.
  *     @type int $user_id The user ID who sent the email.
  *     @type bool $is_html Whether the email content is HTML or not.
  *     @type int $i The email message number.
  * }
  * @param array $params Parsed paramaters from the email address querystring.
  *   See {@link BP_Reply_By_Email_Parser::get_parameters()}.
  * @return array|object Array of the parsed item on success. WP_Error object
  *  on failure.
  */
 public function post($retval, $data, $params)
 {
     /** SETUP DATA ***************************************************/
     // reset globals
     global $bp;
     if (empty($bp->rbe->temp)) {
         $bp->rbe = new stdClass();
         $bp->rbe->temp = new stdClass();
     }
     $i = $data['i'];
     $user_id = $data['user_id'];
     // get topic ID
     $topic_id = !empty($params[$this->secondary_item_id_param]) ? $params[$this->secondary_item_id_param] : false;
     // get reply post ID
     $reply_to = !empty($params[$this->reply_id_param]) ? $params[$this->reply_id_param] : 0;
     // current email is not a bbPress group reply
     if (empty($topic_id)) {
         // if current email is a bbPress new group topic, parse it
         if (!empty($params[$this->forum_id_param])) {
             $retval = $this->post_new_topic($data, $params);
         }
         return $retval;
     }
     /* current email is a bbPress group reply, let's proceed! */
     // let RBE know that we're in the process of rendering a bbP reply
     // BuddyPress group forum reply
     if (!empty($params[$this->item_id_param])) {
         bp_rbe_log('Message #' . $i . ': this is a bbPress group forum reply');
         // bbPress
     } else {
         bp_rbe_log('Message #' . $i . ': this is a bbPress forum reply');
     }
     // other variables
     $reply_author = $user_id;
     $anonymous_data = 0;
     /** GROUP PERMISSIONS ********************************************/
     // posting from a BP group
     if (!empty($params[$this->item_id_param])) {
         // set group ID and cache it in global for later use
         // $bp->rbe->temp->group_id gets passed to the set_group_id() method later on
         $group_id = $bp->rbe->temp->group_id = $params[$this->item_id_param];
         // get all group member data for the user in one swoop!
         $group_member_data = bp_rbe_get_group_member_info($reply_author, $group_id);
         // user is not a member of the group anymore
         if (empty($group_member_data)) {
             //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'user_not_group_member' );
             return new WP_Error('user_not_group_member', '', $data);
         }
         // user is banned from group
         if ((int) $group_member_data->is_banned == 1) {
             //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'user_banned_from_group' );
             return new WP_Error('user_banned_from_group', '', $data);
         }
         // override groups_get_current_group() with our cached group ID
         add_filter('groups_get_current_group', array($this, 'set_group_id'));
         // make sure bbP doesn't send any emails as GES handles this
         add_filter('bbp_get_topic_subscribers', '__return_false');
         // temporarily add some GES filters here
         add_filter('bp_ass_activity_notification_subject', 'wp_specialchars_decode');
         add_filter('bp_ass_activity_notification_content', 'wp_specialchars_decode');
         // bbPress-only forums
     } else {
         // Subscriptions - make sure the author stays subscribed to the thread
         // this is due to how bbp_update_reply() works
         $_POST['bbp_topic_subscription'] = 'bbp_subscribe';
     }
     /** REPLY PERMISSIONS ********************************************/
     // Allow member to pass default cap checks.
     // The reason why we keep the 'publish_replies' check below is b/c bbPress
     // plugins may disable cap access for a specific user if they have hooked into
     // the 'bbp_map_meta_caps' filter.
     add_filter('bbp_map_meta_caps', array($this, 'map_forum_meta_caps'), 5, 4);
     // User cannot create replies
     if (!user_can($reply_author, 'publish_replies')) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_permissions' );
         return new WP_Error('bbp_reply_permissions', '', $data);
     }
     /** UNFILTERED HTML **********************************************/
     // Remove wp_filter_kses filters from title and content for capable users
     if (user_can($user_id, 'unfiltered_html')) {
         remove_filter('bbp_new_reply_pre_title', 'wp_filter_kses');
         remove_filter('bbp_new_reply_pre_content', 'wp_filter_kses');
     }
     /** REPLY DATA ***************************************************/
     // setup a dummy reply title b/c bbP requires it
     $reply_title = sprintf(__('Reply To: Topic ID %d', 'bp-rbe'), $topic_id);
     // Filter and sanitize
     $reply_content = apply_filters('bbp_new_reply_pre_content', $data['content']);
     /** REPLY MODERATION *********************************************/
     // Reply Flooding
     if (!bbp_check_for_flood($anonymous_data, $reply_author)) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_flood' );
         //bbp_add_error( 'bbp_reply_flood', __( '<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress' ) );
         return new WP_Error('bbp_reply_flood', '', $data);
     }
     // Reply Duplicate
     if (!bbp_check_for_duplicate(array('post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data))) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_duplicate' );
         return new WP_Error('bbp_reply_duplicate', '', $data);
     }
     // Reply Blacklist
     if (!bbp_check_for_blacklist($anonymous_data, $reply_author, $reply_title, $reply_content)) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_blacklist' );
         return new WP_Error('bbp_reply_blacklist', '', $data);
     }
     // Reply Status
     // Maybe put into moderation
     if (!bbp_check_for_moderation($anonymous_data, $reply_author, $reply_title, $reply_content)) {
         $reply_status = bbp_get_pending_status_id();
         // Default
     } else {
         $reply_status = bbp_get_public_status_id();
     }
     /** POSTING TIME! ************************************************/
     // get forum ID
     $forum_id = bbp_get_topic_forum_id($topic_id);
     // bbP hook before save
     do_action('bbp_new_reply_pre_extras', $topic_id, $forum_id);
     // Setup reply data
     $reply_data = apply_filters('bbp_new_reply_pre_insert', array('post_author' => $reply_author, 'post_title' => $reply_title, 'post_content' => $reply_content, 'post_status' => $reply_status, 'post_parent' => $topic_id, 'post_type' => bbp_get_reply_post_type(), 'comment_status' => 'closed', 'menu_order' => bbp_get_topic_reply_count($topic_id, false) + 1));
     // Insert reply
     $reply_id = wp_insert_post($reply_data);
     // Reply posted!
     if (!is_wp_error($reply_id)) {
         // more internal logging
         bp_rbe_log('Message #' . $i . ': bbPress reply successfully posted!');
         // Problem posting
     } else {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_error' );
         return new WP_Error('bbp_reply_error', '', $data);
     }
     /** AFTER POSTING ************************************************/
     // stuff that needs to happen after a bbP reply is posted occurs here... bbP
     // should preferably do the following at the 'bbp_new_reply' hook, until then
     // do what bbP does inline.
     // Trash Check ////////////////////////////////////////////////////
     // If this reply starts as trash, add it to pre_trashed_replies
     // for the topic, so it is properly restored.
     if (bbp_is_topic_trash($topic_id) || $reply_data['post_status'] == bbp_get_trash_status_id()) {
         // Trash the reply
         wp_trash_post($reply_id);
         // Only add to pre-trashed array if topic is trashed
         if (bbp_is_topic_trash($topic_id)) {
             // Get pre_trashed_replies for topic
             $pre_trashed_replies = get_post_meta($topic_id, '_bbp_pre_trashed_replies', true);
             // Add this reply to the end of the existing replies
             $pre_trashed_replies[] = $reply_id;
             // Update the pre_trashed_reply post meta
             update_post_meta($topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies);
         }
         // Spam Check /////////////////////////////////////////////////////
         // If reply or topic are spam, officially spam this reply
     } elseif (bbp_is_topic_spam($topic_id) || $reply_data['post_status'] == bbp_get_spam_status_id()) {
         add_post_meta($reply_id, '_bbp_spam_meta_status', bbp_get_public_status_id());
         // Only add to pre-spammed array if topic is spam
         if (bbp_is_topic_spam($topic_id)) {
             // Get pre_spammed_replies for topic
             $pre_spammed_replies = get_post_meta($topic_id, '_bbp_pre_spammed_replies', true);
             // Add this reply to the end of the existing replies
             $pre_spammed_replies[] = $reply_id;
             // Update the pre_spammed_replies post meta
             update_post_meta($topic_id, '_bbp_pre_spammed_replies', $pre_spammed_replies);
         }
     }
     // Reply By Email /////////////////////////////////////////////////
     // Add a RBE marker to the post's meta
     // Could potentially show that post was made via email on the frontend
     add_post_meta($reply_id, 'bp_rbe', 1);
     /** POST HOOKS ***************************************************/
     // RBE Custom Hooks ///////////////////////////////////////////////
     // change activity action
     add_filter('bbp_before_record_activity_parse_args', array($this, 'change_activity_action'));
     // add RBE's special activity hook
     add_action('bp_activity_after_save', array($this, 'activity_rbe_hook'));
     // bbPress Reply Hooks ////////////////////////////////////////////
     do_action('bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, false, $reply_to);
     do_action('bbp_new_reply_post_extras', $reply_id);
     return array('bbp_reply_id' => $reply_id);
 }