Support » Plugin: CMB2 » Bug: Field of type “File” does not delete postmeta properly

  • Resolved sosacek

    (@sosacek)


    Hello everyone,
    the issue is reproducible when the user wants to remove the contents of a “file” field type and deletes the contents of the input element instead of clicking on the close button attached to the preview image.

    Expecting:
    Both meta keys (‘my_field’ and ‘my_field_id’) for the file field should be removed

    What happens:
    Only ‘my_field’ meta key is removed from the database while ‘my_field_id’ remains

    How to reproduce:
    1. Create a new meta field of type file
    2. Add an attachment
    3. Save the post
    4. Check database for ‘my_field’ and ‘my_field_id’ post meta
    4. Delete the contents of the input field only
    5. Save the post
    6. Check database again, ‘my_field_id’ shall still be there

    Example code:

            $cmb = new_cmb2_box(
                [
                    'id' => 'file_test_field',
                    'title' => "Test",
                    'object_types' => ['post'],
                ]
            );
            $cmb->add_field(
                [
                    'id' => 'my_field',
                    'name' => "Insert file here, then remove the input only and save the post",
                    'type' => 'file',
                ]
            );
    
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Bug: Field of type “File” does not delete postmeta properly’ is closed to new replies.