: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Displays first step of custom header image page.
public function step_1() {
$this->process_default_headers();
<h1><?php _e( 'Custom Header' ); ?></h1>
if ( current_user_can( 'customize' ) ) {
/* translators: %s: URL to header image configuration in Customizer. */
__( 'You can now manage and live-preview Custom Header in the <a href="%s">Customizer</a>.' ),
admin_url( 'customize.php?autofocus[control]=header_image' )
'additional_classes' => array( 'hide-if-no-customize' ),
if ( ! empty( $this->updated ) ) {
$updated_message = sprintf(
/* translators: %s: Home URL. */
__( 'Header updated. <a href="%s">Visit your site</a> to see how it looks.' ),
esc_url( home_url( '/' ) )
'additional_classes' => array( 'updated' ),
<h2><?php _e( 'Header Image' ); ?></h2>
<table class="form-table" role="presentation">
<?php if ( get_custom_header() || display_header_text() ) : ?>
<th scope="row"><?php _e( 'Preview' ); ?></th>
if ( $this->admin_image_div_callback ) {
call_user_func( $this->admin_image_div_callback );
$custom_header = get_custom_header();
$header_image = get_header_image();
$header_image_style = 'background-image:url(' . esc_url( $header_image ) . ');';
$header_image_style = '';
if ( $custom_header->width ) {
$header_image_style .= 'max-width:' . $custom_header->width . 'px;';
if ( $custom_header->height ) {
$header_image_style .= 'height:' . $custom_header->height . 'px;';
<div id="headimg" style="<?php echo $header_image_style; ?>">
if ( display_header_text() ) {
$style = ' style="color:#' . get_header_textcolor() . ';"';
$style = ' style="display:none;"';
<h1><a id="name" class="displaying-header-text" <?php echo $style; ?> onclick="return false;" href="<?php bloginfo( 'url' ); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1>
<div id="desc" class="displaying-header-text" <?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
<?php if ( current_user_can( 'upload_files' ) && current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
<th scope="row"><?php _e( 'Select Image' ); ?></th>
<p><?php _e( 'You can select an image to be shown at the top of your site by uploading from your computer or choosing from your media library. After selecting an image you will be able to crop it.' ); ?><br />
if ( ! current_theme_supports( 'custom-header', 'flex-height' )
&& ! current_theme_supports( 'custom-header', 'flex-width' )
/* translators: 1: Image width in pixels, 2: Image height in pixels. */
__( 'Images of exactly <strong>%1$d × %2$d pixels</strong> will be used as-is.' ) . '<br />',
get_theme_support( 'custom-header', 'width' ),
get_theme_support( 'custom-header', 'height' )
} elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) {
if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
/* translators: %s: Size in pixels. */
__( 'Images should be at least %s wide.' ) . ' ',
/* translators: %d: Custom header width. */
'<strong>' . __( '%d pixels' ) . '</strong>',
get_theme_support( 'custom-header', 'width' )
} elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) {
if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) {
/* translators: %s: Size in pixels. */
__( 'Images should be at least %s tall.' ) . ' ',
/* translators: %d: Custom header height. */
'<strong>' . __( '%d pixels' ) . '</strong>',
get_theme_support( 'custom-header', 'height' )
if ( current_theme_supports( 'custom-header', 'flex-height' )
|| current_theme_supports( 'custom-header', 'flex-width' )
if ( current_theme_supports( 'custom-header', 'width' ) ) {
/* translators: %s: Size in pixels. */
__( 'Suggested width is %s.' ) . ' ',
/* translators: %d: Custom header width. */
'<strong>' . __( '%d pixels' ) . '</strong>',
get_theme_support( 'custom-header', 'width' )
if ( current_theme_supports( 'custom-header', 'height' ) ) {
/* translators: %s: Size in pixels. */
__( 'Suggested height is %s.' ) . ' ',
/* translators: %d: Custom header height. */
'<strong>' . __( '%d pixels' ) . '</strong>',
get_theme_support( 'custom-header', 'height' )
<form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post" action="<?php echo esc_url( add_query_arg( 'step', 2 ) ); ?>">
<label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
<input type="file" id="upload" name="import" />
<input type="hidden" name="action" value="save" />
<?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ); ?>
<?php submit_button( __( 'Upload' ), '', 'submit', false ); ?>
$modal_update_href = add_query_arg(
'page' => 'custom-header',
'_wpnonce-custom-header-upload' => wp_create_nonce( 'custom-header-upload' ),
admin_url( 'themes.php' )
<label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
<button id="choose-from-library-link" class="button"
data-update-link="<?php echo esc_url( $modal_update_href ); ?>"
data-choose="<?php esc_attr_e( 'Choose a Custom Header' ); ?>"
data-update="<?php esc_attr_e( 'Set as header' ); ?>"><?php _e( 'Choose Image' ); ?></button>
<form method="post" action="<?php echo esc_url( add_query_arg( 'step', 1 ) ); ?>">
<?php submit_button( null, 'screen-reader-text', 'save-header-options', false ); ?>
<table class="form-table" role="presentation">
<?php if ( get_uploaded_header_images() ) : ?>
<th scope="row"><?php _e( 'Uploaded Images' ); ?></th>
<p><?php _e( 'You can choose one of your previously uploaded headers, or show a random one.' ); ?></p>
$this->show_header_selector( 'uploaded' );
if ( ! empty( $this->default_headers ) ) :
<th scope="row"><?php _e( 'Default Images' ); ?></th>
<?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
<p><?php _e( 'If you do not want to upload your own image, you can use one of these cool headers, or show a random one.' ); ?></p>
<p><?php _e( 'You can use one of these cool headers or show a random one on each page.' ); ?></p>
$this->show_header_selector( 'default' );
if ( get_header_image() ) :
<th scope="row"><?php _e( 'Remove Image' ); ?></th>
<p><?php _e( 'This will remove the header image. You will not be able to restore any customizations.' ); ?></p>
<?php submit_button( __( 'Remove Header Image' ), '', 'removeheader', false ); ?>
$default_image = sprintf(
get_theme_support( 'custom-header', 'default-image' ),
get_template_directory_uri(),
get_stylesheet_directory_uri()
if ( $default_image && get_header_image() !== $default_image ) :
<th scope="row"><?php _e( 'Reset Image' ); ?></th>
<p><?php _e( 'This will restore the original header image. You will not be able to restore any customizations.' ); ?></p>
<?php submit_button( __( 'Restore Original Header Image' ), '', 'resetheader', false ); ?>
<?php if ( current_theme_supports( 'custom-header', 'header-text' ) ) : ?>
<h2><?php _e( 'Header Text' ); ?></h2>
<table class="form-table" role="presentation">
<th scope="row"><?php _e( 'Header Text' ); ?></th>
<label><input type="checkbox" name="display-header-text" id="display-header-text"<?php checked( display_header_text() ); ?> /> <?php _e( 'Show header text with your image.' ); ?></label>
<tr class="displaying-header-text">
<th scope="row"><?php _e( 'Text Color' ); ?></th>
if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) {
$default_color = get_theme_support( 'custom-header', 'default-text-color' );
if ( $default_color && ! str_contains( $default_color, '#' ) ) {
$default_color = '#' . $default_color;
$default_color_attr = $default_color ? ' data-default-color="' . esc_attr( $default_color ) . '"' : '';
$header_textcolor = display_header_text() ? get_header_textcolor() : get_theme_support( 'custom-header', 'default-text-color' );
if ( $header_textcolor && ! str_contains( $header_textcolor, '#' ) ) {
$header_textcolor = '#' . $header_textcolor;
echo '<input type="text" name="text-color" id="text-color" value="' . esc_attr( $header_textcolor ) . '"' . $default_color_attr . ' />';
/* translators: %s: Default text color. */
echo ' <span class="description hide-if-js">' . sprintf( _x( 'Default: %s', 'color' ), esc_html( $default_color ) ) . '</span>';
* Fires just before the submit button in the custom header options form.
do_action( 'custom_header_options' );
wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' );
<?php submit_button( null, 'primary', 'save-header-options' ); ?>
* Displays second step of custom header image page.
public function step_2() {
check_admin_referer( 'custom-header-upload', '_wpnonce-custom-header-upload' );
if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) {
'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
'<p>' . __( 'The active theme does not support uploading a custom header image.' ) . '</p>',
if ( empty( $_POST ) && isset( $_GET['file'] ) ) {
$attachment_id = absint( $_GET['file'] );
$file = get_attached_file( $attachment_id, true );
$url = wp_get_attachment_image_src( $attachment_id, 'full' );
} elseif ( isset( $_POST ) ) {
$data = $this->step_2_manage_upload();
$attachment_id = $data['attachment_id'];
if ( file_exists( $file ) ) {
list( $width, $height, $type, $attr ) = wp_getimagesize( $file );
$data = wp_get_attachment_metadata( $attachment_id );
$height = isset( $data['height'] ) ? (int) $data['height'] : 0;
$width = isset( $data['width'] ) ? (int) $data['width'] : 0;
// For flex, limit size of image displayed to 1500px unless theme says otherwise.
if ( current_theme_supports( 'custom-header', 'flex-width' ) ) {
if ( current_theme_supports( 'custom-header', 'max-width' ) ) {
$max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) );
$max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) );
// If flexible height isn't supported and the image is the exact right size.
if ( ! current_theme_supports( 'custom-header', 'flex-height' )
&& ! current_theme_supports( 'custom-header', 'flex-width' )
&& (int) get_theme_support( 'custom-header', 'width' ) === $width
&& (int) get_theme_support( 'custom-header', 'height' ) === $height
if ( file_exists( $file ) ) {
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
$this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
* Filters the attachment file path after the custom header or background image is set.
* Used for file replication.
* @param string $file Path to the file.
* @param int $attachment_id Attachment ID.
$file = apply_filters( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication.
return $this->finished();
} elseif ( $width > $max_width ) {
$oitar = $width / $max_width;
str_replace( wp_basename( $file ), 'midsize-' . wp_basename( $file ), $file )
if ( ! $image || is_wp_error( $image ) ) {
wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
$image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication.
$url = str_replace( wp_basename( $url ), wp_basename( $image ), $url );
$width = $width / $oitar;
$height = $height / $oitar;
<h1><?php _e( 'Crop Header Image' ); ?></h1>
<form method="post" action="<?php echo esc_url( add_query_arg( 'step', 3 ) ); ?>">
<p class="hide-if-no-js"><?php _e( 'Choose the part of the image you want to use as your header.' ); ?></p>
<p class="hide-if-js"><strong><?php _e( 'You need JavaScript to choose a part of the image.' ); ?></strong></p>
<div id="crop_image" style="position: relative">
<img src="<?php echo esc_url( $url ); ?>" id="upload" width="<?php echo esc_attr( $width ); ?>" height="<?php echo esc_attr( $height ); ?>" alt="" />
<input type="hidden" name="x1" id="x1" value="0" />
<input type="hidden" name="y1" id="y1" value="0" />
<input type="hidden" name="width" id="width" value="<?php echo esc_attr( $width ); ?>" />
<input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>" />
<input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $attachment_id ); ?>" />
<input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" />
<?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?>
<input type="hidden" name="create-new-attachment" value="true" />
<?php wp_nonce_field( 'custom-header-crop-image' ); ?>
<?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?>
if ( isset( $oitar ) && 1 === $oitar
&& ( current_theme_supports( 'custom-header', 'flex-height' )
|| current_theme_supports( 'custom-header', 'flex-width' ) )
submit_button( __( 'Skip Cropping, Publish Image as Is' ), '', 'skip-cropping', false );
* Uploads the file to be cropped in the second step.
public function step_2_manage_upload() {
$overrides = array( 'test_form' => false );
$uploaded_file = $_FILES['import'];
$wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] );
if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
$file = wp_handle_upload( $uploaded_file, $overrides );
if ( isset( $file['error'] ) ) {
wp_die( $file['error'], __( 'Image Upload Error' ) );
$filename = wp_basename( $file );
// Construct the attachment array.
'post_title' => $filename,
'post_mime_type' => $type,
'context' => 'custom-header',