Add suffix to filename of uploaded images

I did it in a different way. I just had to update the code from Gerasimos Tsiamalos Retina Plugin to WordPress 3.5., using image editor instead of image resize. This is how it looks like: function nothing_image_make_retina_size($file, $width, $height, $crop=false) { if ( $width || $height ) { $resized_file = wp_get_image_editor($file); if ( ! is_wp_error( … Read more

WordPress Media mime type filter problem 4.0

Here’s a workaround you can put in a plugin or your theme’s functions.php file. So far no problems. /* * Workaround Bug 30123 * Affects WP 4.0+, should be fixed in WP 4.1 * https://core.trac.wordpress.org/ticket/30123 */ function bugfix30123__action__admin_init() { if ( isset( $_GET[‘attachment-filter’] ) && is_string( $_GET[‘attachment-filter’] ) ) { $_GET[‘attachment-filter’] = $_REQUEST[‘attachment-filter’] = str_replace( … Read more

Rename attachments during upload

You can try to replace $arr[‘name’] = $post_slug . ‘-‘ . $random_number . ‘.jpg’; with $arr[‘name’] = $post_slug . ‘-‘ . $arr[‘name’]; to get the file format [post_slug]-[original_filename].ext. Update: Here is an example of the $arr structure for an image with the filename car.png : Array ( [name] => car.png [type] => image/png [tmp_name] => … Read more

Media upload – choose only one file

WordPress contains 2 media up-loaders. The Flash uploader allows the selection of multiple files while the browser uploader only allows 1 file at a time. To disable the Flash uploader add the following filter to functions.php add_filter(‘flash_uploader’, create_function(‘$flash’, ‘return false;’)); EDIT After further investigation it’s probably not a great idea to use create_function. A beter … Read more

How to get max upload size and accepted file types on multisite?

Yes, you can easily grab those multisite values from database using an MU (μ) Function: get_site_option() Getting Fields Maximum Upload Size The maximum upload size, per site (NOT per blog), per file can be found using: $max_up = get_site_option(‘fileupload_maxk’); var_dump($max_up); //in kilobytes Accepted File Types The accepted file types per site (NOT per blog) can … Read more

Upload images and attachments from frontend form

I mentioned in a comment how it’s important to debug your code. Here’s why: The images are added first. In the image adding section, you’re running this line of code: $_FILES = array(“moreimages” => $image); Then when you get to your routine that adds the files, you start with this: $files = $_FILES[‘morefiles’]; Can you … Read more

White-list file types for media upload

You can hook the upload_mimes filter to accomplish this: add_filter(‘upload_mimes’, ‘wpse_43657_upload_mimes’); function wpse_43657_upload_mimes($mime_types){ $mime_types[‘rwp’] = ‘application/octet-stream’; return $mime_types; }

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