Skip to content

Instantly share code, notes, and snippets.

@matfish2
Forked from paulschreiber/wp-upload-handle.html
Created October 9, 2012 21:57
Show Gist options
  • Save matfish2/3861702 to your computer and use it in GitHub Desktop.
Save matfish2/3861702 to your computer and use it in GitHub Desktop.
WP: upload handling (PHP)
<div class="submit-photos padding-top">
<h2>Photos</h2>
<label for="upload-image-photo">
<input id="upload-image-photo" type="text" size="36" name="upload-image-photo" value="" />
<input id="upload-image-button-photo" class="upload-image-button" type="button" value="Upload Image" />
<br />Upload a picture of yourself
</label>
</div>
<label for="upload-image-failure">
<input id="upload-image-photo" type="text" size="36" name="upload-image-photo" value="" />
<input id="upload-image-button-photo" class="upload-image-button" type="button" value="Upload Image" />
<br />Upload a picture of yourself
</label>
</div>
if ($("body.submit").length > 0) {
var formfield;
var uploadItemId;
$('.upload-image-button').click(function (e) {
e.preventDefault();
tb_show('', '/wp-admin/media-upload.php?type=image&amp;TB_iframe=true');
});
}
<?php
function af_attachment_fields_to_edit($form_fields, $post) {
if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
// align: (radio)
$form_fields['align']['value'] = 'left';
$form_fields['align']['input'] = 'hidden';
// image-size: (radio)
$form_fields['image-size']['value'] = 'full';
$form_fields['image-size']['input'] = 'hidden';
// alt text
$form_fields['image_alt']['value'] = 'alt';
$form_fields['image_alt']['input'] = 'hidden';
// Caption
$form_fields['post_excerpt']['value'] = 'excerpt';
$form_fields['post_excerpt']['input'] = 'hidden';
// Description
// $form_fields['post_content']['value'] = 'description';
// $form_fields['post_content']['input'] = 'hidden';
// URL
$form_fields['url']['input'] = 'hidden';
}
return $form_fields;
}
function af_media_upload_tabs($tabs) {
unset($tabs["type_url"]);
unset($tabs["library"]);
return $tabs;
}
//if (isset($_GET['page']) && $_GET['page'] == 'submit') {
if (!current_user_can('administrator')) {
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_enqueue_script('my-upload');
wp_enqueue_style('thickbox');
add_filter('attachment_fields_to_edit', 'af_attachment_fields_to_edit', 11, 2);
add_filter('media_upload_tabs', 'af_media_upload_tabs');
add_action('admin_head', 'af_auto_media');
}
function af_auto_media() {
echo '<style type="text/css">
#media-items .savesend, #gallery-settings * {display:none;}
</style>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment