: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
function wp_import_upload_form( $action ) {
* Filters the maximum allowed upload size for import files.
* @see wp_max_upload_size()
* @param int $max_upload_size Allowed upload size. Default 1 MB.
$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
$size = size_format( $bytes );
$upload_dir = wp_upload_dir();
if ( ! empty( $upload_dir['error'] ) ) :
$upload_directory_error = '<p>' . __( 'Before you can upload your import file, you will need to fix the following error:' ) . '</p>';
$upload_directory_error .= '<p><strong>' . $upload_dir['error'] . '</strong></p>';
'additional_classes' => array( 'error' ),
'paragraph_wrap' => false,
<form enctype="multipart/form-data" id="import-upload-form" method="post" class="wp-upload-form" action="<?php echo esc_url( wp_nonce_url( $action, 'import-upload' ) ); ?>">
'<label for="upload">%s</label> (%s)',
__( 'Choose a file from your computer:' ),
/* translators: %s: Maximum allowed file size. */
sprintf( __( 'Maximum size: %s' ), $size )
<input type="file" id="upload" name="import" size="25" />
<input type="hidden" name="action" value="save" />
<input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
<?php submit_button( __( 'Upload file and import' ), 'primary' ); ?>
* Adds a meta box to one or more screens.
* @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs.
* @global array $wp_meta_boxes Global meta box state.
* @param string $id Meta box ID (used in the 'id' attribute for the meta box).
* @param string $title Title of the meta box.
* @param callable $callback Function that fills the box with the desired content.
* The function should echo its output.
* @param string|array|WP_Screen $screen Optional. The screen or screens on which to show the box
* (such as a post type, 'link', or 'comment'). Accepts a single
* screen ID, WP_Screen object, or array of screen IDs. Default
* is the current screen. If you have used add_menu_page() or
* add_submenu_page() to create a new screen (and hence screen_id),
* make sure your menu slug conforms to the limits of sanitize_key()
* otherwise the 'screen' menu may not correctly render on your page.
* @param string $context Optional. The context within the screen where the box
* should display. Available contexts vary from screen to
* screen. Post edit screen contexts include 'normal', 'side',
* and 'advanced'. Comments screen contexts include 'normal'
* and 'side'. Menus meta boxes (accordion sections) all use
* the 'side' context. Global default is 'advanced'.
* @param string $priority Optional. The priority within the context where the box should show.
* Accepts 'high', 'core', 'default', or 'low'. Default 'default'.
* @param array $callback_args Optional. Data that should be set as the $args property
* of the box array (which is the second parameter passed
* to your callback). Default null.
function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
if ( empty( $screen ) ) {
$screen = get_current_screen();
} elseif ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
} elseif ( is_array( $screen ) ) {
foreach ( $screen as $single_screen ) {
add_meta_box( $id, $title, $callback, $single_screen, $context, $priority, $callback_args );
if ( ! isset( $screen->id ) ) {
if ( ! isset( $wp_meta_boxes ) ) {
$wp_meta_boxes = array();
if ( ! isset( $wp_meta_boxes[ $page ] ) ) {
$wp_meta_boxes[ $page ] = array();
if ( ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
$wp_meta_boxes[ $page ][ $context ] = array();
foreach ( array_keys( $wp_meta_boxes[ $page ] ) as $a_context ) {
foreach ( array( 'high', 'core', 'default', 'low' ) as $a_priority ) {
if ( ! isset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ) ) {
// If a core box was previously removed, don't add.
if ( ( 'core' === $priority || 'sorted' === $priority )
&& false === $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]
// If a core box was previously added by a plugin, don't add.
if ( 'core' === $priority ) {
* If the box was added with default priority, give it core priority
* to maintain sort order.
if ( 'default' === $a_priority ) {
$wp_meta_boxes[ $page ][ $a_context ]['core'][ $id ] = $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ];
unset( $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ] );
// If no priority given and ID already present, use existing priority.
if ( empty( $priority ) ) {
* Else, if we're adding to the sorted priority, we don't know the title
* or callback. Grab them from the previously added context/priority.
} elseif ( 'sorted' === $priority ) {
$title = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['title'];
$callback = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['callback'];
$callback_args = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['args'];
// An ID can be in only one priority and one context.
if ( $priority !== $a_priority || $context !== $a_context ) {
unset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] );
if ( empty( $priority ) ) {
if ( ! isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
$wp_meta_boxes[ $page ][ $context ][ $priority ] = array();
$wp_meta_boxes[ $page ][ $context ][ $priority ][ $id ] = array(
'args' => $callback_args,
* Renders a "fake" meta box with an information message,
* shown on the block editor, when an incompatible meta box is found.
* @param mixed $data_object The data object being rendered on this screen.
* Custom formats meta box arguments.
* @type string $id Meta box 'id' attribute.
* @type string $title Meta box title.
* @type callable $old_callback The original callback for this meta box.
* @type array $args Extra meta box arguments.
function do_block_editor_incompatible_meta_box( $data_object, $box ) {
$plugin = _get_plugin_from_callback( $box['old_callback'] );
$plugins = get_plugins();
/* translators: %s: The name of the plugin that generated this meta box. */
printf( __( 'This meta box, from the %s plugin, is not compatible with the block editor.' ), "<strong>{$plugin['Name']}</strong>" );
_e( 'This meta box is not compatible with the block editor.' );
if ( empty( $plugins['classic-editor/classic-editor.php'] ) ) {
if ( current_user_can( 'install_plugins' ) ) {
$install_url = wp_nonce_url(
self_admin_url( 'plugin-install.php?tab=favorites&user=wordpressdotorg&save=0' ),
'save_wporg_username_' . get_current_user_id()
/* translators: %s: A link to install the Classic Editor plugin. */
printf( __( 'Please install the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), esc_url( $install_url ) );
} elseif ( is_plugin_inactive( 'classic-editor/classic-editor.php' ) ) {
if ( current_user_can( 'activate_plugins' ) ) {
$activate_url = wp_nonce_url(
self_admin_url( 'plugins.php?action=activate&plugin=classic-editor/classic-editor.php' ),
'activate-plugin_classic-editor/classic-editor.php'
/* translators: %s: A link to activate the Classic Editor plugin. */
printf( __( 'Please activate the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), esc_url( $activate_url ) );
} elseif ( $data_object instanceof WP_Post ) {
$edit_url = add_query_arg(
'classic-editor__forget' => '',
get_edit_post_link( $data_object )
/* translators: %s: A link to use the Classic Editor plugin. */
printf( __( 'Please open the <a href="%s">classic editor</a> to use this meta box.' ), esc_url( $edit_url ) );
* Internal helper function to find the plugin from a meta box callback.
* @param callable $callback The callback function to check.
* @return array|null The plugin that the callback belongs to, or null if it doesn't belong to a plugin.
function _get_plugin_from_callback( $callback ) {
if ( is_array( $callback ) ) {
$reflection = new ReflectionMethod( $callback[0], $callback[1] );
} elseif ( is_string( $callback ) && str_contains( $callback, '::' ) ) {
$reflection = new ReflectionMethod( $callback );
$reflection = new ReflectionFunction( $callback );
} catch ( ReflectionException $exception ) {
// We could not properly reflect on the callable, so we abort here.
// Don't show an error if it's an internal PHP function.
if ( ! $reflection->isInternal() ) {
// Only show errors if the meta box was registered by a plugin.
$filename = wp_normalize_path( $reflection->getFileName() );
$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
if ( str_starts_with( $filename, $plugin_dir ) ) {
$filename = str_replace( $plugin_dir, '', $filename );
$filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename );
$plugins = get_plugins();
foreach ( $plugins as $name => $plugin ) {
if ( str_starts_with( $name, $filename ) ) {
* Meta-Box template function.
* @global array $wp_meta_boxes Global meta box state.
* @param string|WP_Screen $screen The screen identifier. If you have used add_menu_page() or
* add_submenu_page() to create a new screen (and hence screen_id)
* make sure your menu slug conforms to the limits of sanitize_key()
* otherwise the 'screen' menu may not correctly render on your page.
* @param string $context The screen context for which to display meta boxes.
* @param mixed $data_object Gets passed to the meta box callback function as the first parameter.
* Often this is the object that's the focus of the current screen,
* for example a `WP_Post` or `WP_Comment` object.
* @return int Number of meta_boxes.
function do_meta_boxes( $screen, $context, $data_object ) {
static $already_sorted = false;
if ( empty( $screen ) ) {
$screen = get_current_screen();
} elseif ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
$hidden = get_hidden_meta_boxes( $screen );
printf( '<div id="%s-sortables" class="meta-box-sortables">', esc_attr( $context ) );
* Grab the ones the user has manually sorted.
* Pull them out of their previous context/priority and into the one the user chose.
$sorted = get_user_option( "meta-box-order_$page" );
if ( ! $already_sorted && $sorted ) {
foreach ( $sorted as $box_context => $ids ) {
foreach ( explode( ',', $ids ) as $id ) {
if ( $id && 'dashboard_browser_nag' !== $id ) {
add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
if ( false === $box || ! $box['title'] ) {
$block_compatible = true;
if ( is_array( $box['args'] ) ) {
// If a meta box is just here for back compat, don't show it in the block editor.
if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
$block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
unset( $box['args']['__block_editor_compatible_meta_box'] );
// If the meta box is declared as incompatible with the block editor, override the callback function.
if ( ! $block_compatible && $screen->is_block_editor() ) {
$box['old_callback'] = $box['callback'];
$box['callback'] = 'do_block_editor_incompatible_meta_box';
if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
$block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box'];
unset( $box['args']['__back_compat_meta_box'] );
// get_hidden_meta_boxes() doesn't apply in the block editor.
$hidden_class = ( ! $screen->is_block_editor() && in_array( $box['id'], $hidden, true ) ) ? ' hide-if-js' : '';
echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes( $box['id'], $page ) . $hidden_class . '" ' . '>' . "\n";
echo '<div class="postbox-header">';
echo '<h2 class="hndle">';
if ( 'dashboard_php_nag' === $box['id'] ) {
echo '<span aria-hidden="true" class="dashicons dashicons-warning"></span>';
echo '<span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
if ( 'dashboard_browser_nag' !== $box['id'] ) {
$widget_title = $box['title'];
if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
$widget_title = $box['args']['__widget_basename'];
// Do not pass this parameter to the user callback function.
unset( $box['args']['__widget_basename'] );
echo '<div class="handle-actions hide-if-no-js">';
echo '<button type="button" class="handle-order-higher" aria-disabled="false" aria-describedby="' . $box['id'] . '-handle-order-higher-description">';
echo '<span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
echo '<span class="order-higher-indicator" aria-hidden="true"></span>';
echo '<span class="hidden" id="' . $box['id'] . '-handle-order-higher-description">' . sprintf(
/* translators: %s: Meta box title. */
echo '<button type="button" class="handle-order-lower" aria-disabled="false" aria-describedby="' . $box['id'] . '-handle-order-lower-description">';
echo '<span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
echo '<span class="order-lower-indicator" aria-hidden="true"></span>';
echo '<span class="hidden" id="' . $box['id'] . '-handle-order-lower-description">' . sprintf(
/* translators: %s: Meta box title. */
__( 'Move %s box down' ),
echo '<button type="button" class="handlediv" aria-expanded="true">';
echo '<span class="screen-reader-text">' . sprintf(
/* translators: %s: Hidden accessibility text. Meta box title. */
__( 'Toggle panel: %s' ),
echo '<span class="toggle-indicator" aria-hidden="true"></span>';
echo '<div class="inside">' . "\n";
if ( WP_DEBUG && ! $block_compatible && 'edit' === $screen->parent_base && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) {
$plugin = _get_plugin_from_callback( $box['callback'] );
$meta_box_not_compatible_message = sprintf(
/* translators: %s: The name of the plugin that generated this meta box. */
__( 'This meta box, from the %s plugin, is not compatible with the block editor.' ),
"<strong>{$plugin['Name']}</strong>"
$meta_box_not_compatible_message,
'additional_classes' => array( 'error', 'inline' ),
call_user_func( $box['callback'], $data_object, $box );
* Removes a meta box from one or more screens.
* @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs.
* @global array $wp_meta_boxes Global meta box state.
* @param string $id Meta box ID (used in the 'id' attribute for the meta box).
* @param string|array|WP_Screen $screen The screen or screens on which the meta box is shown (such as a
* post type, 'link', or 'comment'). Accepts a single screen ID,
* WP_Screen object, or array of screen IDs.
* @param string $context The context within the screen where the box is set to display.
* Contexts vary from screen to screen. Post edit screen contexts
* include 'normal', 'side', and 'advanced'. Comments screen contexts
* include 'normal' and 'side'. Menus meta boxes (accordion sections)
* all use the 'side' context.
function remove_meta_box( $id, $screen, $context ) {
if ( empty( $screen ) ) {
$screen = get_current_screen();
} elseif ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
} elseif ( is_array( $screen ) ) {
foreach ( $screen as $single_screen ) {
remove_meta_box( $id, $single_screen, $context );
if ( ! isset( $screen->id ) ) {