WordPress / WordPress/Requests

final attribute on the CURL class breaks caching plugin functionality.

Open
#802 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Transports Status: awaiting feedback Status: triage
Dominant language
PHP
Stars
3.6k
Forks
500
Avg merge
2d 21h
Merged PRs (30d)
5

Description

As a hosting provider that provides tailored WordPress hosting for numerous clients we are often tasked with working around poorly written plugins and/or code that does not cache fetched results from external sources. As such we have developed a plugin that extends the Curl transport with a caching mechanism based on a whitelist of URLs.

As of the update to the 2.0.0 requests library, it is now impossible to do this anymore due to the use of the final keyword on the Curl class.

Here is how we were doing this:

  // register our transport wrapper
  Requests::add_transport('\HF\Cache\cURL');

  // force our transport to load first
  Requests::$transport[serialize(['ssl' => true ])] = '\HF\Cache\cURL';
  Requests::$transport[serialize(['ssl' => false])] = '\HF\Cache\cURL';
  Requests::$transport[serialize([]              )] = '\HF\Cache\cURL';

Our class would then override the request method and either inherit the default functionality or respond with a cached value:

class cURL extends \Requests_Transport_cURL
{
  public function request($url, $headers = array(), $data = array(), $options = array())
  {
    // custom caching logic here
    
    // inherit default logic
    return parent::request($url, $headers, $data, $options);
  }
}

Instead we now get the fatal error:

Class HF\Cache\cURL may not inherit from final class (WpOrg\Requests\Transport\Curl)

Please remove the final attribute from the Curl class.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The affected entry point is WpOrg\Requests\Transport\Curl, where the final class prevents the shown cURL subclass from loading. Start by reviewing that transport and its request method; done means the custom subclass can extend it and delegate to parent::request without the fatal inheritance error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.