简体   繁体   中英

Storing Files for WordPress plugin

I am outlining a WordPress plugin that will take some information much like a blog post, including a featured image. I do not want to use actual posts, as this information really isn't part of the blog.

My question is about storing the "Featured Image" portion of this data. I would like to just put it in the database as a BLOB along with the other information on the record, but it doesn't seem that the $wpdb object is built to hand this data type.

So my question is this: How can I use the $wpdb object to insert BLOB data into the database OR is there a better alternative to using the database for this purpose?

Assuming you mean that the plugin will collect this information for multiple entities, it sounds like a job for Custom Post Types . That'll allow you to leverage all the functionality of posts (including feature images), but they won't pollute the blog.

There are also a variety of plugins that will allow you to generate custom post types via a UI rather than having to code them. For example, you might check out the Custom Post Type UI plugin.

If you just want to use the media manager to save a single image for the plugin (rather than one per entity), you could use a tutorial like Using the WordPress Uploader in Your Plugin or Theme to integrate the media manager into your own settings page.

Also, you're right that the WordPress database doesn't store images as blobs. WordPress saves uploaded image files to the wp-content/uploads directory, and stores a URI reference to them in the database for later retrieval.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM