Hack-free Wordpress custom post type image upload?
How do you upload an image with a custom post type in Wordpress without hacking 开发者_开发问答at core files or injecting that multipart thing with jQuery?
The answer depends on what you are going to use to manage those images once they are uploaded. If the upload-and-create-custom-post is all you care about, then you could do it with a trivial plugin.
However, if you want to do the whole management enchilada, then the simplest thing might be to copy the code in wp-admin/upload.php
and wp-admin/includes/template.php
and make your own changes to that. There are very few action/filter hooks in this code and some of the comments indicate that it goes way, way back. In upload.php
there are several SQL statements that have post_type='attachment'
hardwired. Changing those should be straightforward. Mercifully, you will probably have only a few changes to make in template.php
. As the comment at the top of that file says, "A Big Mess. Also some neat functions that are nicely written." So true.
The one thing you must not do is hack the core files themselves. WP's one-click upgrade is critical to their security fixes.
精彩评论