Forum Replies Created
-
AuthorPosts
-
sherwin_flight
ParticipantThis is what I've created. I used jQuery to insert the links so that the plugin code didn't need to be modified.

Basically we just need a way to specify an icon, and a callback name, and pass the post ID along to it.
sherwin_flight
ParticipantAfter further investigation this is also causing a bug that prevents the plugin from working correctly as well.
For File fields there's an option to upload files to a custom folder and also use a callback for a unique filename.
The files upload fine and you can see them attached in the Meta Box. However, you can't delete a file after it's attached because of how it's encoded.
In the plugin's sanitizer.php file there's the following function to sanitize File uploads:
private function sanitize_file( $value, $field ) { return $field['upload_dir'] ? array_map( 'esc_url_raw', $value ) : $this->sanitize_object( $value ); }It uses the esc_url_raw function to encode the file URL before storing it in the database. So a file with the name "Test File Here.pdf" becomes "Test%20File%20Here.pdf" and it is stored in the database that way. However, file names on the server do not get encoded that way, and on the server the file is still called "Test File Here.php".
As a result, the "ajax_delete_file" function in inc/fields/file.php does not delete these files and instead an error message pops up, leaving no way to actually delete these files which is a bug.
The URLs are being encoded properly for storage in the database, but that same encoding doesn't work for displaying the files or deleting them.
I corrected these two issues with two simple fixes, and confirmed that everything works as expected for me now.
- Display Issue - That issues was fixed by making the small change I mentioned in my previous comment above.
-
File Delete Bug -In inc/fields/file.php around line 70 there is this line:
$path = str_replace( home_url( '/' ), trailingslashit( ABSPATH ), $attachment );
Just wrapping that whole thing in a urldecode fixes the issue. So:
$path = urldecode(str_replace( home_url( '/' ), trailingslashit( ABSPATH ), $attachment ));With the two small changes mentioned here the files are uploaded properly, are properly encoded in the database, display properly in the Meta Boxes, and can be properly deleted.
sherwin_flight
ParticipantIn inc/fields/file.php around Line 195 there's a sprintf function that returns this info for display. I fixed my display issues by changing this:
$data['title'], $data['name'],to this:
urldecode($data['title']), urldecode($data['name']),Ideally it would be better if there were an option for this built in to the plugin.
sherwin_flight
ParticipantI tried this amd it works. But the file name displayed in the meta box isn't encoded properly.
In the folder the file name has spaces in it which we want. But when the attached file is shown in the Meta Box the encoding has %20 instead of spaces.
sherwin_flight
ParticipantHas there been an update on this?
sherwin_flight
ParticipantI saw this was recently added. Thank you very much for this feature and great support.
sherwin_flight
ParticipantThanks! That's the only option that's missing from using Metabox for all of my custom metaboxes.
sherwin_flight
ParticipantI have some custom code I use for that right now, just wasn't sure how it would work with your plugin.
The upload script we're using now has a callback for a custom upload folder, which your plugin also has, and a callback for a custom file name, which the Meta Box plugin doesn't have. We upload several types of files, and they're named differently depending on the document type.
$unit_inspection_documentation_upload_overrides = array( 'test_form' => false, 'unique_filename_callback' => 'unit_inspection_documentation_filename' ); $unit_inspection_documentation_uploaded_file = wp_handle_upload($_FILES['unit_inspection_documentation_attachment'], $unit_inspection_documentation_upload_overrides);So in our current code it calls a "unique_filename_callback" function to get the name of the file before passing it to wp_handle_upload. That function names the file based on values from the database. That all works as expected.
However, I've been migrating our custom post metaboxes over to your plugin, and these uploads are the only part I can't figure out.
It's not a huge problem, because if I can't figure it out I'll just use a second custom metabox with our own code for the file uploads, and use Meta Box for the rest. Was just hoping to combine them into one tabbed Meta Box.
Right now I'm not sure how to integrate a custom filename function
sherwin_flight
ParticipantOk, thank you.
-
AuthorPosts