/** * Create Submission form * @since 1.0.0 * @param integer $achievement_id The achievement ID intended for submission * @param string $title The title of the post * @param string $content The post content * @param integer $user_id The user ID * @return boolean Returns true if able to create form */ function badgeos_create_submission($achievement_id = 0, $title = '', $content = '', $user_id = 0) { $submission_data = array('post_title' => $title, 'post_content' => $content, 'post_status' => 'publish', 'post_author' => $user_id, 'post_type' => 'submission'); //insert the post into the database if ($submission_id = wp_insert_post($submission_data)) { // save the achievement ID related to the submission add_post_meta($submission_id, '_badgeos_submission_achievement_id', $achievement_id); //process attachment upload if a file was submitted if (!empty($_FILES['document_file'])) { if (!function_exists('wp_handle_upload')) { require_once ABSPATH . 'wp-admin/includes/file.php'; } $file = $_FILES['document_file']; $upload = wp_handle_upload($file, array('test_form' => false)); if (!isset($upload['error']) && isset($upload['file'])) { $filetype = wp_check_filetype(basename($upload['file']), null); $title = $file['name']; $ext = strrchr($title, '.'); $title = $ext !== false ? substr($title, 0, -strlen($ext)) : $title; $attachment = array('post_mime_type' => $filetype['type'], 'post_title' => addslashes($title), 'post_content' => '', 'post_status' => 'inherit', 'post_parent' => $submission_id); $attach_id = wp_insert_attachment($attachment, $upload['file']); } } // Available action for other processes do_action('badgeos_save_submission', $submission_id); // Submission status workflow $status_args = array('achievement_id' => $achievement_id, 'user_id' => $user_id); $status = 'pending'; // Check if submission is auto approved or not if (badgeos_is_submission_auto_approved($submission_id)) { $status = 'approved'; $status_args['auto'] = true; } badgeos_set_submission_status($submission_id, $status, $status_args); return true; } else { return false; } }
/** * AJAX Helper for approving/denying feedback * * @since 1.1.0 * @return void */ function badgeos_ajax_update_feedback() { // Verify our nonce check_ajax_referer('review_feedback', 'nonce'); // Status workflow $status_args = array('achievement_id' => $_REQUEST['achievement_id'], 'user_id' => $_REQUEST['user_id'], 'submission_type' => $_REQUEST['feedback_type']); // Setup status $status = in_array($_REQUEST['status'], array('approve', 'approved')) ? 'approved' : 'denied'; badgeos_set_submission_status($_REQUEST['feedback_id'], $status, $status_args); // Send back our successful response wp_send_json_success(array('message' => '<p class="badgeos-feedback-response success">' . __('Status Updated!', 'badgeos') . '</p>', 'status' => ucfirst($status))); }