Using WordPress ‘plupload_default_params’ PHP filter

The plupload_default_params WordPress PHP filter allows you to modify the default Plupload parameters.

Usage

add_filter( 'plupload_default_params', 'your_function_name' );

function your_function_name( $params ) {
    // your custom code here
    return $params;
}

Parameters

  • $params (array) – The default Plupload parameters array.

More information

See WordPress Developer Resources: plupload_default_params

Examples

Change the URL for the Plupload handler

add_filter( 'plupload_default_params', 'change_handler_url' );

function change_handler_url( $params ) {
    $params['url'] = 'your-custom-handler-url.php';
    return $params;
}

Add a custom parameter to Plupload

add_filter( 'plupload_default_params', 'add_custom_param' );

function add_custom_param( $params ) {
    $params['custom_param'] = 'your-value';
    return $params;
}

Modify the maximum file size

add_filter( 'plupload_default_params', 'modify_max_file_size' );

function modify_max_file_size( $params ) {
    $params['max_file_size'] = '5mb';
    return $params;
}

Restrict allowed file types

add_filter( 'plupload_default_params', 'restrict_file_types' );

function restrict_file_types( $params ) {
    $params['filters'] = array(
        array(
            'title' => 'Allowed Files',
            'extensions' => 'jpg,gif,png'
        )
    );
    return $params;
}

Add an additional request header

add_filter( 'plupload_default_params', 'add_request_header' );

function add_request_header( $params ) {
    $params['headers'] = array( 'Custom-Header' => 'your-value' );
    return $params;
}