Custom Fields
Support Meta Box Group File field not force deleting

  • Creator
  • #16945


    I have a file field within a group within a tab with a custom upload directory. The file uploads to the custom directory correctly.

    I have force_delete set to true and it does not work when set to the custom directory or the regular uploads directory. It throws a javascript alert: Error: Invalid file. No error in the console. Any ideas?

                    'id' => 'file_link',
                    'type' => 'file',
                    'name' => esc_html__( 'Upload a File' ),
                    'tooltip' =>  esc_html__( 'Select a file from your computer to upload and save as a material for this lesson' ),
                    'force_delete' => true,
                    'max_file_uploads' => 1,
                    'upload_dir' => $upload_dir['basedir'] . '/lms-materials/',
                    'visible' => array( 'type', '=', 'document' )
Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
  • #16946

    Here is the HTML as rendered in the browser:

            Upload a File
                        <a href="" target="_blank" rel="noopener noreferrer">
                            <img width="48" height="64" src="" alt="">
                        <a href="" target="_blank" rel="noopener noreferrer">CtS_A1_1.2</a>
                            <a href="#">
                    <input type="hidden" name="materials[material][0][file_link][0]" value="">
            <input type="hidden" class="rwmb-file-index" name="materials[material][0][_index_file_link]" value="_file_5dce2d87a4c73">


    Anh Tran

    Hi Jason,

    Thanks for your feedback. I’ve checked the code and see that the plugin doesn’t support force deleting a file in groups. The reason is that it’s impossible to get the field settings via Ajax (which is used to get the uploaded files to make sure it deletes the correct file – for security reason).


    Hi Anh,

    I understand the issue. Can you think of a workaround?

    I’m using the custom table extension to save the data, so would rwmb_{$field_id}_after_save_field give me the old data on save_post?

    If so, I could compare the old group array to new and if the file url is either not present or not the same, I can parse the old url to find and delete the file that way. Kind of a hack, but should work if that old data is present in the hook.

    The only other thing I’ll need to do is silence that alert 🙂

    Thanks for the help!

    Anh Tran

    I think hook to the after_save_field will work. As it’s PHP, you can compare the group array and delete the file.

    To disable the alert, I think the best way is to hide it with CSS!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.