Make WordPress Core

Ticket #65448: 65448.diff

File 65448.diff, 1.4 KB (added by zodiac1978, 2 months ago)

First try adding the new method if available

  • src/wp-includes/http.php

     
    750750                $url        = 'placeholder://placeholder' . $url;
    751751        }
    752752
    753         $parts = parse_url( $url );
     753        /*
     754         * PHP 8.5+: Prefer the WHATWG URL parser.
     755         */
     756        if ( class_exists( 'Uri\\WhatWg\\Url' ) ) {
     757                try {
     758                        $parsed = \Uri\WhatWg\Url::parse( $url );
    754759
    755         if ( false === $parts ) {
    756                 // Parsing failure.
    757                 return $parts;
     760                        $parts = array();
     761
     762                        if ( '' !== $parsed->scheme ) {
     763                                $parts['scheme'] = $parsed->scheme;
     764                        }
     765
     766                        if ( '' !== $parsed->host ) {
     767                                $parts['host'] = $parsed->host;
     768                        }
     769
     770                        if ( null !== $parsed->port ) {
     771                                $parts['port'] = $parsed->port;
     772                        }
     773
     774                        if ( '' !== $parsed->username ) {
     775                                $parts['user'] = $parsed->username;
     776                        }
     777
     778                        if ( '' !== $parsed->password ) {
     779                                $parts['pass'] = $parsed->password;
     780                        }
     781
     782                        if ( '' !== $parsed->path ) {
     783                                $parts['path'] = $parsed->path;
     784                        }
     785
     786                        if ( '' !== $parsed->query ) {
     787                                $parts['query'] = $parsed->query;
     788                        }
     789
     790                        if ( '' !== $parsed->fragment ) {
     791                                $parts['fragment'] = $parsed->fragment;
     792                        }
     793                } catch ( \Throwable $e ) {
     794                        return false;
     795                }
     796        } else {
     797                $parts = parse_url( $url );
     798
     799                if ( false === $parts ) {
     800                        // Parsing failure.
     801                        return false;
     802                }
    758803        }
    759804
    760805        // Remove the placeholder values.