Created
October 30, 2012 20:28
-
-
Save blobaugh/3982795 to your computer and use it in GitHub Desktop.
Insert media to WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function insertAttachment($file_handler,$post_id,$setthumb='false') { | |
| // check to make sure its a successful upload | |
| //if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false(); | |
| require_once(ABSPATH . "wp-admin" . '/includes/image.php'); | |
| require_once(ABSPATH . "wp-admin" . '/includes/file.php'); | |
| require_once(ABSPATH . "wp-admin" . '/includes/media.php'); | |
| $attach_id = media_handle_upload( $file_handler, $post_id, array(), array( 'test_form' => false, 'test_upload' => false ) ); | |
| // if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id); | |
| return $attach_id; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment