• Resolved Ehsan Fotoohabadi

    (@ehsanfotoo)


    Hi

    Please add an option in the attachments section to enable apk format so that users can upload.
    Or add a text box so that they can upload any format we write. Like: pdf, zip, rar

Viewing 1 replies (of 1 total)
  • Plugin Support Andrij Tkachenko

    (@andrijtkachenko)

    Hi Ehsan,

    You can already do this — it just needs a small PHP snippet first.

    Better Messages uses the WordPress uploader and media library for attachments, so the format list in Better Messages → Settings → Attachments only shows formats WordPress itself knows about. WordPress does not ship .apk in its allowed types, which is why you don’t see it. Once you register it, the checkbox appears and you can enable it like any other format.

    Add this snippet to your site:

    add_filter( 'ext2type', 'bm_custom_extensions' );
    function bm_custom_extensions( $types ) {
    $types['archive'][] = 'apk';
    return $types;
    }

    add_filter( 'mime_types', 'bm_custom_upload_mimes' );
    function bm_custom_upload_mimes( $existing_mimes ) {
    $existing_mimes['apk'] = 'application/vnd.android.package-archive';
    return $existing_mimes;
    }

    Then go to Better Messages → Settings → Attachments and tick apk in the Archive group. I tested this exact snippet and APK uploads work with it.

    Full guide, including how to allow a format for administrators only, is here: https://www.better-messages.com/docs/development/guides/custom-file-format

    The same snippet works for any other format — just change the extension and MIME type.

    About the free text box idea: the reason it works this way is that WordPress validates uploads against its own registered MIME types, and it will reject a file even if we accepted it in our own settings. A text box would let you type any extension but the upload would still fail unless it is registered with WordPress first, so it would be misleading. The snippet above is the step that actually makes WordPress accept the format.

    One thing worth mentioning since APK is an installable Android package: anyone in a conversation would be able to send them. If you only want certain users to upload APKs, the guide linked above shows how to leave the format disabled in settings and allow it per user instead.

    Best regards

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.