Title: PHP Warning: Undefined array key &#8220;height&#8221; / &#8220;width&#8221; caused in file media.php
Last modified: May 26, 2026

---

# PHP Warning: Undefined array key “height” / “width” caused in file media.php

 *  Resolved [Gevorg](https://wordpress.org/support/users/gev0rg/)
 * (@gev0rg)
 * [2 weeks, 2 days ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-height-width-caused-in-file-media-php/)
 * Hello WordPress developers.
 * I would like to bring to your attention **PHP warnings** that are continually
   being triggered and logged in the **php_errorlog** file on the WordPress/WooCommerce
   installation I work.
 * Here are the PHP warnings:
   `[22-May-2026 18:16:17 UTC] PHP Warning: Undefined
   array key "file" in /home/customer/www/.../public_html/wp-includes/media.php 
   on line **1469**`
 * …and…
 * `[22-May-2026 18:16:17 UTC] PHP Warning: Undefined array key "width" in /home/
   customer/www/.../public_html/wp-includes/media.php on line **1483**`
 * …and…
 * `[22-May-2026 18:16:17 UTC] PHP Warning: Undefined array key "height" in /home/
   customer/www/.../public_html/wp-includes/media.php on line **1488**`
 * This is a **PHP 8+** issue, PHP is complaining that these **array keys** are 
   not set in certain circumstances.
 * Here are the affected code segments:
 * `// If the file name is part of the src, we've confirmed a match.
   if ( ! $src_matched&&
   str_contains( $image_src, $dirname . **$image['file']** ) ) { $src_matched = 
   true; $is_src = true;}
 * …and…
 * `// If the image dimensions are within 1px of the expected size, use it.
   if (
   wp_image_matches_ratio( $image_width, $image_height, **$image['width']**, **$
   image['height']** ) ) { // Add the URL, descriptor, and value to the sources 
   array to be returned. $source = array( 'url' => $image_baseurl . $image['file'],'
   descriptor' => 'w', 'value' => **$image['width']**, ); if ( $is_src ) { $sources
   = array( $image['width'] => $source ) + $sources; } else { $sources[ **$image['
   width']** ] = $source; }}
 * The triggering of these **PHP warnings** may or may not be related to some plugin(
   s) installed on the system. But if you could add some check to your code, something
   like…
 * `if ( isset(**$image['file']**) ) { /* then do something */ }`
 * …then you could satisfy the requirements of PHP 8+, and such scenarios could 
   be avoided, regardless of which plugins-configuration a WordPress installation
   may have.
 * I send this for your information, I hope it helps to improve the code of **WordPress**.
 * Sincerely,
   Gevorg
    -  This topic was modified 2 weeks, 2 days ago by [Gevorg](https://wordpress.org/support/users/gev0rg/).

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [2 weeks, 2 days ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-height-width-caused-in-file-media-php/#post-18917275)
 * This is usually a secondary error caused by a plugin you’re using incorrectly
   calling WordPress core functions. To rule this out as the cause, try deactivating
   all plugins. If the error message no longer appears, reactivate the plugins one
   by one until you find the one causing the problem.
 *  Thread Starter [Gevorg](https://wordpress.org/support/users/gev0rg/)
 * (@gev0rg)
 * [2 weeks, 2 days ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-height-width-caused-in-file-media-php/#post-18917353)
 * Thank you for your **reply** moderator, but it’s **not really helpful**; let 
   me explain…
 * The **default WordPress mantra** of _“deactivating all plugins”_, and then _“
   reactivate the plugins one by one until you find the one causing the problem”_
   is **not helpful** in this case; in this case it’s a **PHP 8+ compatibility issue**.
 * There are so many, so **very many** plugins for WordPress from all sorts of people
   around the world. Not all plugin developers have the necessary experience to 
   develop their plugin for to operate correctly within a WordPress installation.
   And neither is it easy for plugin developers, because such software like **WordPress**
   or **WooCommerce** is being **updated on a continual basis**, and changes are
   applied to it.
 * People who run **WordPress installations** just can not spend so much time with**
   error-catching** of other people’s plugins. They may find themselves in a situation
   where such **PHP warnings** are logged in WordPress’ **php_errorlog file**, which
   then as a consequence is **bloated in size** in the course of time to who knows**
   how many Megabytes**, which then has a **detrimental effect** on the **performance**
   of a WordPress installation. Many such people will not know that the **php_errorlog
   file** is being loaded **with every page-load** –be it for them as administrator,
   or for their visitors– and they may find themselves in a situation where they
   are contacted by their **hosting-provider** about using up too much of **server
   resources** on the **shared hosting-plan** which they have. In such a situation
   they may not even be able to **deactivate** the php_errorlog file logging of 
   WordPress, or **change** the PHP E_WARNING-level set up for the logging.
 * For **inexperienced people** it’s just such a **difficult task** to find out 
   about the real cause of such a problem.
 * Now on the other hand –if you agree with my point– adding **a little bit of PHP
   code** from your side –for **PHP 8+ compatibility** sake– to check whether these**
   array-keys** have any **value** set before trying to access it, you could **circumvent**
   the deficiency of an unknown number of plugins worldwide which do not operate
   correctly within the WordPress instillation, and, as a **secondary effect**, 
   benefit so many people around the world by **avoiding** these **minor PHP issues**
   being recorded as _warnings_ or _errors_.
 * It’s so much **less effort** if you agreed to fix this in your code, than to 
   expect that an unknown number of people worldwide –**possibly many thousands**–
   who are affected by this, spend their time and effort to find the cause for this**
   unknown** and **indirect** –you call it _“**secondary**“_– **problem**.
 * I reported this here on your forum, because, given the circumstances, it’s a **
   common-sense approach** if you fixed this in your code, and thereby helped so
   many other people who may also be affected by this.
 * This is a **PHP 8+ compatibility issue**, as you know. Such warnings were just
   not recorded by PHP in previous time, but now they are being recorded, and there
   can be **many such warnings** on a WordPress installation; **these being triggered
   with every page-load** !
 * I mention this for your **consideration**.
 * You can **close this topic** if you have nothing new to add to your initial reply.
 * Sincerely,
   Gevorg
    -  This reply was modified 2 weeks, 2 days ago by [Gevorg](https://wordpress.org/support/users/gev0rg/).
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [2 weeks, 2 days ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-height-width-caused-in-file-media-php/#post-18917360)
 * If you view your observation as a recommendation for optimizing the WordPress
   Core, I would suggest opening a ticket for it in Core Trac.
 * However, I took a look at the specific lines you mentioned and noticed that you
   do not appear to be running the latest version of WordPress. For instance, in
   the current version, line 1469 of `wp-includes/media.php` contains no PHP code
   that would trigger the warning message you described: [https://github.com/WordPress/WordPress/blob/master/wp-includes/media.php#L1469](https://github.com/WordPress/WordPress/blob/master/wp-includes/media.php#L1469)
 * It is possible that this specific issue was resolved in WordPress 7.0 thanks 
   to a ticket in Core Trac; see: [https://core.trac.wordpress.org/ticket/60480](https://core.trac.wordpress.org/ticket/60480)
 * Consequently, the other error messages you encountered may also be obsolete. 
   However, there is currently an open bug ticket regarding this issue for height
   and width specifically in relation to SVG graphics: [https://core.trac.wordpress.org/ticket/57239](https://core.trac.wordpress.org/ticket/57239)
 * My recommendation, therefore, is as follows:
    - Update your WordPress installation to version 7.0 and check whether the warning
      messages persist.
    - If they do, deactivate all plugins to rule them out as the cause. You should
      also switch to a default theme, such as Twenty Twenty-Five. Users are strongly
      advised to take this step to ensure that the problem is not caused by a plugin.
    - If the issue continues to occur – even with no plugins active, using a default
      theme, and running the latest WordPress 7.0 – please feel free to open a ticket
      in the WordPress Core Trac. When doing so, please describe the exact steps
      required to reproduce the error (including, if possible, the specific image
      file that triggered the issue for you): [https://core.trac.wordpress.org/newticket](https://core.trac.wordpress.org/newticket)–
      only under these conditions will developers have the opportunity to identify
      and implement potential improvements to the Core.
 *  Thread Starter [Gevorg](https://wordpress.org/support/users/gev0rg/)
 * (@gev0rg)
 * [2 weeks, 2 days ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-height-width-caused-in-file-media-php/#post-18917406)
 * The **WordPress installation** where this (**still**) occurs has already been
   updated to **WordPress 7.0**. The code-sections I posted here in this topic are
   from WordPress version 7.0.
 * Due to other tasks I may not have the time to test this thoroughly by deactivating
   all, and then re-activating the plugins one after the other in order to see which
   one is causing this.
 * But to give your **developers** useful hints –if you choose to forward this to
   them– here is a list of **active plugins** on this particular WordPress installation,
   which are involved in **manipulating** or **managing image files**:
 * **_Enable Media Replace_** – version **4.1.9**
   [https://en-au.wordpress.org/plugins/enable-media-replace/](https://en-au.wordpress.org/plugins/enable-media-replace/)
 * **_Media File Renamer: Rename for better SEO (AI-Powered) (Pro)_** – version **
   6.2.5**
   [https://meowapps.com/](https://meowapps.com/)
 * **_ShortPixel Image Optimizer – Optimize Images, Convert WebP & AVIF_** – version**
   2.4.9**
   [https://en-au.wordpress.org/plugins/shortpixel-image-optimiser/](https://en-au.wordpress.org/plugins/shortpixel-image-optimiser/)
 * **_WP Media folder_** – version **6.2.3**
   [https://www.joomunited.com/wordpress-products/wp-media-folder](https://www.joomunited.com/wordpress-products/wp-media-folder)
 * —
 * It’s not about **what** those **code-sections** cited here **contain** that would
   cause these warnings to be triggered –as you write– **it’s about what they do
   not contain **!
 * For example, if this:
   `if ( ! $src_matched && str_contains( $image_src, $dirname.
   $image['file'] ) ) { $src_matched = true; $is_src = true;}
 * …would look like this:
   `if ( **isset($image['file'])** && ( ! $src_matched &&
   str_contains( $image_src, $dirname . $image['file'] ) ) ) { $src_matched = true;
   $is_src = true;}
 * …then such **troublesome plugins** would be **deprived** of their **opportunity**
   to trigger such **PHP warnings**. If you could implement such fixes in your own
   code, then you would **preemptively** solve **very many** such **minor PHP issues**
   in one strike.
 * You are welcome to forward this **recommendation** to your developers, or add
   it to already existing and active tickets.
 * Sincerely,
   Gevorg
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [2 weeks, 1 day ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-height-width-caused-in-file-media-php/#post-18917605)
 * This forum is designed to help users like you and me support one another. See
   also: [https://wordpress.org/support/guidelines/](https://wordpress.org/support/guidelines/)
 * No one here is “my” developer. WordPress is developed by the community, including
   through feedback like yours, which should, however, be as well-founded and clear
   as possible. Based on the list of plugins you mentioned and the continued lack
   of feedback regarding a sample image, I suspect that your problem is caused by
   one of these plugins and not by the WordPress core itself. As described above,
   there are already two tickets with the WordPress community developers addressing
   the recommendations you raised. You’re welcome to participate in this community
   process in this tickets to help find a solution or wait until someone resolves
   the recommendations you’ve raised.
 *  Thread Starter [Gevorg](https://wordpress.org/support/users/gev0rg/)
 * (@gev0rg)
 * [2 weeks ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-height-width-caused-in-file-media-php/#post-18919402)
 * The title of this forum is called **_Fixing WordPress_**, and therefore I opened
   the topic concerning this issue; it is according to the **purpose** of this forum.
 * My remark _“**your developers**“_ is related to **WordPress**, not you moderator.
   But **self-centered people** just pick the wrong interpretation of the meaning.
 * Although this has already occupied quite some time to explain it here, I will
   try **another attempt** to clarify the matter for you: it is a **logical problem**,
   not a syntax problem.
 * **WordPress** is a **good software**, and it has gained **much popularity** because
   of how it has been developed. For simplicity sake, there are **two different 
   types of software** that can be developed:
 * (**1**) One is software which **is and remains under the control** of the developer(
   s).
 * (**2**) The other is software which **allows unknown third-parties to add extensions**(
   plugins) to it, which consequently **change** how the software operates, and 
   such software is no longer under control of its original developer(s).
 * **WordPress is software from category (2).**
 * Your developers (not you personally moderator) are experienced and talented programmers.
   And they have aimed at developing WordPress in an efficient way, according to
   the latest standards of **PHP**; and this is what all developers should aim to
   do.
 * However, they developed WordPress as if it is a **category (1)** software, they
   did not take into consideration that WordPress is a **category (2)** software.
 * It is impossible to know or preempt how these **innumerable plugins** worldwide
   may change the functioning of WordPress. And neither is it meaningful to expect
   that the **manifold plugin developers** worldwide are at the same level, or have
   the same insights as the WordPress developers.
 * Therefore it would be **prudent** if the WordPress developers realized and treated
   WordPress as a **category (2) software**, and as a consequence would implement**
   precautionary measures** –like the example I mentioned here in this topic– to**
   mitigate** potential inefficiencies of other people’s plugins.
 * You can neither correct other people’s plugin code, nor foresee what other blunders
   they may introduce in the future. But what you could do is to make your **category(
   2)** software **compatible with PHP 8+ requirements**.
 * If **WordPress** was a **category (1) software**, and there would be an instance
   where an **array-key** is being addressed which has no value set, then the developers
   can examine the code and simply **prevent the addressing** of that array-key 
   when it has no value. And they can do this because as a category (1) software
   the entire functioning of the software is under their own control. And therefore
   they can **streamline** the programming, avoid **unnecessary extras**, and produce
   an **efficient PHP code**.
 * But with a **category (2) software** it does not work this way. So with **WordPress**–
   which is category (2)– you have a situation where innumerable outside developers
   have the opportunity to modify the functioning of this software, and not all 
   are capable to integrate their plugin and its functioning correctly into WordPress.
   As a consequence modern **PHP** versions are triggered for **error handling**,
   and in the course of time this can have a **detrimental effect** on the **performance**
   of a WordPress installation.
 * The **concept** I am trying to describe here would **improve WordPress’ performance**
   by **preemptively preventing** such **minor PHP issues**, like **warnings about
   array-keys without value**, from occurring. And as a consequence this would positively
   affect many thousands –maybe millions– of WordPress installations worldwide.
 * This is what I am trying to explain here, and I think I have explained it clearly.
 * I will most likely not open a new ticket for this on _WordPress Trac_, neither
   participate in existing discussions. I will be satisfied if you (moderator) could
   draw the attention of relevant people, who are involved in developing WordPress,
   to take a look at this topic, and make their own considerations. It is about 
   the **concept** of how they develop WordPress, it surely is not about a lack 
   of programming skills. It’s about **foreseeing** and **preemptively mitigating
   problems** which other developers –who integrate their plugins into this **category(
   2) software** called WordPress– might cause. It’s not about how good WordPress
   on its own functions.
 * As I wrote before, I hope this can help to **improve** WordPress, on this forum
   which is called **_Fixing WordPress_**.
 * Sincerely,
   Gevorg
    -  This reply was modified 2 weeks ago by [Gevorg](https://wordpress.org/support/users/gev0rg/).
    -  This reply was modified 2 weeks ago by [Gevorg](https://wordpress.org/support/users/gev0rg/).
 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [2 weeks ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-height-width-caused-in-file-media-php/#post-18919565)
 * > You can **close this topic** if you have nothing new to add to your initial
   > reply.
 * That’s a great idea, especially as this topic has become unnecessarily contentious.
 * Gevorg, you may not be aware of this but your replies are conveying a, well, 
   unpleasant attitude and is a bit insulting.
 * It’s fine to provide feedback or seek support or even provide support. It is 
   not fine to take that tone with volunteers trying to assist you. That includes
   the forum moderation team.
 * If you wish to raise a new topic, try to keep it factual and avoid all the judgmental
   and derogatory verbiage.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘PHP Warning: Undefined array key “height” / “width” caused in file media.
php’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 2 participants
 * Last reply from: [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * Last activity: [2 weeks ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-height-width-caused-in-file-media-php/#post-18919565)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
