Exemple #1
0
/**
 * Remove a topic from user's subscriptions
 *
 * @since bbPress (r2668)
 *
 * @param int $user_id Optional. User id
 * @param int $topic_id Optional. Topic id
 * @uses get_post() To get the post object
 * @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_remove_user_forum_subscription() To remove the user's subscription
 * @uses bbp_remove_user_topic_subscription() To remove the user's subscription
 * @uses do_action() Calls 'bbp_remove_user_subscription' with the user id and
 *                    topic id
 * @return bool True if the topic was removed from user's subscriptions,
 *               otherwise false
 */
function bbp_remove_user_subscription($user_id = 0, $object_id = 0)
{
    if (empty($user_id) || empty($object_id)) {
        return false;
    }
    $post_type = get_post_type($object_id);
    if (empty($post_type)) {
        return false;
    }
    switch ($post_type) {
        // Forum
        case bbp_get_forum_post_type():
            bbp_remove_user_forum_subscription($user_id, $object_id);
            break;
            // Topic
        // Topic
        case bbp_get_topic_post_type():
        default:
            bbp_remove_user_topic_subscription($user_id, $object_id);
            break;
    }
    do_action('bbp_remove_user_subscription', $user_id, $object_id, $post_type);
    return true;
}
Exemple #2
0
 /**
  * @covers ::bbp_remove_user_topic_subscription
  */
 public function test_bbp_remove_user_topic_subscription()
 {
     $u = $this->factory->user->create();
     $t = $this->factory->topic->create();
     // Add forum subscription.
     bbp_add_user_topic_subscription($u, $t);
     $this->assertTrue(bbp_is_user_subscribed_to_topic($u, $t));
     // Remove topic subscription.
     bbp_remove_user_topic_subscription($u, $t);
     $this->assertFalse(bbp_is_user_subscribed_to_topic($u, $t));
 }