Using WordPress ‘post-upload-ui’ PHP action

The post-upload-ui WordPress PHP action fires on the post upload UI screen. This is a legacy (pre-3.5.0) media workflow hook.

Usage

add_action('post-upload-ui', 'your_custom_function');

function your_custom_function() {
    // your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: post-upload-ui

Examples

Add a custom message on the post upload UI

Add a custom message to the media upload screen.

add_action('post-upload-ui', 'add_custom_message');

function add_custom_message() {
    echo '<p><strong>Reminder:</strong> Please optimize your images before uploading.</p>';
}

Display user’s remaining storage space

Show the user’s remaining storage space on the media upload screen.

add_action('post-upload-ui', 'display_remaining_storage_space');

function display_remaining_storage_space() {
    $user_id = get_current_user_id();
    $storage_limit = 5000; // in MB
    $used_storage = get_user_meta($user_id, 'used_storage', true);
    $remaining_storage = $storage_limit - $used_storage;

    echo '<p>You have <strong>' . $remaining_storage . ' MB</strong> of storage remaining.</p>';
}

Add custom CSS to the post upload UI

Add custom CSS to style the media upload screen.

add_action('post-upload-ui', 'add_custom_css_to_post_upload_ui');

function add_custom_css_to_post_upload_ui() {
    echo '<style>
        .media-upload-form {
            background-color: #f5f5f5;
            padding: 20px;
            border-radius: 5px;
        }
    </style>';
}

Display a custom notice based on user role

Show a custom message to specific user roles on the media upload screen.

add_action('post-upload-ui', 'display_notice_based_on_user_role');

function display_notice_based_on_user_role() {
    $user = wp_get_current_user();

    if (in_array('editor', $user->roles)) {
        echo '<p><strong>Note:</strong> As an editor, you are responsible for moderating uploaded media.</p>';
    }
}

Add a custom button to the post upload UI

Add a custom button to the media upload screen.

add_action('post-upload-ui', 'add_custom_button_to_post_upload_ui');

function add_custom_button_to_post_upload_ui() {
    echo '<button type="button" onclick="alert(\'Custom button clicked!\')">Custom Button</button>';
}