WordPress.org

Make WordPress Core

Ticket #47704: 47704-WP_REST_Request-get_content.patch

File 47704-WP_REST_Request-get_content.patch, 1.4 KB (added by jrf, 17 months ago)

PHP 7.4/array-access: Fix WP_REST_Request::get_content_type() - fixes 810 errors, 2 failures and 32 unnecessarily skipped tests

  • src/wp-includes/rest-api/class-wp-rest-request.php

    From b68f36f98b7a106f6ce2186f7f00473df8385321 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Sun, 14 Jul 2019 22:22:14 +0200
    Subject: [PATCH] PHP 7.4/array-access: Fix WP_REST_Request::get_content_type()
    
    ---
     src/wp-includes/rest-api/class-wp-rest-request.php | 6 ++++--
     1 file changed, 4 insertions(+), 2 deletions(-)
    
    diff --git a/src/wp-includes/rest-api/class-wp-rest-request.php b/src/wp-includes/rest-api/class-wp-rest-request.php
    index ee106b5c5a..3089547ce7 100644
    a b class WP_REST_Request implements ArrayAccess { 
    294294         *
    295295         * @since 4.4.0
    296296         *
    297          * @return array Map containing 'value' and 'parameters' keys.
     297         * @return array|null Map containing 'value' and 'parameters' keys
     298         *                    or null when no valid content-type header was
     299         *                    available.
    298300         */
    299301        public function get_content_type() {
    300302                $value = $this->get_header( 'content-type' );
    class WP_REST_Request implements ArrayAccess { 
    334336                $order = array();
    335337
    336338                $content_type = $this->get_content_type();
    337                 if ( $content_type['value'] === 'application/json' ) {
     339                if ( isset( $content_type['value'] ) && 'application/json' === $content_type['value'] ) {
    338340                        $order[] = 'JSON';
    339341                }
    340342