/** * The main action used for handling theme-side POST requests * * @since 2.3.0 bbPress (r4550) * * @uses do_action() */ function bbp_post_request() { // Bail if not a POST action if (!bbp_is_post_request()) { return; } // Bail if no action if (empty($_POST['action'])) { return; } // Sanitize the POST action $action = sanitize_key($_POST['action']); // This dynamic action is probably the one you want to use. It narrows down // the scope of the 'action' without needing to check it in your function. do_action('bbp_post_request_' . $action); // Use this static action if you don't mind checking the 'action' yourself. do_action('bbp_post_request', $action); }
/** * Handle the processing and feedback of the admin tools page * * @since 2.0.0 bbPress (r2613) * * @uses check_admin_referer() To verify the nonce and the referer * @uses wp_cache_flush() To flush the cache * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type */ function bbp_admin_reset_handler() { // Bail if not resetting if (!bbp_is_post_request() || empty($_POST['bbpress-are-you-sure'])) { return; } // Only keymasters can proceed if (!bbp_is_user_keymaster()) { return; } check_admin_referer('bbpress-reset'); // Stores messages $messages = array(); $failed = __('Failed!', 'bbpress'); $success = __('Success!', 'bbpress'); // Flush the cache; things are about to get ugly. wp_cache_flush(); /** Posts *****************************************************************/ // Post types and status $fpt = bbp_get_forum_post_type(); $tpt = bbp_get_topic_post_type(); $rpt = bbp_get_reply_post_type(); // Define variables $bbp_db = bbp_db(); $statement = __('Deleting Posts… %s', 'bbpress'); $sql_posts = $bbp_db->get_results("SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')", OBJECT_K); $sql_delete = "DELETE FROM `{$bbp_db->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); /** Post Meta *************************************************************/ if (!empty($sql_posts)) { $sql_meta = array(); foreach ($sql_posts as $key => $value) { $sql_meta[] = $key; } $statement = __('Deleting Post Meta… %s', 'bbpress'); $sql_meta = implode("', '", $sql_meta); $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `post_id` IN ('{$sql_meta}');"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); } /** Forum moderators ******************************************************/ $statement = __('Deleting Forum Moderators… %s', 'bbpress'); $sql_delete = "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'forum-mod';"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); /** Topic Tags ************************************************************/ $statement = __('Deleting Topic Tags… %s', 'bbpress'); $sql_delete = "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'topic-tag';"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); /** User ******************************************************************/ // First, if we're deleting previously imported users, delete them now if (!empty($_POST['bbpress-delete-imported-users'])) { $sql_users = $bbp_db->get_results("SELECT `user_id` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '_bbp_user_id'", OBJECT_K); if (!empty($sql_users)) { $sql_meta = array(); foreach ($sql_users as $key => $value) { $sql_meta[] = $key; } $statement = __('Deleting User… %s', 'bbpress'); $sql_meta = implode("', '", $sql_meta); $sql_delete = "DELETE FROM `{$bbp_db->users}` WHERE `ID` IN ('{$sql_meta}');"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); $statement = __('Deleting User Meta… %s', 'bbpress'); $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `user_id` IN ('{$sql_meta}');"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); } } // Next, if we still have users that were not imported delete that meta data $statement = __('Deleting User Meta… %s', 'bbpress'); $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%';"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); /** Converter *************************************************************/ $statement = __('Deleting Conversion Table… %s', 'bbpress'); $table_name = $bbp_db->prefix . 'bbp_converter_translator'; if ($bbp_db->get_var("SHOW TABLES LIKE '{$table_name}'") === $table_name) { $bbp_db->query("DROP TABLE {$table_name}"); $result = $success; } else { $result = $failed; } $messages[] = sprintf($statement, $result); /** Options ***************************************************************/ $statement = __('Deleting Settings… %s', 'bbpress'); bbp_delete_options(); $messages[] = sprintf($statement, $success); /** Roles *****************************************************************/ $statement = __('Deleting Roles and Capabilities… %s', 'bbpress'); bbp_remove_roles(); bbp_remove_caps(); $messages[] = sprintf($statement, $success); /** Output ****************************************************************/ if (count($messages)) { foreach ($messages as $message) { bbp_admin_tools_feedback($message); } } }
/** * Returns topic status downdown * * This dropdown is only intended to be seen by users with the 'moderate' * capability. Because of this, no additional capablitiy checks are performed * within this function to check available topic statuses. * * @since bbPress (r5059) * * @param $args This function supports these arguments: * - select_id: Select id. Defaults to bbp_open_close_topic * - tab: Tabindex * - topic_id: Topic id * - selected: Override the selected option */ function stachestack_bbp_get_form_topic_status_dropdown($args = '') { // Parse arguments against default values $r = bbp_parse_args($args, array('select_id' => 'bbp_topic_status', 'tab' => bbp_get_tab_index(), 'topic_id' => 0, 'selected' => false), 'topic_open_close_select'); // No specific selected value passed if (empty($r['selected'])) { // Post value is passed if (bbp_is_post_request() && isset($_POST[$r['select_id']])) { $r['selected'] = $_POST[$r['select_id']]; // No Post value was passed } else { // Edit topic if (bbp_is_topic_edit()) { $r['topic_id'] = bbp_get_topic_id($r['topic_id']); $r['selected'] = bbp_get_topic_status($r['topic_id']); // New topic } else { $r['selected'] = bbp_get_public_status_id(); } } } // Used variables $tab = !empty($r['tab']) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; // Start an output buffer, we'll finish it after the select loop ob_start(); ?> <select class="form-control" name="<?php echo esc_attr($r['select_id']); ?> " id="<?php echo esc_attr($r['select_id']); ?> _select"<?php echo $tab; ?> > <?php foreach (bbp_get_topic_statuses($r['topic_id']) as $key => $label) { ?> <option value="<?php echo esc_attr($key); ?> "<?php selected($key, $r['selected']); ?> ><?php echo esc_html($label); ?> </option> <?php } ?> </select> <?php // Return the results return apply_filters('bbp_get_form_topic_status_dropdown', ob_get_clean(), $r); }
/** * Verify if a POST request came from a failed topic attempt. * * Used to avoid cross-site request forgeries when checking posted topic form * content. * * @see bbp_topic_form_fields() * * @since 2.6.0 bbPress (r5558) * * @return boolean True if is a post request with valid nonce */ function bbp_is_topic_form_post_request() { // Bail if not a post request if (!bbp_is_post_request()) { return false; } // Creating a new topic if (bbp_verify_nonce_request('bbp-new-topic')) { return true; } // Editing an existing topic if (bbp_verify_nonce_request('bbp-edit-topic')) { return true; } return false; }
/** * Pass the reply attributes for processing * * @since 2.0.0 bbPress (r2746) * * @param int $reply_id Reply id * @uses current_user_can() To check if the current user is capable of * editing the reply * @uses do_action() Calls 'bbp_reply_attributes_metabox_save' with the * reply id and parent id * @return int Parent id */ public function attributes_metabox_save($reply_id) { if ($this->bail()) { return $reply_id; } // Bail if doing an autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $reply_id; } // Bail if not a post request if (!bbp_is_post_request()) { return $reply_id; } // Check action exists if (empty($_POST['action'])) { return $reply_id; } // Nonce check if (empty($_POST['bbp_reply_metabox']) || !wp_verify_nonce($_POST['bbp_reply_metabox'], 'bbp_reply_metabox_save')) { return $reply_id; } // Current user cannot edit this reply if (!current_user_can('edit_reply', $reply_id)) { return $reply_id; } // Get the reply meta post values $topic_id = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0; $forum_id = !empty($_POST['bbp_forum_id']) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id($topic_id); $reply_to = !empty($_POST['bbp_reply_to']) ? (int) $_POST['bbp_reply_to'] : 0; // Get reply author data $anonymous_data = bbp_filter_anonymous_post_data(); $author_id = bbp_get_reply_author_id($reply_id); $is_edit = isset($_POST['hidden_post_status']) && $_POST['hidden_post_status'] !== 'draft'; // Formally update the reply bbp_update_reply($reply_id, $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit, $reply_to); // Allow other fun things to happen do_action('bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id, $reply_to); do_action('bbp_author_metabox_save', $reply_id, $anonymous_data); return $reply_id; }
/** * Return the forum visibility dropdown * * @since bbPress (r3563) * * @param int $forum_id The forum id to use * @uses bbp_is_topic_edit() To check if it's the topic edit page * @uses bbp_get_forum_visibility() To get the forum visibility * @uses apply_filters() * @return string HTML select list for selecting forum visibility */ function bbp_get_form_forum_visibility_dropdown($args = '') { // Backpat for handling passing of a forum ID if (is_int($args)) { $forum_id = (int) $args; $args = array(); } else { $forum_id = 0; } // Parse arguments against default values $r = bbp_parse_args($args, array('select_id' => 'bbp_forum_visibility', 'tab' => bbp_get_tab_index(), 'forum_id' => $forum_id, 'selected' => false), 'forum_type_select'); // No specific selected value passed if (empty($r['selected'])) { // Post value is passed if (bbp_is_post_request() && isset($_POST[$r['select_id']])) { $r['selected'] = $_POST[$r['select_id']]; // No Post value was passed } else { // Edit topic if (bbp_is_forum_edit()) { $r['forum_id'] = bbp_get_forum_id($r['forum_id']); $r['selected'] = bbp_get_forum_visibility($r['forum_id']); // New topic } else { $r['selected'] = bbp_get_public_status_id(); } } } // Used variables $tab = !empty($r['tab']) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; // Start an output buffer, we'll finish it after the select loop ob_start(); ?> <select name="<?php echo esc_attr($r['select_id']); ?> " id="<?php echo esc_attr($r['select_id']); ?> _select"<?php echo $tab; ?> > <?php foreach (bbp_get_forum_visibilities() as $key => $label) { ?> <option value="<?php echo esc_attr($key); ?> "<?php selected($key, $r['selected']); ?> ><?php echo esc_html($label); ?> </option> <?php } ?> </select> <?php // Return the results return apply_filters('bbp_get_form_forum_type_dropdown', ob_get_clean(), $r); }
/** * Return the value of the reply edit reason * * @since bbPress (r31301) * * @uses apply_filters() Calls 'bbp_get_form_reply_edit_reason' with the * reply edit reason value * @return string Reply edit reason value */ function bbp_get_form_reply_edit_reason() { // Get _POST data if (bbp_is_post_request() && isset($_POST['bbp_reply_edit_reason'])) { $reply_edit_reason = $_POST['bbp_reply_edit_reason']; // No data } else { $reply_edit_reason = ''; } return apply_filters('bbp_get_form_reply_edit_reason', esc_attr($reply_edit_reason)); }
/** * Verify if a POST request came from a failed reply attempt. * * Used to avoid cross-site request forgeries when checking posted reply form * content. * * @see bbp_reply_form_fields() * * @since 2.6.0 bbPress (r5558) * * @return boolean True if is a post request with valid nonce */ function bbp_is_reply_form_post_request() { // Bail if not a post request if (!bbp_is_post_request()) { return false; } // Creating a new reply if (bbp_verify_nonce_request('bbp-new-reply')) { return true; } // Editing an existing reply if (bbp_verify_nonce_request('bbp-edit-reply')) { return true; } return false; }
/** * Pass the topic attributes for processing * * @since 2.0.0 bbPress (r2746) * * @param int $topic_id Topic id * @uses current_user_can() To check if the current user is capable of * editing the topic * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the * topic id and parent id * @return int Parent id */ public function attributes_metabox_save($topic_id) { if ($this->bail()) { return $topic_id; } // Bail if doing an autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $topic_id; } // Bail if not a post request if (!bbp_is_post_request()) { return $topic_id; } // Nonce check if (empty($_POST['bbp_topic_metabox']) || !wp_verify_nonce($_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save')) { return $topic_id; } // Bail if current user cannot edit this topic if (!current_user_can('edit_topic', $topic_id)) { return $topic_id; } // Get the forum ID $forum_id = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0; // Get topic author data $anonymous_data = bbp_filter_anonymous_post_data(); $author_id = bbp_get_topic_author_id($topic_id); $is_edit = isset($_POST['hidden_post_status']) && $_POST['hidden_post_status'] !== 'draft'; // Formally update the topic bbp_update_topic($topic_id, $forum_id, $anonymous_data, $author_id, $is_edit); // Stickies if (!empty($_POST['bbp_stick_topic']) && in_array($_POST['bbp_stick_topic'], array('stick', 'super', 'unstick'))) { // What's the haps? switch ($_POST['bbp_stick_topic']) { // Sticky in this forum case 'stick': bbp_stick_topic($topic_id); break; // Super sticky in all forums // Super sticky in all forums case 'super': bbp_stick_topic($topic_id, true); break; // Normal // Normal case 'unstick': default: bbp_unstick_topic($topic_id); break; } } // Allow other fun things to happen do_action('bbp_topic_attributes_metabox_save', $topic_id, $forum_id); do_action('bbp_author_metabox_save', $topic_id, $anonymous_data); return $topic_id; }
/** * Save the Group Forum data on edit * * @since bbPress (r3465) * @param int $group_id (to handle Group Admin UI hook bp_group_admin_edit_after ) * @uses bbp_new_forum_handler() To check for forum creation * @uses bbp_edit_forum_handler() To check for forum edit */ public function edit_screen_save($group_id = 0) { // Bail if not a POST action if (!bbp_is_post_request()) { return; } // Admin Nonce check if (is_admin()) { check_admin_referer('groups_edit_save_' . $this->slug, 'forum_group_admin_ui'); // Theme-side Nonce check } elseif (!bbp_verify_nonce_request('groups_edit_save_' . $this->slug)) { bbp_add_error('bbp_edit_group_forum_screen_save', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress')); return; } $edit_forum = !empty($_POST['bbp-edit-group-forum']) ? true : false; $forum_id = 0; $group_id = !empty($group_id) ? $group_id : bp_get_current_group_id(); // Keymasters have the ability to reconfigure forums if (bbp_is_user_keymaster()) { $forum_ids = !empty($_POST['bbp_group_forum_id']) ? (array) (int) $_POST['bbp_group_forum_id'] : array(); // Use the existing forum IDs } else { $forum_ids = array_values(bbp_get_group_forum_ids($group_id)); } // Normalize group forum relationships now if (!empty($forum_ids)) { // Loop through forums, and make sure they exist foreach ($forum_ids as $forum_id) { // Look for forum $forum = bbp_get_forum($forum_id); // No forum exists, so break the relationship if (empty($forum)) { $this->remove_forum(array('forum_id' => $forum_id)); unset($forum_ids[$forum_id]); } } // No support for multiple forums yet $forum_id = (int) (is_array($forum_ids) ? $forum_ids[0] : $forum_ids); } // Update the group ID and forum ID relationships bbp_update_group_forum_ids($group_id, (array) $forum_ids); bbp_update_forum_group_ids($forum_id, (array) $group_id); // Update the group forum setting $group = $this->toggle_group_forum($group_id, $edit_forum); // Create a new forum if (empty($forum_id) && true === $edit_forum) { // Set the default forum status switch ($group->status) { case 'hidden': $status = bbp_get_hidden_status_id(); break; case 'private': $status = bbp_get_private_status_id(); break; case 'public': default: $status = bbp_get_public_status_id(); break; } // Create the initial forum $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => $group->name, 'post_content' => $group->description, 'post_status' => $status)); // Setup forum args with forum ID $new_forum_args = array('forum_id' => $forum_id); // If in admin, also include the group ID if (is_admin() && !empty($group_id)) { $new_forum_args['group_id'] = $group_id; } // Run the BP-specific functions for new groups $this->new_forum($new_forum_args); } // Redirect after save when not in admin if (!is_admin()) { bp_core_redirect(trailingslashit(bp_get_group_permalink(buddypress()->groups->current_group) . '/admin/' . $this->slug)); } }
/** * Pass the forum attributes for processing * * @since bbPress (r2746) * * @param int $forum_id Forum id * @uses current_user_can() To check if the current user is capable of * editing the forum * @uses bbp_get_forum() To get the forum * @uses bbp_is_forum_closed() To check if the forum is closed * @uses bbp_is_forum_category() To check if the forum is a category * @uses bbp_is_forum_private() To check if the forum is private * @uses bbp_close_forum() To close the forum * @uses bbp_open_forum() To open the forum * @uses bbp_categorize_forum() To make the forum a category * @uses bbp_normalize_forum() To make the forum normal (not category) * @uses bbp_privatize_forum() To mark the forum as private * @uses bbp_publicize_forum() To mark the forum as public * @uses do_action() Calls 'bbp_forum_attributes_metabox_save' with the * forum id * @return int Forum id */ public function attributes_metabox_save($forum_id) { if ($this->bail()) { return $forum_id; } // Bail if doing an autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $forum_id; } // Bail if not a post request if (!bbp_is_post_request()) { return $forum_id; } // Nonce check if (empty($_POST['bbp_forum_metabox']) || !wp_verify_nonce($_POST['bbp_forum_metabox'], 'bbp_forum_metabox_save')) { return $forum_id; } // Only save for forum post-types if (!bbp_is_forum($forum_id)) { return $forum_id; } // Bail if current user cannot edit this forum if (!current_user_can('edit_forum', $forum_id)) { return $forum_id; } // Parent ID $parent_id = !empty($_POST['parent_id']) && is_numeric($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0; // Update the forum meta bidness bbp_update_forum(array('forum_id' => $forum_id, 'post_parent' => (int) $parent_id)); do_action('bbp_forum_attributes_metabox_save', $forum_id); return $forum_id; }
/** * Pass the topic attributes for processing * * @since 2.0.0 bbPress (r2746) * * @param int $topic_id Topic id * @uses current_user_can() To check if the current user is capable of * editing the topic * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the * topic id and parent id * @return int Parent id */ public function save_meta_boxes($topic_id) { if ($this->bail()) { return $topic_id; } // Bail if doing an autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $topic_id; } // Bail if not a post request if (!bbp_is_post_request()) { return $topic_id; } // Nonce check if (empty($_POST['bbp_topic_metabox']) || !wp_verify_nonce($_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save')) { return $topic_id; } // Bail if current user cannot edit this topic if (!current_user_can('edit_topic', $topic_id)) { return $topic_id; } // Get the forum ID $forum_id = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0; // Get topic author data $anonymous_data = bbp_filter_anonymous_post_data(); $author_id = bbp_get_topic_author_id($topic_id); $is_edit = isset($_POST['hidden_post_status']) && $_POST['hidden_post_status'] !== 'draft'; // Formally update the topic bbp_update_topic($topic_id, $forum_id, $anonymous_data, $author_id, $is_edit); // Allow other fun things to happen do_action('bbp_topic_attributes_metabox_save', $topic_id, $forum_id); do_action('bbp_author_metabox_save', $topic_id, $anonymous_data); return $topic_id; }