Ограничьте типы пантомимы с помощью WordPress Media Uploader - PullRequest
0 голосов
/ 21 марта 2019

Я пишу плагин и хочу использовать встроенную загрузку медиафайлов WordPress, чтобы на бэкэнд-странице можно было загружать файлы .doc и .pdf. С помощью jQuery я указал разрешенный mime в библиотеке, поэтому, если пользователь пытается загрузить недопустимый тип файла, он пропускается, но если я проверяю в библиотеке, файл присутствует.

file_frame = wp.media.frames.file_frame = wp.media({
            title: jQuery( this ).data( 'uploader_title' ),
            button: {
                text: jQuery( this ).data( 'uploader_button_text' ),
            },
            library: { type: [
                    'text/plain',
                    'application/rtf',
                    'application/msword',
                    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                    'application/vnd.ms-excel',
                    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
                    'application/pdf'
                ] },
            multiple: true  // Set to true to allow multiple files to be selected
        });

        file_frame.on( 'select', function() {

            var selection = file_frame.state().get('selection');

            selection.map( function( attachments ) {

                attachments = attachments.toJSON();
                $('#docs_upload_form').append('<input type="hidden" name="file[' + attachments.url + ']" value="' + attachments.id + '">');
            });
        });
        file_frame.open();
            });
        });
...