WordPress.org

Make WordPress Core

Ticket #41933: 0001-41933-Handle-get_the_content-with-no-pages.patch

File 0001-41933-Handle-get_the_content-with-no-pages.patch, 1.4 KB (added by ComputerGuru, 3 years ago)

Proper patch for root issue

  • wp-includes/post-template.php

    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 ) { 
    289289                return get_the_password_form( $post );
    290290        }
    291291
     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        }
    292297        if ( $page > count( $pages ) ) { // if the requested page doesn't exist
    293298                $page = count( $pages ); // give them the highest numbered page that DOES exist
    294299        }