Skip to content

Instantly share code, notes, and snippets.

@paulschreiber
Created December 30, 2011 16:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save paulschreiber/1540428 to your computer and use it in GitHub Desktop.
Save paulschreiber/1540428 to your computer and use it in GitHub Desktop.
WordPress 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