Make WordPress Core

Ticket #41933: 0001-Fix-undefined-offset-1-notice-in-pages-array-in-post.patch

File 0001-Fix-undefined-offset-1-notice-in-pages-array-in-post.patch, 1.1 KB (added by ComputerGuru, 7 years ago)

patch

  • wp-includes/post-template.php

    From 0d7e33a0895b33b23ab3532662e97e6f954b35b7 Mon Sep 17 00:00:00 2001
    From: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
    Date: Wed, 20 Sep 2017 12:06:36 -0500
    Subject: [PATCH] Fix undefined offset -1 notice in $pages array in
     post-template.php
    
    If no pages are defined, WordPress attempts to access $pages[$page - 1]
    which evaluates to $pages[-1], causing a notice to be shown.
    ---
     wp-includes/post-template.php | 4 ++++
     1 file changed, 4 insertions(+)
    
    diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php
    index 3734373..1328bc4 100644
    a b function get_the_content( $more_link_text = null, $strip_teaser = false ) { 
    284284        if ( $page > count( $pages ) ) // if the requested page doesn't exist
    285285                $page = count( $pages ); // give them the highest numbered page that DOES exist
    286286
     287        if ( $page == 0 ) { // if there aren't multiple pages
     288                $page = 1; // show the only page
     289        }
     290
    287291        $content = $pages[$page - 1];
    288292        if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
    289293                $content = explode( $matches[0], $content, 2 );