Support Forum » User Profile

Forum Replies Created

Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
    Posts
  • in reply to: Custom File Actions #28777
    sherwin_flightsherwin_flight
    Participant

    This 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.

    in reply to: Encoding of Uploaded File Name #28578
    sherwin_flightsherwin_flight
    Participant

    After 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.

    1. Display Issue - That issues was fixed by making the small change I mentioned in my previous comment above.
    2. 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.

    in reply to: Encoding of Uploaded File Name #28576
    sherwin_flightsherwin_flight
    Participant

    In 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.

    in reply to: Custom upload file name #28536
    sherwin_flightsherwin_flight
    Participant

    I 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.

    in reply to: OR logic not working #28520
    sherwin_flightsherwin_flight
    Participant

    Has there been an update on this?

    in reply to: Custom upload file name #28519
    sherwin_flightsherwin_flight
    Participant

    I saw this was recently added. Thank you very much for this feature and great support.

    in reply to: Custom upload file name #27908
    sherwin_flightsherwin_flight
    Participant

    Thanks! That's the only option that's missing from using Metabox for all of my custom metaboxes.

    in reply to: Custom upload file name #27616
    sherwin_flightsherwin_flight
    Participant

    I 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

    in reply to: OR logic not working #24943
    sherwin_flightsherwin_flight
    Participant

    Ok, thank you.

Viewing 9 posts - 16 through 24 (of 24 total)