Opened 7 years ago
Closed 7 years ago
#40931 closed defect (bug) (fixed)
Warning: Division by zero in wp-includes/theme-compat/embed-content.php on line 33
Reported by: | aegis123 | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 4.7.5 |
Component: | Embeds | Keywords: | good-first-bug has-patch |
Focuses: | Cc: |
Description
When embedding a post in another post I get the warning Warning: Division by zero in wp-includes/theme-compat/embed-content.php on line 33. It does show a embedded preview image of the post image.
if ( $data['width'] / $data['height'] > $aspect_ratio )
When change this to also check if width and height are larger than 0 the warnings go away.
if ( ($data['width'] > 0 && $data['height'] > 0) && $data['width'] / $data['height'] > $aspect_ratio ) {
Attachments (1)
Change History (9)
#2
@
7 years ago
- Keywords needs-patch good-first-bug added
- Milestone changed from Awaiting Review to 4.9
#3
@
7 years ago
I am also seeing this problem (I am the person who reported in the post linked by @tobifjellner).
It is happening with GET calls to page and post URL's ending with /embed/, on some but not all pages on a few of my sites - most don't have the problem. All sites have different themes. The error persists when disabling various plugins and also persisted when I switched one site to TwentyFifteen for testing. So no obvious conflict that I can find as the cause.
It does happen consistently on GET requests to specific pages-- that is, once I can isolate a page where it is occuring, I can trigger the error simply by browsing to (example): https:// mysite.tld/permalink/embed/ and the error will recur each time I reload the page.
I can also confirm that the code fix that @aegis123 provided above does work to resolve the problem.
#5
@
7 years ago
The warning is displayed when the post has a featured image with corrupted metadata: the image has a particular size, but its height
attribute is empty.
I have no objections to checking the value to avoid the warning, but it would be nice to find out what causes the metadata to become corrupted like that, as it could cause other issues elsewhere.
@aegis123, @Abigailm: Were you able to identify any pattern in the affected posts? What kind of a featured image (format, size) they have?
This ticket was mentioned in Slack in #core by sergey. View the logs.
7 years ago
#7
@
7 years ago
I saw no pattern and have seen this error on multiple sites. It seems to be something that is triggered by bots that are spidering sites -- that is, when I have been able to trace the error in site logs, it often is triggered by a bot such as baidu. It does seem to help to add this line to the robots.txt for the site:
User-agent: *
Disallow: */embed/
Though that is simply taking a step to discourage the triggering event, rather than actually addressing the underlying problem.
And the reason that I am only seeing this with bots may simply reflect that my site content is not commonly embedded elsewhere, so real human users wouldn't ordinarily be viewing the embeds.
Another report about same issue (at least it looks like that to me):
https://wordpress.org/support/topic/division-by-zero-error-with-oembed-get-requests/