Add/change multipart_params parameter when uploading post image

I'm working on plugin that optionally manipulates uploaded content (images). I managed to add some additional fields on "Insert media" popup under "Drop files anywhere to upload" text, but I need to send those parameters with file content to async-upload.php when uploading. Pre WP v3.3, I've been using this to achive desired results: jQuery('input:text[name="custom_text"]').keyup(function() { wpUploaderInit.multipart_params.custom_text = jQuery(this).val(); });
Category: Web

How to get file object from file_attachment?

I followed this code and so far I could get the file attachment object. But I can't seem to get the file. I need the file object to upload to IPFS via Javascript. (function($){ $.extend( wp.Uploader.prototype, { success : function( file_attachment ){ console.log( file_attachment ); } }); })(jQuery); Or, how can I get the JS file object after a file is uploaded?
Category: Web

How to locate the js code and php code for certain function?

For example, I want to debug the code for uploading an image when composing a post. I click the "Add Media" button, right-click on the "Media Library" tab, click the "Inspect" item on the context menu(Firefox). Then I click the "event" button at the end of a <div id="__wp-uploader-id-2...> element, and find several drop event handlers,one of which is tagged with jQuery, the others are tagged with "Bubbling DOM2". I click the event handlers and get these code: //for jQuery …
Category: Web

Make inline uploader (plupload) on options page upload to a specific folder

I’ve set up an options page for my CPT that contains the drag'n'drop upload area (just like Media → Add New). Basicly, I’ve copied all the relevant stuff from wp-admin/media-new.php and it works like charming. This is the code of my options page: /** * Callback for the submenu page */ function syk_bulk_import_callback() { // Taken from media-new.php if ( ! current_user_can( 'upload_files' ) ) { wp_die( __( 'Sorry, you are not allowed to upload files.' ) ); } wp_enqueue_script( …
Category: Web

async_upload.php 500 Error when Uploading larger files with slow internet connection and latency

my page runs on a local corporate network on a Windows 2016 server running IIS 10. PHP 7.1 WordPress 5.3 The page is used as a video platform. Videos up to 2GB can be uploaded. From our locations on the same network (upload speed 25-50Mbps) the upload works without any problems. The corresponding parameters in IIS, php.ini and wp-config.php are set correctly. The timeouts on the server and the proxies are set to 2 hrs. The problem is: Uploads >300MB …
Category: Web

Add inline uploader to plugin option page

I would like to implement an inline file uploader to my plugin's option page as introduced in new media grid view of the WP media library: I imagine having this drag & drop uploader in the page and getting an JSON object of either errors or attachment data back in JS when used. As far as I know there is a wp.media.view.UploaderInline class present in wp-includes/js/media-views.js but I have no idea of how to implement that in combination with the …
Category: Web

How do I increase the upload size only when editing special pages?

I have the following code to increase the upload size only when editing certain, special pages: function my_edit_page_form( $post ) { if( my_is_special_page( $post ) ) { add_filter( 'upload_size_limit', 'my_upload_size_limit' ); } } add_action( 'edit_page_form', 'my_edit_page_form' ); function my_upload_size_limit( $size ) { return 1024 * 18000; } On one of those pages, I have a Gallery shortcode. When I click on the Edit button, the "Maximum upload" message looks correct, but the upload is denied: When viewing the source, I …
Category: Web

post_id missing from the wp-admin file upload request

I'm trying to upload an attachment using the "Add Media" button placed right above the editor. The request goes to the wp-admin/async-upload.php file. I can put a var_dump($_REQUEST); call there. Whenever I upload an attachment for a regular post, the $_REQUEST contains the post_id key and the attachment has that post saved as it's parent_post. But when I do the same for a custom post type I've created, the post_id key is missing. I have no idea why. Tried adding …
Category: Web

How to delete file uploaded by Plupload

I follow the steps from here to integrate the plupload in metabox. Everything is working fine. But I did find one disadvantage of this guide. When I click the 'Remove' link from the uploaded images, it only removed it from the post, not actually deleting it in the directory. Another example of using plupload in metabox is RW Metabox plugin. This plugin does delete the file entirely when the "Delete" link is clicked. But I just can't figure it how …
Category: Web

Can I use plupload multiple queues in wordpress?

I have a frontend upload form where users can upload images for their posts and I am using Plupload for it. Since the next upload only starts once the previous upload is finised and the preview appears, it takes quite a while to upload only a couple of images. The upload is fast, but wp processing before the preview can be shown takes like 40 seconds even for a 2MB image and the server I am using is not slow …
Category: Web

Searching JQuery arrays of taxonomy terms for word matches in frontend images upload

I have a need to search through 4 different Taxonomy terms for matches of image tags. Using Jquery. Having hundereds of images to upload and tag and the theme I'm usings back end has a problem(multiple posting for each post type), I have added a hook to the wordpress exif imagemeta data, using the copyright exif tag. function hk_filter_add_exif($meta, $file, $sourceImageType) { if ( is_callable('exif_read_data') && in_array($sourceImageType, apply_filters('wp_read_image_metadata_types', array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM)) ) ) { $exif = @exif_read_data( $file ); if …
Category: Web

Use plupload to upload images and save them to custom folder and database table

I'm building a plugin and I need to upload images and save them to a separate folder from the default wp media folder and to a custom database table. I managed to do both, but for every uploaded image I get a 404 error on the console and I don't think the way I did it is good. Here is the code: <?php ?> <script> (function ( $ ) { $(document).ready(function () { var i = <?php echo $chapter->id; ?>; …
Category: Web

Plupload resize for worpdress

So, for the Plupload, I know there is a documentation to how to resize the image on the client side before uploading : http://www.plupload.com/docs/Image-Resizing-on-Client-Side However, I am not sure how to do it for Wordpress. Could you guys give me a guidance to how to do this? Thank you so much! Regards
Category: Web

Get File Object from wp.Uploader

I would like to hook into the wp.Uploader and get the FileList object containing the file to be uploaded. So far I've been able to extend the uploader using the code below, but I can't quite seem to find the "before upload" hook. $.extend( wp.Uploader.prototype, { success : function( file_attachment ){ console.log( file_attachment ); } });
Category: Web

wp.media add context

I have wp.media frame on my plugin to upload doc, docx file. I am filtering the uploaded file. If uploaded other than supported file, it will display this error I am filtering it at wp_handle_upload_prefilter to check for supported file However this filter will affect all other media uploader as well. I think, if it is possible to add context to media uploader, i could check weather to filter or not. EDIT 1: My barebone js code to // Create …
Category: Web

Does WordPress support Plupload chunking when uploading asynchronously?

I'm using the Plupload library to upload audio files to my website from the front-end. Here is an example of my Plupload config: var uploader = new plupload.Uploader({ browse_button : 'browse', file_data_name : 'async-upload', multipart_params: { action : 'upload-attachment' }, url : ajax_url, flash_swf_url : flash_swf_url, silverlight_xap_url : silverlight_xap_url, chunk_size : '200kb', max_retries : 3 }); My aim is to break files down into smaller 'chunks' whilst uploading. Plupload has built-in support for this. My question An example of server-side …
Category: Web

Is custom behaviour possible when asynchronously uploading?

I'm using Plupload and making use of wp-admin/async-upload.php to allow my website's users to upload images from the front-end asynchronously. The default behaviour of that particular script is for files to be uploaded to the media library as posts (of post_type attachment). Users may upload as many files as they like (each file upload creates a new post). My aim is to allow users to continue to upload in this way but instead of creating a new post on each …
Category: Web

"load-scripts.php" hangs and times out when plupload is requested

I have a perplexing problem with Wordpress. When pages under /admin/ loads "load-scripts.php" with "plupload" as one of the arguments, it hangs for ever. The "Add New Post" page is one such page. For example, this URL hangs for ever: http://example.com/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate,utils,plupload,json2&ver=3.9.1 While this returns successfully immediately: http://example.com/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate,utils,json2&ver=3.9.1 When I say "hang for ever", I mean that it hangs for several minutes and finally just returns a partial result without error. By partial result, I mean minified Javascript that just ends …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.