WordPress function: limit size, only jpg, jpeg, limit of uploaded files per account

You cannot check the image before uploading, as WordPress is a serverside script. However, before inserting the image in the Media library, you have different options, as I explained in this answer, with filtering wp_handle_upload_prefilter. In your case, the function filtering the wp_handle_upload_prefilter would be something like this: add_filter(‘wp_handle_upload_prefilter’, ‘f711_image_size_prevent’); function f711_image_size_prevent($file) { // get … Read more

Post type specific upload folder in 3.5

Yes, it does. I had to do something similar just yesterday and worked out this solution. About the same as the linked solution, but with a bit more error checking. <?php add_filter(‘upload_dir’, ‘cgg_upload_dir’); function cgg_upload_dir($dir) { // xxx Lots of $_REQUEST usage in here, not a great idea. // Are we where we want to … Read more

Shared upload folder in wordpress multisite

This will force uploads for all sites to the wp-content/uploads directory. Sub-directories (like year/month) will still exist (if the setting is enabled). /** * Force all network uploads to reside in “wp-content/uploads”, and by-pass * “files” URL rewrite for site-specific directories. * * @link http://wordpress.stackexchange.com/q/147750/1685 * * @param array $dirs * @return array */ function … Read more

Restrict file uploads by extension?

I believe you can add a filter to upload_mimes to restrict to certain types. The hook: http://adambrown.info/p/wp_hooks/hook/upload_mimes The filter: add_filter(‘upload_mimes’,’restict_mime’); function restict_mime($mimes) { $mimes = array( ‘jpg|jpeg|jpe’ => ‘image/jpeg’, ‘gif’ => ‘image/gif’, ‘png’ => ‘image/png’, ); return $mimes; } From what I understand this will not work for admins or any user with the unfiltered_upload … Read more

Automatically wrap post image in div

It’s the image_send_to_editor filter: if(is_admin()){ add_filter(‘image_send_to_editor’, ‘wrap_my_div’, 10, 8); function wrap_my_div($html, $id, $caption, $title, $align, $url, $size, $alt){ return ‘<div class=”mydiv” id=”mydiv-‘.$id.'”>’.$html.'</div>’; } } For existing images/posts you can try the regex in the function below

exposing attachment uploading to the front end — delicate

here is the function i use whenever i accept uploads from front end and you can use it in your template files: function insert_attachment($file_handler,$post_id,$setthumb=’false’) { // check to make sure its a successful upload if ($_FILES[$file_handler][‘error’] !== UPLOAD_ERR_OK) __return_false(); require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’); $attach_id … Read more

Create custom tab in WordPress 5 media upload

The only way I could get this to work in WP 5 was to install the Classic Editor. Then I could use media_view_settings to add the tab. add_filter(‘media_view_settings’, ‘addMediaTab’); function addMediaTab($settings) { $settings[‘tabs’] = array(‘mymediatab’ => ‘My Media Tab’); return $settings; } BUT it appears the new UI doesn’t include those sections in Gutenberg, you … Read more

Restrict the number of images to upload per post

I won’t go into the code specifics right now, because I am not sure if you need me to. You essentially need to modify the SWFUpload JavaScript settings array to set the file_upload_limit to 1. Unfortunately I don’t believe SWFUpload allows you to change that settings variable after it has been inited, because it has … Read more

How to define a remote uploads directory?

IMHO a better approach would be adding the remote server’s directory as a locally mounted directory and use this as wp-content directory. Doing this on the block/filesystem level means that WordPress won’t notice a thing, since it appears to WordPress as normal local directory. You may want to have a look at sshfs in order … Read more

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