From a4b1f6fd864d63937c7a1a011972624fdbfbb2f7 Mon Sep 17 00:00:00 2001
From: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date: Fri, 27 Apr 2018 19:51:21 -0500
Subject: [PATCH] [#41933] Handle `get_the_content()` with no `$pages`
In the event that `get_the_content()` is called but `$pages` is
undefined or empty, a number of PHP errors will follow as the code
attempts to dereference indices that are not present in the array
(including `$pages[-1]`, see #43463).
This patch forces `get_the_content()` to return an empty string (`""`)
if `$pages` is undefined or empty.
Certain plugins, notably JetPack, are guilty of triggering this
behavior.
Patch both addresses #41933 and obviates #43463.
---
wp-includes/post-template.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php
index 9cf6c44551..dba7a3c00d 100644
a
|
b
|
function get_the_content( $more_link_text = null, $strip_teaser = false ) { |
289 | 289 | return get_the_password_form( $post ); |
290 | 290 | } |
291 | 291 | |
| 292 | if (empty($pages)) { |
| 293 | // continuing without at least one valid page causes PHP execution errors |
| 294 | // alternative is `$pages = array( "" );` and continue execution. |
| 295 | return ""; |
| 296 | } |
292 | 297 | if ( $page > count( $pages ) ) { // if the requested page doesn't exist |
293 | 298 | $page = count( $pages ); // give them the highest numbered page that DOES exist |
294 | 299 | } |