Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Insert Attachment
- *
- * @access private
- * @since 0.1.3a
- * @see shortcode_insert_recipe
- *
- * @param string $file_handler
- * @param integer $post_id
- * @param boolean $set_thumbnails
- * @return integer|boolean
- */
- private function insert_attachment( $file_handler, $post_id, $set_thumbnails = true )
- {
- // check to make sure its a successful upload
- if ( UPLOAD_ERR_OK !== $_FILES[ $file_handler ]['error'] ) {
- __return_false();
- }
- // Include required files from wp-admin to make this work
- require_once( ABSPATH . "wp-admin" . '/includes/image.php' );
- require_once( ABSPATH . "wp-admin" . '/includes/file.php' );
- require_once( ABSPATH . "wp-admin" . '/includes/media.php' );
- $attachment_id = media_handle_upload( $file_handler, $post_id );
- // Check if thumbnails should be generated
- if ( $set_thumbnails )
- {
- update_post_meta( $post_id, '_thumbnail_id', $attachment_id );
- }
- return $attachment_id;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement