/** * @covers badgeos_update_users_points() */ public function test_badgeos_update_users_points_as_admin() { $starting_points = 150; $admin_points = 250; $user_id = $this->factory->user->create(); update_user_meta($user_id, '_badgeos_points', $starting_points); $new_total = badgeos_update_users_points($user_id, $admin_points, 1); $this->assertSame($new_total, $admin_points); }
/** * Save extra user meta fields to the Edit Profile screen * * @since 1.0.0 * @param int $user_id User ID being saved * @return mixed false if current user can not edit users, void if can */ function badgeos_save_user_profile_fields($user_id = 0) { if (!current_user_can('edit_user', $user_id)) { return false; } $can_notify = isset($_POST['_badgeos_can_notify_user']) ? 'true' : 'false'; update_user_meta($user_id, '_badgeos_can_notify_user', $can_notify); // Update our user's points total, but only if edited if (isset($_POST['user_points']) && $_POST['user_points'] != badgeos_get_users_points($user_id)) { badgeos_update_users_points($user_id, absint($_POST['user_points']), get_current_user_id()); } }
/** * Award new points to a user based on logged activites and earned badges * * @since 1.0.0 * @param integer $user_id The given user's ID * @param integer $achievement_id The given achievement's post ID * @return integer The user's updated points total */ function badgeos_award_user_points($user_id = 0, $achievement_id = 0) { // Grab our points from the provided post $points = absint(get_post_meta($achievement_id, '_badgeos_points', true)); if (!empty($points)) { return badgeos_update_users_points($user_id, $points, false, $achievement_id); } }