Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
// add a shortcode to place on the submission page (or post)
add_shortcode('videowizard', 'videowizard_main'); // shortcode, function
// create attachments column
function videodjin_custom_column($column_name, $post_id) {
global $wpdb;
if($column_name == 'attachments') {
$query = "SELECT post_title, ID FROM $wpdb->posts WHERE post_type='attachment' AND post_parent='$post_id'";
$attachments = $wpdb->get_results($query);
if($attachments) {
$my_func = create_function('$att', 'return "<a href=\"" . get_permalink($att->ID) . "\">" . $att->post_title . "</a>";');
$text = array_map($my_func, $attachments);
echo implode(', ', $text);
} else {
echo '<i>' . __('None') . '</i>';
}
}
}
function videodjin_columns($defaults) {
$defaults['attachments'] = __('Attachments');
return $defaults;
}
add_filter('manage_posts_columns', 'videodjin_columns');
add_action('manage_posts_custom_column', 'videodjin_custom_column', 10, 2);
// main submission form
function videowizard_main() {
$display = '';
if(isset($_POST['submitvideo'])) {
global $user_ID;
$post_title = $_POST['groupname'];
$post_content =
'<h3>' . $_POST['groupname'] . '</h3>' .
'<p>' . $_POST['contactemail'] . ' | ' . $_POST['contactphone'] . '</p>' .
'<p>
<b>Name of students(s):</b> ' . $_POST['studentname'] . '<br>
<b>Institute/University:</b> ' . $_POST['universityname'] . '<br>
<b>Course name:</b> ' . $_POST['coursename'] . '<br>
<b>Course year:</b> ' . $_POST['courseyear'] . '<br>
<b>Academic mentor (if applicable):</b> ' . $_POST['mentorname'] .
'</p>' .
'<p><b>Video URL (if applicable):</b> <a href="' . $_POST['videolink'] . '" rel="external">' . $_POST['videolink'] . '</a></p>' .
'<p>' . $_POST['description'] . '</p>' .
'<p><small>Video submitted on ' . date('l, d/m/Y H:i:s') . '.</small></p>';
$postarr = array(
'post_status' => 'private',
'post_type' => 'post',
'post_title' => $post_title,
'post_content' => $post_content,
'post_author' => $user_ID
);
$post_id = wp_insert_post($postarr);
wp_set_post_terms($post_id, array(3), 'category'); // "Submissions" category has ID 3
if(!function_exists('wp_handle_upload')) require_once(ABSPATH . 'wp-admin/includes/file.php');
$uploadedfile = $_FILES['videoattachment'];
$upload_overrides = array('test_form' => false);
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
if($movefile) {
$wp_filetype = $movefile['type'];
$filename = $movefile['file'];
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename($filename),
'post_mime_type' => $wp_filetype,
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_content' => '',
'post_parent' => $post_id,
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment($attachment, $filename, $post_id);
}
$headers = '';
$headers .= 'From: My WordPress Site <noreply@mywordpresssite.com>' . "\r\n";
$headers .= "Reply-To: info@mywordpresssite.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=\"" . get_settings('blog_charset') . "\"\r\n";
$submitter_message = '<p>Congratulations!</p><p>Your submissions was sucessfully processed!</p>';
$administrator_message = '<p>New submission available!</p>';
wp_mail($_POST['contactemail'], 'My WordPress Site Submission Confirmation', $submitter_message, $headers);
wp_mail('admin@mywordpresssite.com', 'My WordPress Site Submission Notification', $administrator_message, $headers);
$display .= '<div class="choose"><p>Your submission was successful! A confirmation email was sent to your email address.</p></div>';
}
$display .= '
<form id="submit-form" method="post" enctype="multipart/form-data">
<p>
<label for="groupname">Name of Group <span class="star">*</span></label>
<input name="groupname" id="groupname" type="text" placeholder="Name of Group..." required>
</p>
<p>
<label for="studentname">Name of Student(s) <span class="star">*</span></label>
<input name="studentname" id="studentname" type="text" placeholder="Name of Student(s)..." required>
<br><small>Separate multiple names with comma</small>
</p>
<p>
<label for="universityname">Institute/University <span class="star">*</span></label>
<input name="universityname" id="universityname" type="text" placeholder="Institute/University..." required>
</p>
<p>
<label for="coursename">Course Name <span class="star">*</span></label>
<input name="coursename" id="coursename" type="text" placeholder="Course Name..." required>
</p>
<p>
<label for="courseyear">Year <span class="star">*</span></label>
<input name="courseyear" id="courseyear" type="number" min="2000" max="2020" placeholder="Year..." value="' . date('Y') . '" required>
</p>
<p>
<label for="mentorname">Academic Mentor (if applicable)</label>
<input name="mentorname" id="mentorname" type="text" placeholder="Academic Mentor (if applicable)...">
</p>
<p>
<label for="contactemail">Contact Email <span class="star">*</span></label>
<input name="contactemail" id="contactemail" type="email" placeholder="Contact Email..." required>
</p>
<p>
<label for="contactphone">Contact Phone Number <span class="star">*</span></label>
<input name="contactphone" id="contactphone" type="text" placeholder="Contact Phone Number..." required>
</p>
<p class="choose">
<label for="videoattachment" class="nofloat">Video Attachment</label>
<input type="file" name="videoattachment" id="videoattachment">
<br><small>Maximum video size is <b>' . ini_get('upload_max_filesize') . '</b></small>
<br><br><b>or</b><br></br>
<label for="videolink" class="nofloat">Link to Your Video</label>
<input name="videolink" id="videolink" type="text" placeholder="Link to Your Video...">
<br><small>Add a link to your video on Youtube or Vimeo</small>
</p>
<p>
<label for="description" class="nofloat">100 Word Description or Idea <span class="star">*</span></label>
<textarea name="description" id="description" rows="8" required></textarea>
</p>
<p>
<input type="checkbox" name="agree" id="agree" value="0" required> I agree with the <a href="/terms-and-conditions/" target="_blank">terms and conditions</a>
</p>
<p>
<input type="submit" name="submitvideo" id="submitvideo" value="Submit Video">
</p>
</form>';
return $display;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.