Using WordPress ‘media_upload_html_bypass()’ PHP function

The media_upload_html_bypass() WordPress PHP function displays the browser’s built-in uploader message.

Usage

media_upload_html_bypass();

Parameters

  • None

More information

See WordPress Developer Resources: media_upload_html_bypass

Examples

Display the built-in uploader message

In this example, we use the media_upload_html_bypass() function to display the browser’s built-in uploader message when the user’s browser does not support the default uploader.

function display_bypass_message() {
  if ( ! _device_can_upload() ) {
    media_upload_html_bypass();
  }
}
add_action( 'admin_notices', 'display_bypass_message' );

Display the built-in uploader message in a custom meta box

In this example, we create a custom meta box that displays the built-in uploader message.

function custom_meta_box() {
  add_meta_box(
    'custom_meta_box_id', 
    'Custom Meta Box', 
    'meta_box_content', 
    'post'
  );
}
add_action('add_meta_boxes', 'custom_meta_box');

function meta_box_content() {
  if ( ! _device_can_upload() ) {
    media_upload_html_bypass();
  }
}

Display the built-in uploader message in the media library

In this example, we use the media_upload_html_bypass() function to display the built-in uploader message when the user is viewing the media library.

function media_library_bypass_message() {
  $screen = get_current_screen();
  if ( 'upload' === $screen->id && ! _device_can_upload() ) {
    media_upload_html_bypass();
  }
}
add_action( 'admin_notices', 'media_library_bypass_message' );

Display the built-in uploader message in a plugin settings page

In this example, we create a plugin settings page that displays the built-in uploader message.

function plugin_settings_page() {
  add_options_page(
    'Plugin Settings', 
    'Plugin Settings', 
    'manage_options', 
    'plugin-settings', 
    'settings_page_content'
  );
}
add_action('admin_menu', 'plugin_settings_page');

function settings_page_content() {
  if ( ! _device_can_upload() ) {
    media_upload_html_bypass();
  }
}

Display the built-in uploader message on a custom post type

In this example, we use the media_upload_html_bypass() function to display the built-in uploader message when the user is editing a custom post type.

function custom_post_type_bypass_message() {
  $screen = get_current_screen();
  if ( 'custom_post_type' === $screen->id && ! _device_can_upload() ) {
    media_upload_html_bypass();
  }
}
add_action( 'admin_notices', 'custom_post_type_bypass_message' );