bbp_新建_回复_处理程序(字符串美元的行动='')

处理前端回复提交

描述

参数

美元的行动

(字符串)(可选)请求将此函数与之进行比较的操作

默认值:“”

文件:bp forums/repress/functions.php

函数bbp_new_reply_handler('action=''){//Bail if action不是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',error('strong>error:您确定要这样做吗?,'buddyboss');return;}//定义局部变量$topic_id=$forum_id=$reply_author=$anonymous_data=$reply_to=0;$reply_title=$reply_content=$terms=''./**回复作者***********************************************************************///如果(bbp_是匿名的话,用户是匿名的){过滤数据$anonymous;//匿名数据签出,所以设置cookie,等等……如果(!empty($Anonymous_data)和&is_数组($Anonymous_data)){bbp_set_current_Anonymous_user_data($Anonymous_data)}//用户已登录},否则{//用户无法创建回复,如果(!current_user_can('publish_reply')){bbp_add error('bbp_reply_permissions')__(“错误:您没有回复的权限。”,“buddyboss”);}//回复作者是当前用户$reply\u author=bbp\u get\u current\u user\u id()}/**主题id*****************************************************************************************************************************************************************如果(空($u POST['bbp\u主题id])add__(“错误:缺少讨论ID。”,“buddyboss”);//主题ID不是一个数字。}elseif(!是数字($\u POST['bbp\u Topic\u ID']){bbp\u添加错误('bbp\u reply\u Topic\u ID',\uuu(“错误:讨论ID必须是一个数字,”,“buddyboss”);//主题ID可能有效。}其他{//获取主题id$posted_topic_id=intval($\u POST['bbp_topic_id']);//如果(0>$posted_topic_id){bbp_add_error('bbp_reply_topic_id','strong错误:讨论id不能是负数,'buddyboss');//主题不存在}其他(!bbp_Get_topic id('posted topic topic id))(bbp{bbp{bbp{bbp{bbp}U加上加上一个错误('bbp{bbp{bbp{bbp{bbp{bbp{bbp}U加上一个加加加加加上一个加上一个错误('bbp{bbp{bbp{P{P{P{U论坛论坛回复回复主题的回复主题的主题的主题的主题的主题的主题的主题的主题的主题的主题的id,id,id($topic_id)){$forum_id=bbp_get_topic_forum_id($topic_id);//错误检查POST'ed forum id}elseif(isset($_POST['bbp_forum_id']){//如果(空($_POST['bbp_forum_id']){bbp_add Error('bbp_reply.'u forum_id',错误('bbp_reply.'u forum_id',),错误:forum id丢失,'buddyboss则传递了空论坛id'));//论坛id不是一个数字}否则(!是数字($\u POST['bbp\u Forum\u id']){bbp\u add\u error('bbp\u reply\u Forum\u id',uuu('strong>error:Forum id必须是一个数字,'buddyboss');//论坛id可能有效}否则{//获取论坛id$posted\u Forum\u id=intval($\u POST['bbp\u Forum\u id'])//如果论坛id为空(0==$posted\u forum\u id){bbp\u add\u error('bbp\u topic\u forum\u id','bbp\u error:forum id丢失','buddyboss');//forum id为负数}否则(0>$posted\u forum\u id){bbp\u add error('bbp\u topic forum\u forum\u id',';//论坛不存在}其他(!bbp_get_Forum($posted_Forum_id)){bbp_add_error('bbp_topic_Forum_id',{strong>errorerror:Forum不存在,'buddyboss');//使用POST'ed Forum id}否则{$Forum_id=$posted Forum_Forum_id;}//论坛存在,如果(!empty($Forum_id)){//论坛是一个类别,如果(bbp_是论坛类别($forum_id)){bbp_添加错误('bbp_new_reply_forum_category',错误('strong>error:此论坛是一个类别。无法在此论坛中创建任何回复。','buddyboss');//论坛不是一个类别}否则{//论坛关闭,如果(bbp_论坛关闭($forum_id)&!当前用户可以访问,则用户无法访问('edit_forum',$forum_id'){bbp_add_error('bbp_new_reply_forum_closed','bbp_error:此论坛已对新回复关闭。','buddyboss');}//论坛是私有的,如果(bbp_forum_private($forum_id)){如果(!当前用户可以('read private_private_forum'){bbp_add error'),则用户无法访问('bbp_new_reply_forum_private','bbp_('strong>ERROR:此论坛是私有的,您没有能力在其中读取或创建新的回复。','buddyboss');}//论坛隐藏,用户无法访问}其他论坛(bbp_隐藏('forum_id)){如果(!当前用户可以('read hidden_forum')){bbp_add ERROR('bbp_new_reply_forum_hidden',uuu('错误:此论坛是隐藏的,您没有能力在其中读取或创建新回复。','buddyboss');}}/**未筛选的HTML********************************************************************************///为有能力的用户从标题和内容中删除kses筛选器,并且如果已验证nonce,则(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', __( 'ERROR: Your reply cannot be empty.', 'buddyboss' ) ); /** Reply Flooding ********************************************************/ if ( !bbp_check_for_flood( $anonymous_data, $reply_author ) ) bbp_add_error( 'bbp_reply_flood', __( 'ERROR: Slow down; you move too fast.', 'buddyboss' ) ); /** 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', __( 'ERROR: Duplicate reply detected; it looks as though you\'ve already said that!', 'buddyboss' ) ); /** Reply Blacklist *******************************************************/ if ( !bbp_check_for_blacklist( $anonymous_data, $reply_author, $reply_title, $reply_content ) ) bbp_add_error( 'bbp_reply_blacklist', __( 'ERROR: Your reply cannot be created at this time.', 'buddyboss' ) ); /** 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', __( 'ERROR: Discussion is closed.', 'buddyboss' ) ); } /** 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', __( 'ERROR: There was a problem adding the tags to the topic.', 'buddyboss' ) ); } /** 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 = (array) 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 = (array) 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', __( 'ERROR: The following problem(s) have been found with your reply:' . $append_error . 'Please try again.', 'buddyboss' ) ); } }

变更日志

变更日志
版本 描述
bbPress (r2574) 介绍。

问题?

我们随时乐意为您提供代码或其他问题的帮助!搜索我们的开发者文档,联系支持,或与我们联系销售团队.