bbp\u订阅\u处理程序(一串$action='')
处理前端订阅和取消订阅主题
描述
参数
- $action
-
(一串)(可选)要将此函数与之进行比较的请求操作
默认值:“”
来源
Function bbp_subscriptions_handler($action = ") {if (!bbp_is_subscriptions_active()) {return false;$_GET['topic_id']) {return;} //设置可能的动作$可能的动作= array('bbp_subscribe', 'bbp_unsubscribe',);if (!in_array($action, $possible_actions)) {return;} //获取所需数据$user_id = bbp_get_user_id(0, true, true);$_GET['topic_id'] = intval($_GET['topic_id']);//检查空主题if (empty($topic_id)) {bbp_add_error('bbp_subscription_topic_id', __('ERROR: No discussion was found!你订阅/取消了哪个讨论?', 'buddyboss'));//检查nonce} elseif (!bbp_verify_nonce_request(“toggle-subscription_”。 $topic_id ) ) { bbp_add_error( 'bbp_subscription_topic_id', __( 'ERROR: Are you sure you wanted to do that?', 'buddyboss' ) ); // Check current user's ability to edit the user } elseif ( !current_user_can( 'edit_user', $user_id ) ) { bbp_add_error( 'bbp_subscription_permissions', __( 'ERROR: You don\'t have the permission to edit favorites of that user!', 'buddyboss' ) ); } // Bail if we have errors if ( bbp_has_errors() ) { return; } /** No errors *************************************************************/ $is_subscription = bbp_is_user_subscribed( $user_id, $topic_id ); $success = false; if ( true === $is_subscription && 'bbp_unsubscribe' === $action ) { $success = bbp_remove_user_subscription( $user_id, $topic_id ); } elseif ( false === $is_subscription && 'bbp_subscribe' === $action ) { $success = bbp_add_user_subscription( $user_id, $topic_id ); } // Do additional subscriptions actions do_action( 'bbp_subscriptions_handler', $success, $user_id, $topic_id, $action ); // Success! if ( true === $success ) { // Redirect back from whence we came if ( bbp_is_subscriptions() ) { $redirect = bbp_get_subscriptions_permalink( $user_id ); } elseif ( bbp_is_single_user() ) { $redirect = bbp_get_user_profile_url(); } elseif ( is_singular( bbp_get_topic_post_type() ) ) { $redirect = bbp_get_topic_permalink( $topic_id ); } elseif ( is_single() || is_page() ) { $redirect = get_permalink(); } else { $redirect = get_permalink( $topic_id ); } wp_safe_redirect( $redirect ); // For good measure exit(); // Fail! Handle errors } elseif ( true === $is_subscription && 'bbp_unsubscribe' === $action ) { bbp_add_error( 'bbp_unsubscribe', __( 'ERROR: There was a problem unsubscribing from that discussion!', 'buddyboss' ) ); } elseif ( false === $is_subscription && 'bbp_subscribe' === $action ) { bbp_add_error( 'bbp_subscribe', __( 'ERROR: There was a problem subscribing to that discussion!', 'buddyboss' ) ); } }