Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to use an automated process to replicate a non-WordPress file folder in \wp-content\uploads\ and have the files automatically registered in the Media Library.

I could use such a process to upload the files, then register them using Add From Server (http://wordpress.org/plugins/add-from-server/) or the similar Media From FTP. But that seems like excessive human input.

LR/Blog (http://www.photographers-toolbox.com/products/lrblog.php) appears to be able to save to WP and register the files at the same time. How can this be done with any files using a command line?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I would suggest using WP CLI for that. It's the (in)official WordPress command line tool, like Drush for Drupal or the Symfony2 Console Component.

Use the media command to handle your (future) attachments:

wp media import <file> [--option=value*] 

* Take a look at the docs or the CLI help tool to see what options you got.

wp media import produces WordPress attachment post types from plain files, therefore letting them appear as uploads in the WP media library.

Examples from the docs.

# Import all jpgs in the current user's "Pictures" directory, not attached to any post
wp media import ~/Pictures/**\/*.jpg

# Import a local image and set it to be the post thumbnail for a post
wp media import ~/Downloads/image.png --post_id=123 --title="A downloaded picture" --featured_image

# Import an image from the web
wp media import http://s.wordpress.org/style/images/wp-header-logo.png --title='The WordPress logo' --alt="Semantic personal publishing"

(current state of code base while writing this question - later readers, read the docs on the official site)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.