/** * Handles the front end edit forum submission * * @param string $action The requested action to compare this function to * @uses bbPress:errors::add() To log various error messages * @uses bbp_get_forum() To get the forum * @uses bbp_verify_nonce_request() To verify the nonce and check the request * @uses bbp_is_forum_anonymous() To check if forum is by an anonymous user * @uses current_user_can() To check if the current user can edit the forum * @uses bbp_filter_anonymous_post_data() To filter anonymous data * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error} * @uses esc_attr() For sanitization * @uses bbp_is_forum_category() To check if the forum is a category * @uses bbp_is_forum_closed() To check if the forum is closed * @uses bbp_is_forum_private() To check if the forum is private * @uses remove_filter() To remove kses filters if needed * @uses apply_filters() Calls 'bbp_edit_forum_pre_title' with the title and * forum id * @uses apply_filters() Calls 'bbp_edit_forum_pre_content' with the content * and forum id * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors * @uses wp_save_post_revision() To save a forum revision * @uses bbp_update_forum_revision_log() To update the forum revision log * @uses wp_update_post() To update the forum * @uses do_action() Calls 'bbp_edit_forum' with the forum id, forum id, * anonymous data and reply author * @uses bbp_move_forum_handler() To handle movement of a forum from one forum * to another * @uses bbp_get_forum_permalink() To get the forum permalink * @uses wp_safe_redirect() To redirect to the forum link * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error * messages */ function bbp_edit_forum_handler($action = '') { // Bail if action is not bbp-edit-forum if ('bbp-edit-forum' !== $action) { return; } // Define local variable(s) $anonymous_data = array(); $forum = $forum_id = $forum_parent_id = 0; $forum_title = $forum_content = $forum_edit_reason = ''; /** Forum *****************************************************************/ // Forum id was not passed if (empty($_POST['bbp_forum_id'])) { bbp_add_error('bbp_edit_forum_id', __('<strong>ERROR</strong>: Forum ID not found.', 'bbpress')); return; // Forum id was passed } elseif (is_numeric($_POST['bbp_forum_id'])) { $forum_id = (int) $_POST['bbp_forum_id']; $forum = bbp_get_forum($forum_id); } // Nonce check if (!bbp_verify_nonce_request('bbp-edit-forum_' . $forum_id)) { bbp_add_error('bbp_edit_forum_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress')); return; // Forum does not exist } elseif (empty($forum)) { bbp_add_error('bbp_edit_forum_not_found', __('<strong>ERROR</strong>: The forum you want to edit was not found.', 'bbpress')); return; // User cannot edit this forum } elseif (!current_user_can('edit_forum', $forum_id)) { bbp_add_error('bbp_edit_forum_permissions', __('<strong>ERROR</strong>: You do not have permission to edit that forum.', 'bbpress')); return; } // Remove kses filters from title and content for capable users and if the nonce is verified if (current_user_can('unfiltered_html') && !empty($_POST['_bbp_unfiltered_html_forum']) && wp_create_nonce('bbp-unfiltered-html-forum_' . $forum_id) === $_POST['_bbp_unfiltered_html_forum']) { remove_filter('bbp_edit_forum_pre_title', 'wp_filter_kses'); remove_filter('bbp_edit_forum_pre_content', 'bbp_encode_bad', 10); remove_filter('bbp_edit_forum_pre_content', 'bbp_filter_kses', 30); } /** Forum Parent ***********************************************************/ // Forum parent id was passed if (!empty($_POST['bbp_forum_parent_id'])) { $forum_parent_id = bbp_get_forum_id($_POST['bbp_forum_parent_id']); } // Current forum this forum is in $current_parent_forum_id = bbp_get_forum_parent_id($forum_id); // Forum exists if (!empty($forum_parent_id) && $forum_parent_id !== $current_parent_forum_id) { // Forum is closed and user cannot access if (bbp_is_forum_closed($forum_parent_id) && !current_user_can('edit_forum', $forum_parent_id)) { bbp_add_error('bbp_edit_forum_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new forums.', 'bbpress')); } // Forum is private and user cannot access if (bbp_is_forum_private($forum_parent_id) && !current_user_can('read_private_forums')) { bbp_add_error('bbp_edit_forum_forum_private', __('<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress')); } // Forum is hidden and user cannot access if (bbp_is_forum_hidden($forum_parent_id) && !current_user_can('read_hidden_forums')) { bbp_add_error('bbp_edit_forum_forum_hidden', __('<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress')); } } /** Forum Title ***********************************************************/ if (!empty($_POST['bbp_forum_title'])) { $forum_title = esc_attr(strip_tags($_POST['bbp_forum_title'])); } // Filter and sanitize $forum_title = apply_filters('bbp_edit_forum_pre_title', $forum_title, $forum_id); // No forum title if (empty($forum_title)) { bbp_add_error('bbp_edit_forum_title', __('<strong>ERROR</strong>: Your forum needs a title.', 'bbpress')); } /** Forum Content *********************************************************/ if (!empty($_POST['bbp_forum_content'])) { $forum_content = $_POST['bbp_forum_content']; } // Filter and sanitize $forum_content = apply_filters('bbp_edit_forum_pre_content', $forum_content, $forum_id); // No forum content if (empty($forum_content)) { bbp_add_error('bbp_edit_forum_content', __('<strong>ERROR</strong>: Your forum description cannot be empty.', 'bbpress')); } /** Forum Blacklist *******************************************************/ if (!bbp_check_for_blacklist($anonymous_data, bbp_get_forum_author_id($forum_id), $forum_title, $forum_content)) { bbp_add_error('bbp_forum_blacklist', __('<strong>ERROR</strong>: Your forum cannot be edited at this time.', 'bbpress')); } /** Forum Moderation ******************************************************/ $post_status = bbp_get_public_status_id(); if (!bbp_check_for_moderation($anonymous_data, bbp_get_forum_author_id($forum_id), $forum_title, $forum_content)) { $post_status = bbp_get_pending_status_id(); } /** Additional Actions (Before Save) **************************************/ do_action('bbp_edit_forum_pre_extras', $forum_id); // Bail if errors if (bbp_has_errors()) { return; } /** No Errors *************************************************************/ // Add the content of the form to $forum_data as an array // Just in time manipulation of forum data before being edited $forum_data = apply_filters('bbp_edit_forum_pre_insert', array('ID' => $forum_id, 'post_title' => $forum_title, 'post_content' => $forum_content, 'post_status' => $post_status, 'post_parent' => $forum_parent_id)); // Insert forum $forum_id = wp_update_post($forum_data); /** Revisions *************************************************************/ /** * @todo omitted for 2.1 // Revision Reason if ( !empty( $_POST['bbp_forum_edit_reason'] ) ) $forum_edit_reason = esc_attr( strip_tags( $_POST['bbp_forum_edit_reason'] ) ); // Update revision log if ( !empty( $_POST['bbp_log_forum_edit'] ) && ( "1" === $_POST['bbp_log_forum_edit'] ) && ( $revision_id = wp_save_post_revision( $forum_id ) ) ) { bbp_update_forum_revision_log( array( 'forum_id' => $forum_id, 'revision_id' => $revision_id, 'author_id' => bbp_get_current_user_id(), 'reason' => $forum_edit_reason ) ); } */ /** No Errors *************************************************************/ if (!empty($forum_id) && !is_wp_error($forum_id)) { // Update counts, etc... do_action('bbp_edit_forum', array('forum_id' => $forum_id, 'post_parent' => $forum_parent_id, 'forum_author' => $forum->post_author, 'last_topic_id' => 0, 'last_reply_id' => 0, 'last_active_id' => 0, 'last_active_time' => 0, 'last_active_status' => bbp_get_public_status_id())); // If the new forum parent id is not equal to the old forum parent // id, run the bbp_move_forum action and pass the forum's parent id // as the first arg and new forum parent id as the second. // @todo implement //if ( $forum_id !== $forum->post_parent ) // bbp_move_forum_handler( $forum_parent_id, $forum->post_parent, $forum_id ); /** Additional Actions (After Save) ***********************************/ do_action('bbp_edit_forum_post_extras', $forum_id); /** Redirect **********************************************************/ // Redirect to $redirect_to = bbp_get_redirect_to(); // View all? $view_all = bbp_get_view_all(); // Get the forum URL $forum_url = bbp_get_forum_permalink($forum_id, $redirect_to); // Add view all? if (!empty($view_all)) { $forum_url = bbp_add_view_all($forum_url); } // Allow to be filtered $forum_url = apply_filters('bbp_edit_forum_redirect_to', $forum_url, $view_all, $redirect_to); /** Successful Edit ***************************************************/ // Redirect back to new forum wp_safe_redirect($forum_url); // For good measure exit; /** Errors ****************************************************************/ } else { $append_error = is_wp_error($forum_id) && $forum_id->get_error_message() ? $forum_id->get_error_message() . ' ' : ''; bbp_add_error('bbp_forum_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your forum:' . $append_error . 'Please try again.', 'bbpress')); } }
/** * Handles the front end edit topic submission * * @param string $action The requested action to compare this function to * @uses bbp_add_error() To add an error message * @uses bbp_get_topic() To get the topic * @uses bbp_verify_nonce_request() To verify the nonce and check the request * @uses bbp_is_topic_anonymous() To check if topic is by an anonymous user * @uses current_user_can() To check if the current user can edit the topic * @uses bbp_filter_anonymous_post_data() To filter anonymous data * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error} * @uses esc_attr() For sanitization * @uses bbp_is_forum_category() To check if the forum is a category * @uses bbp_is_forum_closed() To check if the forum is closed * @uses bbp_is_forum_private() To check if the forum is private * @uses remove_filter() To remove kses filters if needed * @uses apply_filters() Calls 'bbp_edit_topic_pre_title' with the title and * topic id * @uses apply_filters() Calls 'bbp_edit_topic_pre_content' with the content * and topic id * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors * @uses wp_save_post_revision() To save a topic revision * @uses bbp_update_topic_revision_log() To update the topic revision log * @uses bbp_stick_topic() To stick or super stick the topic * @uses bbp_unstick_topic() To unstick the topic * @uses wp_update_post() To update the topic * @uses do_action() Calls 'bbp_edit_topic' with the topic id, forum id, * anonymous data and reply author * @uses bbp_move_topic_handler() To handle movement of a topic from one forum * to another * @uses bbp_get_topic_permalink() To get the topic permalink * @uses wp_safe_redirect() To redirect to the topic link * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error * messages */ function bbp_edit_topic_handler($action = '') { // Bail if action is not bbp-edit-topic if ('bbp-edit-topic' !== $action) { return; } // Define local variable(s) $revisions_removed = false; $topic = $topic_id = $topic_author = $forum_id = $anonymous_data = 0; $topic_title = $topic_content = $topic_edit_reason = ''; /** Topic *****************************************************************/ // Topic id was not passed if (empty($_POST['bbp_topic_id'])) { bbp_add_error('bbp_edit_topic_id', __('<strong>ERROR</strong>: Topic ID not found.', 'bbpress')); return; // Topic id was passed } elseif (is_numeric($_POST['bbp_topic_id'])) { $topic_id = (int) $_POST['bbp_topic_id']; $topic = bbp_get_topic($topic_id); } // Topic does not exist if (empty($topic)) { bbp_add_error('bbp_edit_topic_not_found', __('<strong>ERROR</strong>: The topic you want to edit was not found.', 'bbpress')); return; // Topic exists } else { // Check users ability to create new topic if (!bbp_is_topic_anonymous($topic_id)) { // User cannot edit this topic if (!current_user_can('edit_topic', $topic_id)) { bbp_add_error('bbp_edit_topic_permissions', __('<strong>ERROR</strong>: You do not have permission to edit that topic.', 'bbpress')); } // Set topic author $topic_author = bbp_get_topic_author_id($topic_id); // It is an anonymous post } else { // Filter anonymous data $anonymous_data = bbp_filter_anonymous_post_data(array(), true); } } // Nonce check if (!bbp_verify_nonce_request('bbp-edit-topic_' . $topic_id)) { bbp_add_error('bbp_edit_topic_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress')); return; } // Remove kses filters from title and content for capable users and if the nonce is verified if (current_user_can('unfiltered_html') && !empty($_POST['_bbp_unfiltered_html_topic']) && wp_create_nonce('bbp-unfiltered-html-topic_' . $topic_id) === $_POST['_bbp_unfiltered_html_topic']) { remove_filter('bbp_edit_topic_pre_title', 'wp_filter_kses'); remove_filter('bbp_edit_topic_pre_content', 'bbp_encode_bad', 10); remove_filter('bbp_edit_topic_pre_content', 'bbp_filter_kses', 30); } /** Topic Forum ***********************************************************/ // Forum id was not passed if (empty($_POST['bbp_forum_id'])) { bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum ID is missing.', 'bbpress')); // Forum id was passed } elseif (is_numeric($_POST['bbp_forum_id'])) { $forum_id = (int) $_POST['bbp_forum_id']; } // Current forum this topic is in $current_forum_id = bbp_get_topic_forum_id($topic_id); // Forum exists if (!empty($forum_id) && $forum_id !== $current_forum_id) { // Forum is a category if (bbp_is_forum_category($forum_id)) { bbp_add_error('bbp_edit_topic_forum_category', __('<strong>ERROR</strong>: This forum is a category. No topics can be created in it.', 'bbpress')); // Forum is not a category } else { // Forum is closed and user cannot access if (bbp_is_forum_closed($forum_id) && !current_user_can('edit_forum', $forum_id)) { bbp_add_error('bbp_edit_topic_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new topics.', 'bbpress')); } // Forum is private and user cannot access if (bbp_is_forum_private($forum_id)) { if (!current_user_can('read_private_forums')) { bbp_add_error('bbp_edit_topic_forum_private', __('<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress')); } // Forum is hidden and user cannot access } elseif (bbp_is_forum_hidden($forum_id)) { if (!current_user_can('read_hidden_forums')) { bbp_add_error('bbp_edit_topic_forum_hidden', __('<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress')); } } } } /** Topic Title ***********************************************************/ if (!empty($_POST['bbp_topic_title'])) { $topic_title = esc_attr(strip_tags($_POST['bbp_topic_title'])); } // Filter and sanitize $topic_title = apply_filters('bbp_edit_topic_pre_title', $topic_title, $topic_id); // No topic title if (empty($topic_title)) { bbp_add_error('bbp_edit_topic_title', __('<strong>ERROR</strong>: Your topic needs a title.', 'bbpress')); } /** Topic Content *********************************************************/ if (!empty($_POST['bbp_topic_content'])) { $topic_content = $_POST['bbp_topic_content']; } // Filter and sanitize $topic_content = apply_filters('bbp_edit_topic_pre_content', $topic_content, $topic_id); // No topic content if (empty($topic_content)) { bbp_add_error('bbp_edit_topic_content', __('<strong>ERROR</strong>: Your topic cannot be empty.', 'bbpress')); } /** Topic Blacklist *******************************************************/ if (!bbp_check_for_blacklist($anonymous_data, $topic_author, $topic_title, $topic_content)) { bbp_add_error('bbp_topic_blacklist', __('<strong>ERROR</strong>: Your topic cannot be edited at this time.', 'bbpress')); } /** Topic Status **********************************************************/ // Maybe put into moderation if (!bbp_check_for_moderation($anonymous_data, $topic_author, $topic_title, $topic_content)) { // Set post status to pending if public or closed if (in_array($topic->post_status, array(bbp_get_public_status_id(), bbp_get_closed_status_id()))) { $topic_status = bbp_get_pending_status_id(); } // Check a whitelist of possible topic status ID's } elseif (!empty($_POST['bbp_topic_status']) && in_array($_POST['bbp_topic_status'], array_keys(bbp_get_topic_statuses()))) { $topic_status = $_POST['bbp_topic_status']; // Use existing post_status } else { $topic_status = $topic->post_status; } /** Topic Tags ************************************************************/ // Either replace terms if (bbp_allow_topic_tags() && current_user_can('assign_topic_tags') && !empty($_POST['bbp_topic_tags'])) { // Escape tag input $terms = esc_attr(strip_tags($_POST['bbp_topic_tags'])); // Explode by comma if (strstr($terms, ',')) { $terms = explode(',', $terms); } // Add topic tag ID as main key $terms = array(bbp_get_topic_tag_tax_id() => $terms); // ...or remove them. } elseif (isset($_POST['bbp_topic_tags'])) { $terms = array(bbp_get_topic_tag_tax_id() => array()); // Existing terms } else { $terms = array(bbp_get_topic_tag_tax_id() => explode(',', bbp_get_topic_tag_names($topic_id, ','))); } /** Additional Actions (Before Save) **************************************/ do_action('bbp_edit_topic_pre_extras', $topic_id); // Bail if errors if (bbp_has_errors()) { return; } /** No Errors *************************************************************/ // Add the content of the form to $topic_data as an array // Just in time manipulation of topic data before being edited $topic_data = apply_filters('bbp_edit_topic_pre_insert', array('ID' => $topic_id, 'post_title' => $topic_title, 'post_content' => $topic_content, 'post_status' => $topic_status, 'post_parent' => $forum_id, 'post_author' => $topic_author, 'post_type' => bbp_get_topic_post_type(), 'tax_input' => $terms)); // Toggle revisions to avoid duplicates if (post_type_supports(bbp_get_topic_post_type(), 'revisions')) { $revisions_removed = true; remove_post_type_support(bbp_get_topic_post_type(), 'revisions'); } // Insert topic $topic_id = wp_update_post($topic_data); // Toggle revisions back on if (true === $revisions_removed) { $revisions_removed = false; add_post_type_support(bbp_get_topic_post_type(), 'revisions'); } /** No Errors *************************************************************/ if (!empty($topic_id) && !is_wp_error($topic_id)) { // Update counts, etc... do_action('bbp_edit_topic', $topic_id, $forum_id, $anonymous_data, $topic_author, true); /** Revisions *********************************************************/ // Revision Reason if (!empty($_POST['bbp_topic_edit_reason'])) { $topic_edit_reason = esc_attr(strip_tags($_POST['bbp_topic_edit_reason'])); } // Update revision log if (!empty($_POST['bbp_log_topic_edit']) && "1" === $_POST['bbp_log_topic_edit']) { $revision_id = wp_save_post_revision($topic_id); if (!empty($revision_id)) { bbp_update_topic_revision_log(array('topic_id' => $topic_id, 'revision_id' => $revision_id, 'author_id' => bbp_get_current_user_id(), 'reason' => $topic_edit_reason)); } } /** Move Topic ********************************************************/ // If the new forum id is not equal to the old forum id, run the // bbp_move_topic action and pass the topic's forum id as the // first arg and topic id as the second to update counts. if ($forum_id !== $topic->post_parent) { bbp_move_topic_handler($topic_id, $topic->post_parent, $forum_id); } /** Stickies **********************************************************/ if (!empty($_POST['bbp_stick_topic']) && in_array($_POST['bbp_stick_topic'], array_keys(bbp_get_topic_types()))) { // What's the caps? if (current_user_can('moderate')) { // What's the haps? switch ($_POST['bbp_stick_topic']) { // Sticky in forum case 'stick': bbp_stick_topic($topic_id); break; // Sticky in all forums // Sticky in all forums case 'super': bbp_stick_topic($topic_id, true); break; // Normal // Normal case 'unstick': default: bbp_unstick_topic($topic_id); break; } } } /** Additional Actions (After Save) ***********************************/ do_action('bbp_edit_topic_post_extras', $topic_id); /** Redirect **********************************************************/ // Redirect to $redirect_to = bbp_get_redirect_to(); // View all? $view_all = bbp_get_view_all(); // Get the topic URL $topic_url = bbp_get_topic_permalink($topic_id, $redirect_to); // Add view all? if (!empty($view_all)) { $topic_url = bbp_add_view_all($topic_url); } // Allow to be filtered $topic_url = apply_filters('bbp_edit_topic_redirect_to', $topic_url, $view_all, $redirect_to); /** Successful Edit ***************************************************/ // Redirect back to new topic wp_safe_redirect($topic_url); // For good measure exit; /** Errors ****************************************************************/ } else { $append_error = is_wp_error($topic_id) && $topic_id->get_error_message() ? $topic_id->get_error_message() . ' ' : ''; bbp_add_error('bbp_topic_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your topic:' . $append_error . 'Please try again.', 'bbpress')); } }
/** * Handles the front end spamming/unspamming and trashing/untrashing/deleting of * replies * * @since bbPress (r2740) * * @param string $action The requested action to compare this function to * @uses bbp_get_reply() To get the reply * @uses current_user_can() To check if the user is capable of editing or * deleting the reply * @uses check_ajax_referer() To verify the nonce and check the referer * @uses bbp_get_reply_post_type() To get the reply post type * @uses bbp_is_reply_spam() To check if the reply is marked as spam * @uses bbp_spam_reply() To make the reply as spam * @uses bbp_unspam_reply() To unmark the reply as spam * @uses wp_trash_post() To trash the reply * @uses wp_untrash_post() To untrash the reply * @uses wp_delete_post() To delete the reply * @uses do_action() Calls 'bbp_toggle_reply_handler' with success, post data * and action * @uses bbp_get_reply_url() To get the reply url * @uses wp_safe_redirect() To redirect to the reply * @uses bbPress::errors:add() To log the error messages */ function bbp_toggle_reply_handler($action = '') { // Bail if required GET actions aren't passed if (empty($_GET['reply_id'])) { return; } // Setup possible get actions $possible_actions = array('bbp_toggle_reply_spam', 'bbp_toggle_reply_trash'); // 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 $reply_id = (int) $_GET['reply_id']; // What's the reply id? $success = false; // Flag $post_data = array('ID' => $reply_id); // Prelim array // Make sure reply exists $reply = bbp_get_reply($reply_id); if (empty($reply)) { return; } // What is the user doing here? if (!current_user_can('edit_reply', $reply->ID) || 'bbp_toggle_reply_trash' === $action && !current_user_can('delete_reply', $reply->ID)) { bbp_add_error('bbp_toggle_reply_permission', __('<strong>ERROR:</strong> You do not have the permission to do that!', 'bbpress')); return; } // What action are we trying to perform? switch ($action) { // Toggle spam case 'bbp_toggle_reply_spam': check_ajax_referer('spam-reply_' . $reply_id); $is_spam = bbp_is_reply_spam($reply_id); $success = $is_spam ? bbp_unspam_reply($reply_id) : bbp_spam_reply($reply_id); $failure = $is_spam ? __('<strong>ERROR</strong>: There was a problem unmarking the reply as spam!', 'bbpress') : __('<strong>ERROR</strong>: There was a problem marking the reply as spam!', 'bbpress'); $view_all = !$is_spam; break; // Toggle trash // Toggle trash case 'bbp_toggle_reply_trash': $sub_action = in_array($_GET['sub_action'], array('trash', 'untrash', 'delete')) ? $_GET['sub_action'] : false; if (empty($sub_action)) { break; } switch ($sub_action) { case 'trash': check_ajax_referer('trash-' . bbp_get_reply_post_type() . '_' . $reply_id); $view_all = true; $success = wp_trash_post($reply_id); $failure = __('<strong>ERROR</strong>: There was a problem trashing the reply!', 'bbpress'); break; case 'untrash': check_ajax_referer('untrash-' . bbp_get_reply_post_type() . '_' . $reply_id); $success = wp_untrash_post($reply_id); $failure = __('<strong>ERROR</strong>: There was a problem untrashing the reply!', 'bbpress'); break; case 'delete': check_ajax_referer('delete-' . bbp_get_reply_post_type() . '_' . $reply_id); $success = wp_delete_post($reply_id); $failure = __('<strong>ERROR</strong>: There was a problem deleting the reply!', 'bbpress'); break; } break; } // Do additional reply toggle actions do_action('bbp_toggle_reply_handler', $success, $post_data, $action); // No errors if (false !== $success && !is_wp_error($success)) { /** Redirect **********************************************************/ // Redirect to $redirect_to = bbp_get_redirect_to(); // Get the reply URL $reply_url = bbp_get_reply_url($reply_id, $redirect_to); // Add view all if needed if (!empty($view_all)) { $reply_url = bbp_add_view_all($reply_url, true); } // Redirect back to reply wp_safe_redirect($reply_url); // For good measure exit; // Handle errors } else { bbp_add_error('bbp_toggle_reply', $failure); } }
/** * Handles the front end reporting/un-reporting of replies * * @since 1.0.0 * * @param string $action The requested action to compare this function to */ public function toggle_reply_handler($action = '') { // Bail if required GET actions aren't passed if (empty($_GET['reply_id'])) { return; } // Setup possible get actions $possible_actions = array('bbp_rc_toggle_reply_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 $reply_id = (int) $_GET['reply_id']; // What's the reply id? $success = false; // Flag $post_data = array('ID' => $reply_id); // Prelim array $redirect = ''; // Empty redirect URL // Make sure reply exists $reply = bbp_get_reply($reply_id); if (empty($reply)) { 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_reply_report': check_ajax_referer('report-reply_' . $reply_id); $is_reported = $this->is_reply_reported($reply_id); $success = true === $is_reported ? $this->unreport_reply($reply_id) : $this->report_reply($reply_id); $failure = true === $is_reported ? __('<strong>ERROR</strong>: There was a problem unmarking the reply as reported.', 'bbpress-report-content') : __('<strong>ERROR</strong>: There was a problem reporting the reply.', '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 **********************************************************/ // Redirect to $redirect_to = bbp_get_redirect_to(); // Get the reply URL $reply_url = bbp_get_reply_url($reply_id, $redirect_to); // Add view all if needed if (!empty($view_all)) { $reply_url = bbp_add_view_all($reply_url, true); } // Redirect back to reply wp_safe_redirect($reply_url); // For good measure exit; // Handle errors } else { bbp_add_error('bbp_rc_toggle_reply', $failure); } }
function my_topic_edit_handler() { //error_log("og reply id:".$_POST['bbp_reply_id']); //error_log("og redirect:".bbp_get_redirect_to()); //error_log("page uri:".$_SERVER['REQUEST_URI']); // Edit replies do not have the url that we don't want to cache (unlike new posts). // In order to disable the cache for the editing user for this topic, we need to obtain // its url // Get the post id $mytopicid = (int) $_POST['bbp_topic_id']; // Get the full redirect url $myredirect = bbp_get_redirect_to(); $myreplyurl = bbp_get_topic_permalink($mytopicid); $myforumid = bbp_get_topic_forum_id($mytopicid); error_log("topic url: " . $myreplyurl . " og topic id: " . $_POST['bbp_topic_id'] . " og forumid: " . $myforumid); // Get rid of the extras (such as the domain name and the #post123) $myreplyurlpart = trim(preg_replace("/([^\\/]+\$)/", "", preg_replace("/^https?:\\/\\/[^\\/]+(\\/*.+\\/).*/", " \$1 ", $myreplyurl))); $myforumurl = bbp_get_forum_permalink($myforumid); $myforumurlpart = trim(preg_replace("/([^\\/]+\$)/", "", preg_replace("/^https?:\\/\\/[^\\/]+(\\/*.+\\/).*/", " \$1 ", $myforumurl))); //error_log("og reply url:".home_url()); // Don't cache the topic so that the user can see their updated content and title error_log("og topic uri:" . $myreplyurlpart); my_disable_page_cache($myreplyurlpart); error_log("og topic uri:" . $myreplyurlpart); error_log("og forum uri:" . $myforumurlpart); // Don't cache the forum so that the user can see their updated title my_disable_page_cache($myreplyurlpart); }
/** * Do the actual topic toggling * * This function is used by `bbp_toggle_topic_handler()` to do the actual heavy * lifting when it comes to toggling topic. It only really makes sense to call * within that context, so if you need to call this function directly, make sure * you're also doing what the handler does too. * * @since 2.6.0 bbPress (r6133) * @access private * * @param array $args */ function bbp_toggle_topic($args = array()) { // Parse the arguments $r = bbp_parse_args($args, array('id' => 0, 'action' => '', 'sub_action' => '', 'data' => array())); // Build the nonce suffix $nonce_suffix = bbp_get_topic_post_type() . '_' . (int) $r['id']; // Default return values $retval = array('status' => 0, 'message' => '', 'redirect_to' => bbp_get_topic_permalink($r['id'], bbp_get_redirect_to()), 'view_all' => false); // What action are we trying to perform? switch ($r['action']) { // Toggle approve/unapprove case 'bbp_toggle_topic_approve': check_ajax_referer("approve-{$nonce_suffix}"); $is_pending = bbp_is_topic_pending($r['id']); $retval['view_all'] = !$is_pending; // Toggle $retval['status'] = true === $is_pending ? bbp_approve_topic($r['id']) : bbp_unapprove_topic($r['id']); // Feedback $retval['message'] = true === $is_pending ? __('<strong>ERROR</strong>: There was a problem approving the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem unapproving the topic.', 'bbpress'); break; // Toggle open/close // Toggle open/close case 'bbp_toggle_topic_close': check_ajax_referer("close-{$nonce_suffix}"); $is_open = bbp_is_topic_open($r['id']); // Toggle $retval['status'] = true === $is_open ? bbp_close_topic($r['id']) : bbp_open_topic($r['id']); // Feedback $retval['message'] = true === $is_open ? __('<strong>ERROR</strong>: There was a problem closing the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem opening the topic.', 'bbpress'); break; // Toggle sticky/super-sticky/unstick // Toggle sticky/super-sticky/unstick case 'bbp_toggle_topic_stick': check_ajax_referer("stick-{$nonce_suffix}"); $is_sticky = bbp_is_topic_sticky($r['id']); $is_super = false === $is_sticky && !empty($_GET['super']) && "1" === $_GET['super'] ? true : false; // Toggle $retval['status'] = true === $is_sticky ? bbp_unstick_topic($r['id']) : bbp_stick_topic($r['id'], $is_super); // Feedback $retval['message'] = true === $is_sticky ? __('<strong>ERROR</strong>: There was a problem unsticking the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem sticking the topic.', 'bbpress'); break; // Toggle spam // Toggle spam case 'bbp_toggle_topic_spam': check_ajax_referer("spam-{$nonce_suffix}"); $is_spam = bbp_is_topic_spam($r['id']); $retval['view_all'] = !$is_spam; // Toggle $retval['status'] = true === $is_spam ? bbp_unspam_topic($r['id']) : bbp_spam_topic($r['id']); // Feedback $retval['message'] = true === $is_spam ? __('<strong>ERROR</strong>: There was a problem unmarking the topic as spam.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem marking the topic as spam.', 'bbpress'); break; // Toggle trash // Toggle trash case 'bbp_toggle_topic_trash': switch ($r['sub_action']) { case 'trash': check_ajax_referer("trash-{$nonce_suffix}"); $retval['view_all'] = true; $retval['status'] = wp_trash_post($r['id']); $retval['message'] = __('<strong>ERROR</strong>: There was a problem trashing the topic.', 'bbpress'); break; case 'untrash': check_ajax_referer("untrash-{$nonce_suffix}"); $retval['status'] = wp_untrash_post($r['id']); $retval['message'] = __('<strong>ERROR</strong>: There was a problem untrashing the topic.', 'bbpress'); break; case 'delete': check_ajax_referer("delete-{$nonce_suffix}"); $retval['status'] = wp_delete_post($r['id']); $retval['message'] = __('<strong>ERROR</strong>: There was a problem deleting the topic.', 'bbpress'); break; } break; } // Maybe redirect back to the topic's forum if (isset($r['sub_action']) && 'delete' === $r['sub_action']) { $retval['redirect_to'] = bbp_get_forum_permalink($retval['status']->post_parent); } // Add view all if needed if (!empty($retval['view_all'])) { $retval['redirect_to'] = bbp_add_view_all($retval['redirect_to'], true); } // Filter & return return apply_filters('bbp_toggle_topic', $retval, $r, $args); }
/** * Do the actual reply toggling * * This function is used by `bbp_toggle_reply_handler()` to do the actual heavy * lifting when it comes to toggling replies. It only really makes sense to call * within that context, so if you need to call this function directly, make sure * you're also doing what the handler does too. * * @since 2.6.0 bbPress (r6133) * @access private * * @param array $args */ function bbp_toggle_reply($args = array()) { // Parse the arguments $r = bbp_parse_args($args, array('id' => 0, 'action' => '', 'sub_action' => '', 'data' => array())); // Build the nonce suffix $nonce_suffix = bbp_get_reply_post_type() . '_' . (int) $r['id']; // Default return values $retval = array('status' => 0, 'message' => '', 'redirect_to' => bbp_get_reply_url($r['id'], bbp_get_redirect_to()), 'view_all' => false); // What action are we trying to perform? switch ($r['action']) { // Toggle approve case 'bbp_toggle_reply_approve': check_ajax_referer("approve-{$nonce_suffix}"); $is_approve = bbp_is_reply_pending($r['id']); $retval['status'] = $is_approve ? bbp_approve_reply($r['id']) : bbp_unapprove_reply($r['id']); $retval['message'] = $is_approve ? __('<strong>ERROR</strong>: There was a problem approving the reply.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem unapproving the reply.', 'bbpress'); $retval['view_all'] = !$is_approve; break; // Toggle spam // Toggle spam case 'bbp_toggle_reply_spam': check_ajax_referer("spam-{$nonce_suffix}"); $is_spam = bbp_is_reply_spam($r['id']); $retval['status'] = $is_spam ? bbp_unspam_reply($r['id']) : bbp_spam_reply($r['id']); $retval['message'] = $is_spam ? __('<strong>ERROR</strong>: There was a problem unmarking the reply as spam.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem marking the reply as spam.', 'bbpress'); $retval['view_all'] = !$is_spam; break; // Toggle trash // Toggle trash case 'bbp_toggle_reply_trash': // Which subaction? switch ($r['sub_action']) { case 'trash': check_ajax_referer("trash-{$nonce_suffix}"); $retval['view_all'] = true; $retval['status'] = wp_trash_post($r['id']); $retval['message'] = __('<strong>ERROR</strong>: There was a problem trashing the reply.', 'bbpress'); break; case 'untrash': check_ajax_referer("untrash-{$nonce_suffix}"); $retval['status'] = wp_untrash_post($r['id']); $retval['message'] = __('<strong>ERROR</strong>: There was a problem untrashing the reply.', 'bbpress'); break; case 'delete': check_ajax_referer("delete-{$nonce_suffix}"); $retval['status'] = wp_delete_post($r['id']); $retval['message'] = __('<strong>ERROR</strong>: There was a problem deleting the reply.', 'bbpress'); break; } break; } // Add view all if needed if (!empty($retval['view_all'])) { $retval['redirect_to'] = bbp_add_view_all($retval['redirect_to'], true); } // Filter & return return apply_filters('bbp_toggle_reply', $retval, $r, $args); }