コード例 #1
0
ファイル: functions.php プロジェクト: rlybbert/achievements
/**
 * When an achievement is unlocked, give the points to the user.
 *
 * @param WP_Post $achievement_obj The Achievement object to send a notification for.
 * @param int $user_id ID of the user who unlocked the achievement.
 * @param int $progress_id The Progress object's ID.
 * @since Achievements (3.0)
 */
function dpa_send_points(WP_Post $achievement_obj, $user_id, $progress_id)
{
    // Let other plugins easily bypass sending points.
    if (!apply_filters('dpa_maybe_send_points', true, $achievement_obj, $user_id, $progress_id)) {
        return;
    }
    // Get the user's current total points plus the point value for the unlocked achievement
    $points = dpa_get_user_points($user_id) + dpa_get_achievement_points($achievement_obj->ID);
    $points = apply_filters('dpa_send_points_value', $points, $achievement_obj, $user_id, $progress_id);
    // Give points to user
    dpa_update_user_points($points, $user_id);
    // Allow other things to happen after the user's points have been updated
    do_action('dpa_send_points', $achievement_obj, $user_id, $progress_id, $points);
}
コード例 #2
0
ファイル: options.php プロジェクト: rlybbert/achievements
/**
 * Output the user's points total
 *
 * @param int $user_id Optional. User ID to retrieve value for
 * @since Achievements (3.0)
 */
function dpa_user_points($user_id = 0)
{
    echo number_format_i18n(dpa_get_user_points($user_id));
}
コード例 #3
0
ファイル: admin.php プロジェクト: rlybbert/achievements
        /**
         * Add the 'User Points' box to Edit User page, and a list of the user's current achievements.
         *
         * @param WP_User $user
         * @since Achievements (3.0)
         */
        public function add_profile_fields(WP_User $user)
        {
            if (!is_super_admin()) {
                return;
            }
            ?>

		<h3><?php 
            _e('Achievements Settings', 'achievements');
            ?>
</h3>
		<table class="form-table">
			<tr>
				<th><label for="dpa_achievements"><?php 
            _ex('Total Points', "User&rsquo;s total points from unlocked Achievements", 'achievements');
            ?>
</label></th>
				<td><input type="number" name="dpa_achievements" id="dpa_achievements" value="<?php 
            echo (int) dpa_get_user_points($user->ID);
            ?>
" class="regular-text" />
				</td>
			</tr>

			<?php 
            if (dpa_has_achievements(array('ach_populate_progress' => $user->ID, 'ach_progress_status' => dpa_get_unlocked_status_id(), 'posts_per_page' => -1))) {
                ?>
				<tr>
					<th scope="row"><?php 
                _e('Unlocked Achievements', 'achievements');
                ?>
</th>
					<td>
						<fieldset>
							<legend class="screen-reader-text"><?php 
                _e('Assign or remove achievements from this user', 'achievements');
                ?>
</legend>

							<?php 
                while (dpa_achievements()) {
                    ?>
								<?php 
                    dpa_the_achievement();
                    ?>

								<label><input type="checkbox" name="dpa_user_achievements[]" value="<?php 
                    echo absint(dpa_get_the_achievement_ID());
                    ?>
" <?php 
                    checked(dpa_is_achievement_unlocked(), true);
                    ?>
> <?php 
                    dpa_achievement_title();
                    ?>
</label><br>
							<?php 
                }
                ?>

						</fieldset>
					</td>
				</tr>
			<?php 
            }
            ?>

		</table>

	<?php 
        }