/** * @covers ::bbp_add_user_to_object */ public function test_bbp_add_user_to_object() { $u = $this->factory->user->create_many(3); $t = $this->factory->topic->create(); // Add object terms. foreach ($u as $k => $v) { bbp_add_user_to_object($t, $v, '_bbp_moderator'); } $r = get_metadata('post', $t, '_bbp_moderator', false); $this->assertCount(3, $r); }
/** * Add a user subscription * * @since 2.5.0 bbPress (r5156) * * @param int $user_id Optional. User id * @param int $object_id Optional. Topic id * @uses get_post() To get the post object * @uses do_action() Calls 'bbp_add_user_subscription' with the user & object id * @return bool Always true */ function bbp_add_user_subscription($user_id = 0, $object_id = 0) { // Bail if not enough info if (empty($user_id) || empty($object_id)) { return false; } // Get the post type $post_type = get_post_type($object_id); if (empty($post_type)) { return false; } // Bail if already subscribed if (bbp_is_user_subscribed($user_id, $object_id)) { return false; } // Bail if add fails if (!bbp_add_user_to_object($object_id, $user_id, '_bbp_subscription')) { return false; } do_action('bbp_add_user_subscription', $user_id, $object_id, $post_type); return true; }
/** * Add a moderator to an object * * @since 2.6.0 bbPRess * * @param int $object_id Traditionally a forum ID, but could be useful * @param int $user_id * * @return @mixed */ function bbp_add_moderator($object_id = 0, $user_id = 0) { return bbp_add_user_to_object($object_id, $user_id, '_bbp_moderator_id'); }