Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //**************************************
- // Attachment Insert Form
- //**************************************
- function insert_attachment_form($postID) {
- ?>
- <form id="file-form" name="file-form" method="POST" action="" enctype="multipart/form-data" >
- <input type="file" id="async-upload" name="async-upload" />
- <input type="hidden" name="postID" value="<?php echo $postID; ?>" />
- <?php wp_nonce_field('client-file-upload', 'client-file-upload'); ?>
- <input type="submit" value="Upload" id="submit" name="submit" />
- </form>
- <?php }
- //**************************************
- // Process Attachment Form
- //**************************************
- function process_attachment() {
- // verify this came from the our screen and with proper authorization,
- // because save_post can be triggered at other times
- if ( !wp_verify_nonce( $_POST['client-file-upload'], 'client-file-upload') ) {
- return $post->ID;
- }
- // Is the user allowed to edit the post or page?
- if ( !current_user_can( 'publish_posts', $post->ID ))
- return $post->ID;
- if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_FILES )) {
- require_once(ABSPATH . 'wp-admin/includes/admin.php');
- $id = media_handle_upload('async-upload', $_POST['postID']);
- unset($_FILES);
- }
- }
- add_action('init', 'process_attachment');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement