bp_activity_add_user_favorite (intactivity_id美元,intuser_id美元)
为用户添加一个活动提要项作为收藏。
描述
参数
- activity_id美元
-
(int)(必需)被收藏的活动项的ID。
- user_id美元
-
(int)(必需)收藏活动项的用户ID。
返回
(保龄球)成功时真,失败时假。
源
文件:bp-activity / bp-activity-functions.php
function bp_activity_add_user_favorite($activity_id, $user_id = 0){//如果没有user_id被传递,回退到已登录的用户。If(空($user_id)) {$user_id = bp_loggedin_user_id();} $my_favs = bp_get_user_meta($user_id, 'bp_favorite_activities', true);If(空($my_favs) || !Is_array ($my_favs)) {$my_favs = array();} //如果用户已经收藏了该活动项,则取消收藏。If (in_array($activity_id, $my_favs)){返回false;} //添加到用户的收藏夹。美元my_favs [] = $ activity_id;//更新收藏此活动的用户总数。 $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ); $fav_count = !empty( $fav_count ) ? (int) $fav_count + 1 : 1; // Update the users who have favorited this activity. $users = bp_activity_get_meta( $activity_id, 'bp_favorite_users', true ); if ( empty( $users ) || ! is_array( $users ) ) { $users = array(); } // Add to activity's favorited users. $users[] = $user_id; // Update user meta. bp_update_user_meta( $user_id, 'bp_favorite_activities', array_unique( $my_favs ) ); // Update activity meta bp_activity_update_meta( $activity_id, 'bp_favorite_users', array_unique( $users ) ); // Update activity meta counts. if ( bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ) ) { /** * Fires if bp_activity_update_meta() for favorite_count is successful and before returning a true value for success. * * @since BuddyPress 1.2.1 * * @param int $activity_id ID of the activity item being favorited. * @param int $user_id ID of the user doing the favoriting. */ do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id ); // Success. return true; // Saving meta was unsuccessful for an unknown reason. } else { /** * Fires if bp_activity_update_meta() for favorite_count is unsuccessful and before returning a false value for failure. * * @since BuddyPress 1.5.0 * * @param int $activity_id ID of the activity item being favorited. * @param int $user_id ID of the user doing the favoriting. */ do_action( 'bp_activity_add_user_favorite_fail', $activity_id, $user_id ); return false; } }
更新日志
版本 | 描述 |
---|---|
BuddyPress 1.2.0 | 介绍了。 |