Add a file type
Use filter ‘upload_mimes‘. <?php add_filter(‘upload_mimes’,’add_java_files’); function add_java_files($mimes) { // Add file extension ‘extension’ with mime type ‘mime/type’ $mimes[‘java’] = ‘text/x-java-source’; return $mimes; }
Use filter ‘upload_mimes‘. <?php add_filter(‘upload_mimes’,’add_java_files’); function add_java_files($mimes) { // Add file extension ‘extension’ with mime type ‘mime/type’ $mimes[‘java’] = ‘text/x-java-source’; return $mimes; }
I’ve had the same issue in the past when uploading very large images. When it comes to crunching the image it fails and shows HTTP ERROR in red. However other images continue to load. It wasnt file size where it would fail but rather the pixel width and height of the images. By default PHP … Read more
You need to pass the $profileuser->ID as the second argument when you call your function and define it accordingly: add_filter(‘wp_handle_upload_prefilter’, ‘my_pre_upload’, 2, 2); // (3rd param is priority, 4th is number of args) // and pass the $userid as argument to your function function my_pre_upload($file, $userid = false){ // if no user specified, get $current_user … Read more
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
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
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
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
If this is really your code: <?php add_filter(‘attachment_fields_to_edit’, array($this, ‘attachment_fields’, 15, 2)); The reason it doesn’t work is because of a misplaced parenthesis. Try this: <?php add_filter(‘attachment_fields_to_edit’, array($this, ‘attachment_fields’), 15, 2);
The only directory a theme or a plugin should write to is the uploads directory. That is the only directory with guaranteed write access (besides the server’s temporary directory). Anything else is wrong and might not work. There is no practical difference between both, except one: the upload directory may be on another (sub) domain … Read more
I’d sugest you to properly handle new media modal integration. There’s no need to hijack wp.media.editor object’s attributes in order to use media modal in your plugins. You can inspire yourself from a demo integration plugin at github Demo #4 best suits your needs I guess