undefined index warnings due to Jetpack_Media_Summary::get()
-
This bug affects the Jetpack 3.9.1 modules
* Twitter Cards (open graph)
* Publicize (open graph)
* Related Posts (maybe)Symptom you may see:
Notice: Undefined offset: -1 in ***/wp-includes/post-template.php on line 268
(In error_log, on screen with WP_DEBUG true, or not at all depending on server config and other plugins.)
Jetpack_Media_Summary is used by the modules to create “og:” open graph meta tags for Facebook, and for whatever Related Posts does.
It tries to get a post/page excerpt and fails. It would be easy to fix this bug, because the data it tries to get is never used.
The problem is that
get_excerpt()
on line 261 ofclass.media-summary.php
does this:$post_excerpt = apply_filters( ‘get_the_excerpt’, $post_excerpt );
which in turn calls
get_the_content()
, an extremely touchy Worpdress core function. Then get_the_content() fails depending on the state of the loop, queries done by other plugins, etc., because it relies on the practically insane globals$page
and$pages
. The behavior of the code that emits the warning above in wp-includes/post-template.php is actually worse than just that warning. For example, $page=0 and count($pages)=1 will create the warning at the line:$content = $pages[$page – 1]
I de-activated another plugin and the warning stopped, but only because then count($pages) was 0. PHP did not complain about an invalid index in an empty array! So the code is really a massive failure in both cases.
Once your theme is in its loop and displaying the post/page, everything is fine. Typically $page=1 and count($pages)=1. But the modules do their work before that loop, in order to generate meta tags.
I admit I have not tried our site with only Jetpack enabled, but even if it were just a plugin conflict, and the code is completely unnecessary, why keep it? By inspection, I don’t see $excerpt[‘extract’] is ever used. It’s just overhead in the data structure. So the fix is easy.
(Debugging detail: $page was set to zero in register_globals(). Using wp_reset_query() does not help.)
- The topic ‘undefined index warnings due to Jetpack_Media_Summary::get()’ is closed to new replies.