: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
public function maybe_exif_rotate() {
if ( is_callable( 'exif_read_data' ) && 'image/jpeg' === $this->mime_type ) {
$exif_data = @exif_read_data( $this->file );
if ( ! empty( $exif_data['Orientation'] ) ) {
$orientation = (int) $exif_data['Orientation'];
* Filters the `$orientation` value to correct it before rotating or to prevent rotating the image.
* @param int $orientation EXIF Orientation value as retrieved from the image file.
* @param string $file Path to the image file.
$orientation = apply_filters( 'wp_image_maybe_exif_rotate', $orientation, $this->file );
if ( ! $orientation || 1 === $orientation ) {
switch ( $orientation ) {
$result = $this->flip( false, true );
* Rotate 180 degrees or flip horizontally and vertically.
* Flipping seems faster and uses less resources.
$result = $this->flip( true, true );
$result = $this->flip( true, false );
// Rotate 90 degrees counter-clockwise and flip vertically.
$result = $this->rotate( 90 );
if ( ! is_wp_error( $result ) ) {
$result = $this->flip( true, false );
// Rotate 90 degrees clockwise (270 counter-clockwise).
$result = $this->rotate( 270 );
// Rotate 90 degrees counter-clockwise and flip horizontally.
$result = $this->rotate( 90 );
if ( ! is_wp_error( $result ) ) {
$result = $this->flip( false, true );
// Rotate 90 degrees counter-clockwise.
$result = $this->rotate( 90 );
* Either calls editor's save function or handles file as a stream.
* @param string $filename
* @param callable $callback
* @param array $arguments
protected function make_image( $filename, $callback, $arguments ) {
$stream = wp_is_stream( $filename );
// The directory containing the original file may no longer exist when using a replication plugin.
wp_mkdir_p( dirname( $filename ) );
$result = call_user_func_array( $callback, $arguments );
if ( $result && $stream ) {
$contents = ob_get_contents();
$fp = fopen( $filename, 'w' );
fwrite( $fp, $contents );
* Returns first matched mime-type from extension,
* as mapped from wp_get_mime_types()
* @param string $extension
protected static function get_mime_type( $extension = null ) {
$mime_types = wp_get_mime_types();
$extensions = array_keys( $mime_types );
foreach ( $extensions as $_extension ) {
if ( preg_match( "/{$extension}/i", $_extension ) ) {
return $mime_types[ $_extension ];
* Returns first matched extension from Mime-type,
* as mapped from wp_get_mime_types()
* @param string $mime_type
protected static function get_extension( $mime_type = null ) {
if ( empty( $mime_type ) ) {
return wp_get_default_extension_for_mime_type( $mime_type );