/** * Check if user should earn an achievement, and award it if so. * * @since 1.0.0 * @param integer $achievement_id The given achievement ID to possibly award * @param integer $user_id The given user's ID * @param string $this_trigger The trigger * @param integer $site_id The triggered site id * @param array $args The triggered args * @return mixed False if user has no access, void otherwise */ function badgeos_maybe_award_achievement_to_user($achievement_id = 0, $user_id = 0, $this_trigger = '', $site_id = 0, $args = array()) { // Set to current site id if (!$site_id) { $site_id = get_current_blog_id(); } // Grab current user ID if one isn't specified if (!$user_id) { $user_id = wp_get_current_user()->ID; } // If the user does not have access to this achievement, bail here if (!badgeos_user_has_access_to_achievement($user_id, $achievement_id, $this_trigger, $site_id, $args)) { return false; } // If the user has completed the achievement, award it if (badgeos_check_achievement_completion_for_user($achievement_id, $user_id, $this_trigger, $site_id, $args)) { badgeos_award_achievement_to_user($achievement_id, $user_id, $this_trigger, $site_id, $args); } }
/** * Process the adding/revoking of achievements on the user profile page * * @since 1.0.0 * @return void */ function badgeos_process_user_data() { //verify uesr meets minimum role to view earned badges if (current_user_can(badgeos_get_manager_capability())) { // Process awarding achievement to user if (isset($_GET['action']) && 'award' == $_GET['action'] && isset($_GET['user_id']) && isset($_GET['achievement_id'])) { // Verify our nonce check_admin_referer('badgeos_award_achievement'); // Award the achievement badgeos_award_achievement_to_user(absint($_GET['achievement_id']), absint($_GET['user_id'])); // Redirect back to the user editor wp_redirect(add_query_arg('user_id', absint($_GET['user_id']), admin_url('user-edit.php'))); exit; } // Process revoking achievement from a user if (isset($_GET['action']) && 'revoke' == $_GET['action'] && isset($_GET['user_id']) && isset($_GET['achievement_id'])) { // Verify our nonce check_admin_referer('badgeos_revoke_achievement'); // Revoke the achievement badgeos_revoke_achievement_from_user(absint($_GET['achievement_id']), absint($_GET['user_id'])); // Redirect back to the user editor wp_redirect(add_query_arg('user_id', absint($_GET['user_id']), admin_url('user-edit.php'))); exit; } } }
/** * Filter submission messages and send one for Submission Approval * * @param array $messages Messages to send * @param array $args Submission Args */ function badgeos_set_submission_status_submission_approved($messages, $args) { // Award achievement badgeos_award_achievement_to_user($args['achievement_id'], $args['user_id']); // Check if user can be notified if (!badgeos_can_notify_user($args['user_data']->ID)) { return $messages; } $email = $args['user_data']->user_email; $message_id = 'badgeos_submission_approved'; if ($args['auto']) { $message_id = 'badgeos_submission_auto_approved'; $email = $args['submission_email_addresses']; $subject = sprintf(__('Approved Submission: %1$s from %2$s', 'badgeos'), get_the_title($args['achievement_id']), $args['user_data']->display_name); // set the email message $message = sprintf(__('A new submission has been received and auto-approved: In response to: %1$s Submitted by: %2$s To view all submissions, including this one, visit: %3$s', 'badgeos'), get_the_title($args['achievement_id']), $args['user_data']->display_name, admin_url('edit.php?post_type=submission')); } else { $subject = sprintf(__('Submission Approved: %s', 'badgeos'), get_the_title($args['achievement_id'])); // set the email message $message = sprintf(__('Your submission has been approved: In response to: %1$s Submitted by: %2$s %3$s', 'badgeos'), get_the_title($args['achievement_id']), $args['user_data']->display_name, get_permalink($args['achievement_id'])); } $messages[$message_id] = array('email' => $email, 'subject' => $subject, 'message' => $message); return $messages; }