Using WordPress ‘pre_plupload_upload_ui’ PHP action

The pre_plupload_upload_ui WordPress action fires before the upload interface loads.

Usage

add_action('pre_plupload_upload_ui', 'your_custom_function');
function your_custom_function() {
  // Your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: pre_plupload_upload_ui

Examples

Add a custom message above the upload interface

Add a custom message above the WordPress media uploader.

add_action('pre_plupload_upload_ui', 'add_custom_message_above_uploader');
function add_custom_message_above_uploader() {
  echo '<p><strong>Note:</strong> Please upload only high-quality images.</p>';
}

Add custom CSS styles to the upload interface

Inject custom CSS styles to the media uploader.

add_action('pre_plupload_upload_ui', 'add_custom_css_to_uploader');
function add_custom_css_to_uploader() {
  echo '<style>.media-modal { background-color: #f1f1f1; }</style>';
}

Display a custom upload limit message

Display a custom upload limit message based on file size.

add_action('pre_plupload_upload_ui', 'display_custom_upload_limit');
function display_custom_upload_limit() {
  echo '<p><strong>Upload Limit:</strong> Maximum file size is 2MB.</p>';
}

Add a terms and conditions checkbox

Require users to agree to terms and conditions before uploading media.

add_action('pre_plupload_upload_ui', 'add_terms_and_conditions_checkbox');
function add_terms_and_conditions_checkbox() {
  echo '<input type="checkbox" id="terms_and_conditions" required> <label for="terms_and_conditions">I agree to the Terms and Conditions</label>';
}

Display a custom file type restriction message

Inform users about the allowed file types for uploading.

add_action('pre_plupload_upload_ui', 'display_custom_file_type_restrictions');
function display_custom_file_type_restrictions() {
  echo '<p><strong>Allowed File Types:</strong> JPG, PNG, and GIF only.</p>';
}