bbp_new_forum_handler (字符串$action''

处理前端论坛提交

描述

参数

$action

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

默认值:“

文件:bp-forums /论坛/显然也

功能bbp_new_forum_handler($行动= ''){//如果保释动作不BBP-新论坛,如果( 'BBP-新论坛' == $行动!)回报;//杜撰检查(bbp_verify_nonce_request( 'BBP-新论坛')!){bbp_add_error( 'bbp_new_forum_nonce',__( '错误:你确定你想这样做',“buddyboss'));返回;} //定义本地变量(多个)$ view_all = $ anonymous_data = FALSE;$ forum_parent_id = $ forum_author = 0;$ FORUM_TITLE = $ forum_content = '';/ **论坛作者********************************************************** / //用户无法创建论坛,如果(current_user_can( 'publish_forums')!){bbp_add_error( 'bbp_forum_permissions',__(“错误:您没有权限创建新论坛“,‘buddyboss’));返回; } // Forum author is current user $forum_author = bbp_get_current_user_id(); // 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_new' ) === $_POST['_bbp_unfiltered_html_forum'] ) { remove_filter( 'bbp_new_forum_pre_title', 'wp_filter_kses' ); remove_filter( 'bbp_new_forum_pre_content', 'bbp_encode_bad', 10 ); remove_filter( 'bbp_new_forum_pre_content', 'bbp_filter_kses', 30 ); } /** 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_new_forum_pre_title', $forum_title ); // No forum title if ( empty( $forum_title ) ) bbp_add_error( 'bbp_forum_title', __( 'ERROR: Your forum needs a title.', 'buddyboss' ) ); /** Forum Content *********************************************************/ if ( !empty( $_POST['bbp_forum_content'] ) ) $forum_content = $_POST['bbp_forum_content']; // Filter and sanitize $forum_content = apply_filters( 'bbp_new_forum_pre_content', $forum_content ); // No forum content if ( empty( $forum_content ) ) bbp_add_error( 'bbp_forum_content', __( 'ERROR: Your forum description cannot be empty.', 'buddyboss' ) ); /** Forum Parent **********************************************************/ // Forum parent was passed (the norm) if ( !empty( $_POST['bbp_forum_parent_id'] ) ) { $forum_parent_id = bbp_get_forum_id( $_POST['bbp_forum_parent_id'] ); } // Filter and sanitize $forum_parent_id = apply_filters( 'bbp_new_forum_pre_parent_id', $forum_parent_id ); // No forum parent was passed (should never happen) if ( empty( $forum_parent_id ) ) { bbp_add_error( 'bbp_new_forum_missing_parent', __( 'ERROR: Your forum must have a parent.', 'buddyboss' ) ); // Forum exists } elseif ( !empty( $forum_parent_id ) ) { // Forum is a category if ( bbp_is_forum_category( $forum_parent_id ) ) { bbp_add_error( 'bbp_new_forum_forum_category', __( 'ERROR: This forum is a category. No forums can be created in this forum.', 'buddyboss' ) ); } // 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_new_forum_forum_closed', __( 'ERROR: This forum has been closed to new forums.', 'buddyboss' ) ); } // 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_new_forum_forum_private', __( 'ERROR: This forum is private and you do not have the capability to read or create new forums in it.', 'buddyboss' ) ); } // 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_new_forum_forum_hidden', __( 'ERROR: This forum is hidden and you do not have the capability to read or create new forums in it.', 'buddyboss' ) ); } } /** Forum Flooding ********************************************************/ if ( !bbp_check_for_flood( $anonymous_data, $forum_author ) ) bbp_add_error( 'bbp_forum_flood', __( 'ERROR: Slow down; you move too fast.', 'buddyboss' ) ); /** Forum Duplicate *******************************************************/ if ( !bbp_check_for_duplicate( array( 'post_type' => bbp_get_forum_post_type(), 'post_author' => $forum_author, 'post_content' => $forum_content, 'anonymous_data' => $anonymous_data ) ) ) bbp_add_error( 'bbp_forum_duplicate', __( 'ERROR: This forum already exists.', 'buddyboss' ) ); /** Forum Blacklist *******************************************************/ if ( !bbp_check_for_blacklist( $anonymous_data, $forum_author, $forum_title, $forum_content ) ) bbp_add_error( 'bbp_forum_blacklist', __( 'ERROR: Your forum cannot be created at this time.', 'buddyboss' ) ); /** Forum Moderation ******************************************************/ $post_status = bbp_get_public_status_id(); if ( !bbp_check_for_moderation( $anonymous_data, $forum_author, $forum_title, $forum_content ) ) $post_status = bbp_get_pending_status_id(); /** Additional Actions (Before Save) **************************************/ do_action( 'bbp_new_forum_pre_extras', $forum_parent_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 created $forum_data = apply_filters( 'bbp_new_forum_pre_insert', array( 'post_author' => $forum_author, 'post_title' => $forum_title, 'post_content' => $forum_content, 'post_parent' => $forum_parent_id, 'post_status' => $post_status, 'post_type' => bbp_get_forum_post_type(), 'comment_status' => 'closed' ) ); // Insert forum $forum_id = wp_insert_post( $forum_data ); /** No Errors *************************************************************/ if ( !empty( $forum_id ) && !is_wp_error( $forum_id ) ) { /** Trash Check *******************************************************/ // If the forum is trash, or the forum_status is switched to // trash, trash it properly if ( ( get_post_field( 'post_status', $forum_id ) === bbp_get_trash_status_id() ) || ( $forum_data['post_status'] === bbp_get_trash_status_id() ) ) { // Trash the reply wp_trash_post( $forum_id ); // Force view=all $view_all = true; } /** Spam Check ********************************************************/ // If reply or forum are spam, officially spam this reply if ( $forum_data['post_status'] === bbp_get_spam_status_id() ) { add_post_meta( $forum_id, '_bbp_spam_meta_status', bbp_get_public_status_id() ); // Force view=all $view_all = true; } /** Update counts, etc... *********************************************/ do_action( 'bbp_new_forum', array( 'forum_id' => $forum_id, 'post_parent' => $forum_parent_id, 'forum_author' => $forum_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() ) ); /** Additional Actions (After Save) ***********************************/ do_action( 'bbp_new_forum_post_extras', $forum_id ); /** Redirect **********************************************************/ // Redirect to $redirect_to = bbp_get_redirect_to(); // Get the forum URL $redirect_url = bbp_get_forum_permalink( $forum_id, $redirect_to ); // Add view all? if ( bbp_get_view_all() || !empty( $view_all ) ) { // User can moderate, so redirect to forum with view all set if ( current_user_can( 'moderate' ) ) { $redirect_url = bbp_add_view_all( $redirect_url ); // User cannot moderate, so redirect to forum } else { $redirect_url = bbp_get_forum_permalink( $forum_id ); } } // Allow to be filtered $redirect_url = apply_filters( 'bbp_new_forum_redirect_to', $redirect_url, $redirect_to ); /** Successful Save ***************************************************/ // Redirect back to new forum wp_safe_redirect( $redirect_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', __( 'ERROR: The following problem(s) have been found with your forum:' . $append_error, 'buddyboss' ) ); } }

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们的销售团队