예제 #1
0
/**
 * Display achievements for a user on their profile screen
 *
 * @since  1.0.0
 * @param  object $user The current user's $user object
 * @return void
 */
function badgeos_user_profile_data($user = null)
{
    $achievement_ids = array();
    echo '<h2>' . __('BadgeOS Email Notifications', 'badgeos') . '</h2>';
    echo '<table class="form-table">';
    echo '<tr>';
    echo '<th scope="row">' . __('Email Preference', 'badgeos') . '</th>';
    echo '<td>';
    echo '<label for="_badgeos_can_notify_user"><input type="checkbox" name="_badgeos_can_notify_user" id="_badgeos_can_notify_user" value="1" ' . checked(badgeos_can_notify_user($user->ID), true, false) . '/>' . __('Enable BadgeOS Email Notifications', 'badgeos') . '</label>';
    echo '</td>';
    echo '</tr>';
    echo '</table>';
    //verify uesr meets minimum role to view earned badges
    if (current_user_can(badgeos_get_manager_capability())) {
        $achievements = badgeos_get_user_achievements(array('user_id' => absint($user->ID)));
        echo '<h2>' . __('Earned Achievements', 'badgeos') . '</h2>';
        echo '<table class="form-table">';
        echo '<tr>';
        echo '<th><label for="user_points">' . __('Earned Points', 'badgeos') . '</label></th>';
        echo '<td>';
        echo '<input type="text" name="user_points" id="user_points" value="' . badgeos_get_users_points($user->ID) . '" class="regular-text" /><br />';
        echo '<span class="description">' . __("The user's points total. Entering a new total will automatically log the change and difference between totals.", 'badgeos') . '</span>';
        echo '</td>';
        echo '</tr>';
        echo '<tr><td colspan="2">';
        // List all of a user's earned achievements
        if ($achievements) {
            echo '<table class="widefat badgeos-table">';
            echo '<thead><tr>';
            echo '<th>' . __('Image', 'badgeos') . '</th>';
            echo '<th>' . __('Name', 'badgeos') . '</th>';
            echo '<th>' . __('Action', 'badgeos') . '</th>';
            echo '</tr></thead>';
            foreach ($achievements as $achievement) {
                // Setup our revoke URL
                $revoke_url = add_query_arg(array('action' => 'revoke', 'user_id' => absint($user->ID), 'achievement_id' => absint($achievement->ID)));
                echo '<tr>';
                echo '<td>' . badgeos_get_achievement_post_thumbnail($achievement->ID, array(50, 50)) . '</td>';
                echo '<td>', edit_post_link(get_the_title($achievement->ID), '', '', $achievement->ID), ' </td>';
                echo '<td> <span class="delete"><a class="error" href="' . esc_url(wp_nonce_url($revoke_url, 'badgeos_revoke_achievement')) . '">' . __('Revoke Award', 'badgeos') . '</a></span></td>';
                echo '</tr>';
                $achievement_ids[] = $achievement->ID;
            }
            echo '</table>';
        }
        echo '</td></tr>';
        echo '</table>';
        // If debug mode is on, output our achievements array
        if (badgeos_is_debug_mode()) {
            echo __('DEBUG MODE ENABLED', 'badgeos') . '<br />';
            echo __('Metadata value for:', 'badgeos') . ' _badgeos_achievements<br />';
            var_dump($achievements);
        }
        echo '<br/>';
        // Output markup for awarding achievement for user
        badgeos_profile_award_achievement($user, $achievement_ids);
    }
}
예제 #2
0
 /**
  * @covers badgeos_is_debug_mode()
  */
 public function test_badgeos_is_debug_mode_false()
 {
     // Set debug mode to false
     $settings = get_option('badgeos_settings');
     $settings['debug_mode'] = false;
     update_option('badgeos_settings', $settings);
     $this->assertFalse(badgeos_is_debug_mode());
 }