Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 22, 2025

The mattwright/urlresolver library is abandoned and throws PHP deprecation notices. Replace with a lightweight implementation using WordPress's native HTTP API.

Changes

  • New Libraries/PF_URL_Resolver.php: Implements resolveURL()->getURL() interface using wp_remote_head() to manually follow redirects (301, 302, 303, 307, 308)

  • Core/Providers/LibrariesProvider.php: Instantiate PF_URL_Resolver instead of URLResolver

  • Controllers/HTTPTools.php: Update type hints and remove curl extension check (WordPress HTTP API supports multiple transports)

  • Core/API/MetaCheckEndpoint.php: Remove unused $url_resolver dependency

  • composer.json: Remove mattwright/urlresolver dependency

Implementation

The new resolver manually tracks the final URL by following redirects rather than relying on WordPress's auto-redirect:

protected function resolve( $url ) {
    $max_redirects = 10;
    $current_url   = $url;
    
    for ( $i = 0; $i < $max_redirects; $i++ ) {
        $response = wp_remote_head( $current_url, array( 'redirection' => 0 ) );
        
        if ( is_wp_error( $response ) ) {
            return $current_url;
        }
        
        $response_code = wp_remote_retrieve_response_code( $response );
        
        if ( in_array( $response_code, array( 301, 302, 303, 307, 308 ), true ) ) {
            $location = wp_remote_retrieve_header( $response, 'location' );
            // Handle relative URLs and continue
            $current_url = $location;
        } else {
            return $current_url; // Final destination
        }
    }
    
    return $current_url;
}

Maintains full backward compatibility with the existing resolveURL($url)->getURL() interface used in HTTPTools::resolve_a_url().

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/DaveChild/Text-Statistics/zipball/e83d5f82726db80e662ae305fce3b3c41299b4f5
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Fe7ga7 /usr/bin/composer install --no-interaction cal/bin/grep (http block)
  • https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/2d1b63db139c3c6ea0c927698e5160f8b3b8d630
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Fe7ga7 /usr/bin/composer install --no-interaction cal/bin/grep (http block)
  • https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Fe7ga7 /usr/bin/composer install --no-interaction cal/bin/grep (http block)
  • https://api.github.com/repos/firebase/php-jwt/zipball/8f718f4dfc9c5d5f0c994cdfd103921b43592712
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Fe7ga7 /usr/bin/composer install --no-interaction cal/bin/grep (http block)
  • https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Fe7ga7 /usr/bin/composer install --no-interaction cal/bin/grep (http block)
  • https://api.github.com/repos/phpstan/phpstan/zipball/29201e7a743a6ab36f91394eab51889a82631428
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Fe7ga7 /usr/bin/composer install --no-interaction cal/bin/grep (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Replace URLResolver.php</issue_title>
<issue_description>We use the library https://github.com/mattwright/URLResolver.php to follow URL redirects to their final point. But the library is abandoned, and in recent PHP it's started throwing lots of deprecation notices.

It's not clear to me that we really need a full-fledged library for this purpose. Something as simple as the following will probably do about the same thing:

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_NOBODY, true);         // No body, just headers (HEAD request)
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return response as string
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10);        // Stop after 10 redirects
    curl_exec($ch);
    
    $finalUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    curl_close($ch);
    
    return $finalUrl;

Perhaps better yet, this could be written in a way that's not specific to cURL, using wp_remote_head().

URLResolver objects are scattered throughout the system, for example as a param to Controllers/HTTPTools. The intent was likely to do some sort of DI architecture, but if we're going to have a very simple replacement, this seems way overkill. So we would also need to make some modifications to the consuming classes to make this work. We could mimic the URLResolver interface (such as it is) so that we could still call the resolveURL() method, but this would still require changes to function signatures. Or we could continue to include the library, but not actually use it anywhere - this way signatures would be unchanged.</issue_description>

<agent_instructions>I've made a few suggestions for how this might work, but I'd like you to use your best judgment about the approach that will (a) be the most maintainable going forward, and (b) do the least potential damage with respect to backward compatibility (the latter concern is pretty theoretical - it's likely that no one is actually using DI to replace any of the consuming classes)</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits December 22, 2025 20:27
- Created new PressForward\Libraries\PF_URL_Resolver class using wp_remote_head()
- Updated LibrariesProvider to use new resolver
- Removed mattwright/urlresolver dependency from composer.json
- Updated HTTPTools to use new PF_URL_Resolver class
- Updated MetaCheckEndpoint to remove unused url_resolver parameter

Co-authored-by: boonebgorges <246627+boonebgorges@users.noreply.github.com>
Updated the resolve() method to manually follow redirects instead of
relying on WordPress auto-redirect, which allows us to properly track
the final URL destination.

Co-authored-by: boonebgorges <246627+boonebgorges@users.noreply.github.com>
Replaced isset() ternary with ?? operator for cleaner code.

Co-authored-by: boonebgorges <246627+boonebgorges@users.noreply.github.com>
Since we're now using WordPress's HTTP API (wp_remote_head) instead of
raw cURL, the curl extension check is no longer necessary. WordPress's
HTTP API can use multiple transports (curl, streams, fsockopen).

Co-authored-by: boonebgorges <246627+boonebgorges@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove abandoned URLResolver.php library Replace abandoned URLResolver library with WordPress HTTP API implementation Dec 22, 2025
Copilot AI requested a review from boonebgorges December 22, 2025 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace URLResolver.php

2 participants