bbp_toggle_topic_handler (细绳$行动''

处理前端打开/关闭,垃圾/反垃圾,粘贴/反粘贴和垃圾/反垃圾/删除的主题

描述

参数

$行动

细绳(可选)请求将此函数与之进行比较的操作。

默认值:“

来源

文件:BP-论坛/主题/函数.php

函数bbp_toggle_topic_handler($ action =''){//保释如果需要,如果(空($ _get ['topic_id'])))返回;//设置可能的获取操作$ delact_actions = array('bbp_toggle_topic_close','bbp_toggle_topic_stick','bbp_toggle_topic_spam','bbp_toggle_topic_trash');//扣押如果行动不是用于此功能的(!in_array($ action,$ delach))返回;$ fally ='';//空失败字符串$ view_all = false;//假设未查看所有$ topic_id =(int)$ _get ['topic_id'];//主题ID是什么?$成功= false;//标志$ post_data = array('id'=> $ topic_id);// prelim array $ redirect =''; // Empty redirect URL // Make sure topic exists $topic = bbp_get_topic( $topic_id ); if ( empty( $topic ) ) return; // What is the user doing here? if ( !current_user_can( 'edit_topic', $topic->ID ) || ( 'bbp_toggle_topic_trash' === $action && !current_user_can( 'delete_topic', $topic->ID ) ) ) { bbp_add_error( 'bbp_toggle_topic_permission', __( 'ERROR: You do not have the permission to do that.', 'buddyboss' ) ); return; } // What action are we trying to perform? switch ( $action ) { // Toggle open/close case 'bbp_toggle_topic_close' : check_ajax_referer( 'close-topic_' . $topic_id ); $is_open = bbp_is_topic_open( $topic_id ); $success = true === $is_open ? bbp_close_topic( $topic_id ) : bbp_open_topic( $topic_id ); $failure = true === $is_open ? __( 'ERROR: There was a problem closing the discussion.', 'buddyboss' ) : __( 'ERROR: There was a problem opening the discussion.', 'buddyboss' ); break; // Toggle sticky/super-sticky/unstick case 'bbp_toggle_topic_stick' : check_ajax_referer( 'stick-topic_' . $topic_id ); $is_sticky = bbp_is_topic_sticky( $topic_id ); $is_super = false === $is_sticky && !empty( $_GET['super'] ) && ( "1" === $_GET['super'] ) ? true : false; $success = true === $is_sticky ? bbp_unstick_topic( $topic_id ) : bbp_stick_topic( $topic_id, $is_super ); $failure = true === $is_sticky ? __( 'ERROR: There was a problem unsticking the discussion.', 'buddyboss' ) : __( 'ERROR: There was a problem sticking the discussion.', 'buddyboss' ); break; // Toggle spam case 'bbp_toggle_topic_spam' : check_ajax_referer( 'spam-topic_' . $topic_id ); $is_spam = bbp_is_topic_spam( $topic_id ); $success = true === $is_spam ? bbp_unspam_topic( $topic_id ) : bbp_spam_topic( $topic_id ); $failure = true === $is_spam ? __( 'ERROR: There was a problem unmarking the discussion as spam.', 'buddyboss' ) : __( 'ERROR: There was a problem marking the discussion as spam.', 'buddyboss' ); $view_all = !$is_spam; break; // Toggle trash case 'bbp_toggle_topic_trash' : $sub_action = !empty( $_GET['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_topic_post_type() . '_' . $topic_id ); $view_all = true; $success = wp_trash_post( $topic_id ); $failure = __( 'ERROR: There was a problem trashing the discussion.', 'buddyboss' ); break; case 'untrash': check_ajax_referer( 'untrash-' . bbp_get_topic_post_type() . '_' . $topic_id ); $success = wp_untrash_post( $topic_id ); $failure = __( 'ERROR: There was a problem untrashing the discussion.', 'buddyboss' ); break; case 'delete': check_ajax_referer( 'delete-' . bbp_get_topic_post_type() . '_' . $topic_id ); $success = wp_delete_post( $topic_id ); $failure = __( 'ERROR: There was a problem deleting the discussion.', 'buddyboss' ); break; } break; } // Do additional topic toggle actions do_action( 'bbp_toggle_topic_handler', $success, $post_data, $action ); // No errors if ( false !== $success && !is_wp_error( $success ) ) { // Redirect back to the topic's forum if ( isset( $sub_action ) && ( 'delete' === $sub_action ) ) { $redirect = bbp_get_forum_permalink( $success->post_parent ); // Redirect back to the topic } else { // Get the redirect detination $permalink = bbp_get_topic_permalink( $topic_id ); $redirect = bbp_add_view_all( $permalink, $view_all ); } wp_safe_redirect( $redirect ); // For good measure exit(); // Handle errors } else { bbp_add_error( 'bbp_toggle_topic', $failure ); } }

更新日志

更新日志
版本 描述
Bbpress(R2727) 介绍。

问题吗?

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