Using WordPress ‘media_upload_max_image_resize()’ PHP function

The media_upload_max_image_resize() WordPress PHP function displays a checkbox allowing users to scale images during the upload process.

Usage

media_upload_max_image_resize();

Parameters

  • None

More information

See WordPress Developer Resources: media_upload_max_image_resize

Examples

Add a max image resize option to the media uploader

This example demonstrates how to add the max image resize option to the media uploader using the media_upload_max_image_resize() function.

function custom_media_uploader() {
    // Display the max image resize option
    media_upload_max_image_resize();
}
add_action('post-upload-ui', 'custom_media_uploader');

Customize media uploader tabs

In this example, we’ll customize the media uploader tabs by adding the media_upload_max_image_resize() function to a new tab.

function custom_media_upload_tabs($tabs) {
    // Add a new tab
    $tabs['custom_resize'] = __('Custom Resize', 'textdomain');
    return $tabs;
}
add_filter('media_upload_tabs', 'custom_media_upload_tabs');

function custom_media_upload_tab_content() {
    // Display the max image resize option
    media_upload_max_image_resize();
}
add_action('media_upload_custom_resize', 'custom_media_upload_tab_content');

Add the max image resize option to a custom media upload form

This example shows how to add the max image resize option to a custom media upload form using the media_upload_max_image_resize() function.

function custom_media_upload_form() {
    // Custom form code
    // ...

    // Add the max image resize option
    media_upload_max_image_resize();
}
add_action('custom_media_upload_form', 'custom_media_upload_form');

Display the max image resize option only for admins

In this example, we’ll display the max image resize option only for administrators using the media_upload_max_image_resize() function.

function admin_only_max_image_resize() {
    // Check if the user is an administrator
    if (current_user_can('manage_options')) {
        // Display the max image resize option
        media_upload_max_image_resize();
    }
}
add_action('post-upload-ui', 'admin_only_max_image_resize');

Change the max image resize option text

This example demonstrates how to change the text displayed next to the max image resize option using the media_upload_max_image_resize() function and a translation filter.

function custom_max_image_resize_text($translated_text, $untranslated_text, $domain) {
    if ('default' == $domain && 'Scale images on upload' == $untranslated_text) {
        $translated_text = 'Custom resize text';
    }
    return $translated_text;
}
add_filter('gettext', 'custom_max_image_resize_text', 20, 3);

function display_custom_resize_option() {
    // Display the max image resize option with custom text
    media_upload_max_image_resize();
}
add_action('post-upload-ui', 'display_custom_resize_option');