Using WordPress ‘pre-plupload-upload-ui’ PHP action

The pre-plupload-upload-ui WordPress action fires before the upload interface loads, allowing you to modify or add functionality to the upload process.

Usage

add_action('pre-plupload-upload-ui', 'your_custom_function_name');
function your_custom_function_name() {
    // your custom code here
}

Parameters

  • No parameters

More information

See WordPress Developer Resources: pre-plupload-upload-ui

Examples

Display a custom message before the upload interface

This example shows how to display a custom message before the upload interface.

add_action('pre-plupload-upload-ui', 'display_custom_message');
function display_custom_message() {
    echo '<p><strong>Note:</strong> Please ensure all files are properly named.</p>';
}

Add a custom CSS class to the upload interface container

This example adds a custom CSS class to the upload interface container.

add_action('pre-plupload-upload-ui', 'add_custom_class');
function add_custom_class() {
    echo '<script>document.addEventListener("DOMContentLoaded", function() {
        document.getElementById("plupload-upload-ui").classList.add("custom-class");
    });</script>';
}

Set a custom max file size for the upload interface

This example sets a custom max file size for the upload interface.

add_action('pre-plupload-upload-ui', 'set_custom_max_file_size');
function set_custom_max_file_size() {
    echo '<script>document.addEventListener("DOMContentLoaded", function() {
        if (typeof pluploadL10n !== "undefined") {
            pluploadL10n.max_file_size = "20mb";
        }
    });</script>';
}

Add a custom file type filter to the upload interface

This example adds a custom file type filter to the upload interface.

add_action('pre-plupload-upload-ui', 'add_custom_file_type_filter');
function add_custom_file_type_filter() {
    echo '<script>document.addEventListener("DOMContentLoaded", function() {
        if (typeof pluploadL10n !== "undefined") {
            pluploadL10n.filters.push({
                title: "Custom file types",
                extensions: "pdf,doc,docx"
            });
        }
    });</script>';
}

Disable multiple file uploads

This example disables multiple file uploads by modifying the Plupload configuration.

add_action('pre-plupload-upload-ui', 'disable_multiple_file_uploads');
function disable_multiple_file_uploads() {
    echo '<script>document.addEventListener("DOMContentLoaded", function() {
        if (typeof _wpPluploadSettings !== "undefined") {
            _wpPluploadSettings.defaults.multipart_params._multiple_files = "0";
        }
    });</script>';
}