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

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.

Append button to WordPress Image Details modal

Here’s an alternative technique to manipulating the template. I adapted the solution below from this post. In the approach below, the print_media_templates hook, which is triggered at the bottom of wp-includes/media-template.php, is used to output some JavaScript that removes the default image details underscores template (<script type=”text/html” id=”tmpl-image-details”>) and replaces it with a duplicated version … Read more

Impose a Maximum Limit on Image height and width upload size

Basically you just retrieve the info via getimagesize(), a basic PHP function, a then handle your errors with notes. The plugin A basic plugin as a starting point: <?php /** Plugin Name: (#67107) »kaiser« Restrict file upload via image dimensions */ function wpse67107_restrict_upload( $file ) { $file_data = getimagesize( $file ); // Handle cases where … Read more

Trigger JS when featured image upload window is opened in admin

After some digging I discovered that wp.media.featuredImage.frame() was what I was looking for: wp.media.featuredImage.frame().on(‘open’,function() { // Clever JS here }); I then discovered that the select event fires once you’ve clicked on the ‘Set featured image’ button, not when you’ve clicked on thumbnail, which was what I was after. So I bound my events to … Read more

How to set file type in wp_handle_upload?

Got it, looking at the source code I came up with this: wp_handle_upload($file_input, array(‘test_form’ => false, ‘mimes’ => array(‘csv’ => ‘text/csv’))); To override the mime types just pass mimes as an array wit the key being the file extension and the value as the mime type.

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