Example #1
0
    public function ap_edit_badges()
    {
        if (current_user_can('manage_options')) {
            $id = sanitize_text_field($_POST['id']);
            $badge = ap_badge_by_id($id);
            $badges_opt = '';
            foreach (ap_badge_types() as $k => $b) {
                $badges_opt .= "<option value='{$k}' " . selected($k, $badge['type'], false) . ">{$b}</option>";
            }
            $html = '
				<div id="ap-badge-edit">
					<form method="POST" data-action="ap-save-badge">
						<table class="form-table">
							<tr valign="top">
								<th scope="row"><label for="title">' . __('Title', 'ap') . '</label></th>
								<td>
									<input id="title" type="text" name="title" value="' . $badge['title'] . '" />
								</td>
							</tr>
							<tr valign="top">
								<th scope="row"><label for="description">' . __('Description', 'ap') . '</label></th>
								<td>
									<textarea cols="50" id="description" name="description">' . $badge['description'] . '</textarea>
								</td>
							</tr>
							<tr valign="top">
								<th scope="row"><label for="type">' . __('Type', 'ap') . '</label></th>
								<td>
									<select id="type" name="type">' . $badges_opt . '</select>
								</td>
							</tr>
							<tr valign="top">
								<th scope="row"><label for="min_points">' . __('Min. Points', 'ap') . '</label></th>
								<td>
									<input id="min_points" type="text" name="min_points" value="' . $badge['min_points'] . '" />
								</td>
							</tr>
							<tr valign="top">
								<th scope="row"><label for="event">' . __('Event', 'ap') . '</label></th>
								<td>
									<input type="text" name="event" value="' . $badge['event'] . '" />
								</td>
							</tr>
							<tr valign="top">
								<th scope="row"><label for="multiple">' . __('Multiple', 'ap') . '</label></th>
								<td>
									<input type="checkbox" name="multiple" ' . checked($badge['multiple'], 1, false) . 'value="1" />
								</td>
							</tr>
						</table>
						<input class="button-primary" type="submit" value="' . __('Save badge', 'ap') . '">
						<input type="hidden" name="id" value="' . $badge['id'] . '">
						<input type="hidden" name="action" value="ap_save_badges">
						<input type="hidden" name="nonce" value="' . wp_create_nonce('ap_save_badge') . '">
					</form>
				</div>
			';
            $result = array('status' => true, 'html' => $html);
            $result = apply_filters('ap_edit_badge_result', $result);
            echo json_encode($result);
        }
        die;
    }
Example #2
0
<div id="ap-user-badges">
	<ul class="ap-list-badges">
	<?php 
if ($user_badges) {
    foreach ($user_badges as $b) {
        echo '<li><ul class="ap-badge-item clearfix">';
        $badge = ap_badge_by_id($b->badge_id);
        echo '<li class="ap-badge-type"><i class="ap-icon-badge badge-' . $badge['type'] . '"></i><span>' . $badge['type'] . '</span></li>';
        echo '<li class="ap-badge-info"><strong>' . $badge['title'] . '</strong><span>' . sprintf($badge['description'], $badge['value']) . '</span></li>';
        echo '<li class="ap-total-badge">' . sprintf(_n('<span>1</span> Badge', '<span>%d</span> Badges', $count_badges[$b->badge_id], 'ap'), $count_badges[$b->badge_id]) . '</li>';
        echo '<li class="ap-badge-date ap-icon-clock">' . ap_human_time($b->date, false) . '</li>';
        echo '</ul></li>';
    }
} else {
    echo '<li class="ap-nobadges">' . __('No badges earned yet!', 'ap') . '</li>';
}
?>
	</ul>
</div>
Example #3
0
 public function select_answer($userid, $question_id, $answer_id)
 {
     $question = get_post($question_id);
     $scholar = ap_badge_by_id('scholar');
     if ($question->post_author == $userid && !ap_received_badge_on_post('scholar', $question_id)) {
         ap_award_badge($question->post_author, 'scholar', $question_id);
     }
 }