How to set custom upload directory per user after moving content directory

With credits to petermolnar via irc://freenode.net/wordpress I can answer my own question. The key is to set an upload-dir filter in the theme’s functions.php: function per_user_upload_dir( $original ){ // use the original array for initial setup $modified = $original; // set our own replacements if ( is_user_logged_in() ) { $current_user = wp_get_current_user(); $subdir = $current_user->user_login; … Read more

Moving Media Library

There are three ways you could do this: 1. Upload all into the Media Library The most tiresome way, IMHO, is to upload all the images you got via the media library. 2. Use a plugin You can use plugins like Add From Server to import your images easily to the Media Library 3. WP-CLI … Read more

Downloadable Documents

No need to insert the download into the post as @kaiser says, you can automate: $download = get_children( ‘post_type=attachment&post_mime_type=application/pdf&post_parent=”.$post->ID ); if ($download) { foreach ( $download as $attachment_id => $attachment ) { echo “<a href=”‘.wp_get_attachment_url($attachment_id).'” target=”_blank” class=”download”>Download PDF</a>’; } }

Remove tabs from media uploader for a CPT

You can use the media_upload_tabs filter check for your post type and unset any tab you don’t want ex: function remove_media_library_tab($tabs) { if (isset($_REQUEST[‘post_id’])) { $post_type = get_post_type($_REQUEST[‘post_id’]); if (‘premium’ == $post_type) unset($tabs[‘library’]); unset($tabs[‘type_url’]); } return $tabs; } add_filter(‘media_upload_tabs’, ‘remove_media_library_tab’);

Get attachment ID of author_meta image – Attachment Metadata

I suggest you to use the more newer media manager dialog; WordPress will hanlde all the image upload stuff, including generating intermediate sizes and attachement metadata. Here a working example (it is a quick example built from a previous code, it may needs some tweaks to be used on production): add_action( ‘admin_enqueue_scripts’, ‘load_wp_media_files’ ); function … Read more

Change URLs for static content

This answer has solved the problem. You need to add this to your functions.php file. /** * Custom media upload URL * @link https://wordpress.stackexchange.com/questions/77960/wordpress-3-5-setting-custom-full-url-path-to-files-in-the-media-library */ add_filter( ‘pre_option_upload_url_path’, ‘upload_url’ ); function upload_url() { return ‘http://static.yourdomain.com/wp-content/uploads’; } There’s no need to add the original snippet to wp-config.php.

Add metabox with media uploader in a custom post type [duplicate]

I am working on something similar. This is for a podcast upload meta-box. Returns the url to the file. Here is what I have so far: //Add Metabox add_action(‘add_meta_boxes’, ‘add_upload_file_metaboxes’); function add_upload_file_metaboxes() { add_meta_box(‘swp_file_upload’, ‘File Upload’, ‘swp_file_upload’, ‘podcasts’, ‘normal’, ‘default’); } function swp_file_upload() { global $post; // Noncename needed to verify where the data originated … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)