admin管理员组文章数量:1125062
After upgrading to 6.2 via WP-CLI I get an error regarding deprecated/renamed PSR-0 classes being requested.
The source comment from WP core says:
/* * Integrators who cannot yet upgrade to the PSR-4 class names can silence deprecations * by defining a `REQUESTS_SILENCE_PSR0_DEPRECATIONS` constant and setting it to `true`. * The constant needs to be defined before the first deprecated class is requested * via this autoloader. */
.php#L161
How to upgrade to the PSR-4 class names?
Asked differently, could it be a script autoloaded before WordPress via PSR-0?
After upgrading to 6.2 via WP-CLI I get an error regarding deprecated/renamed PSR-0 classes being requested.
The source comment from WP core says:
/* * Integrators who cannot yet upgrade to the PSR-4 class names can silence deprecations * by defining a `REQUESTS_SILENCE_PSR0_DEPRECATIONS` constant and setting it to `true`. * The constant needs to be defined before the first deprecated class is requested * via this autoloader. */
https://github.com/WordPress/WordPress/blob/7714010f60a55633bd0ee5c5a0843ef7a4a7f756/wp-includes/Requests/src/Autoload.php#L161
How to upgrade to the PSR-4 class names?
Asked differently, could it be a script autoloaded before WordPress via PSR-0?
Share Improve this question edited Mar 31, 2023 at 8:46 RafaSashi asked Mar 31, 2023 at 8:40 RafaSashiRafaSashi 5071 gold badge7 silver badges17 bronze badges 01 Answer
Reset to default 2This is covered in the WP 6.2 Field guide post, and in the post about the upgrade of the requests library that you found the deprecation warning in.
If your plugin or theme uses Requests directly and supports a wider range of WordPress versions, you may need to conditionally declare the REQUESTS_SILENCE_PSR0_DEPRECATIONS constant as true to silence deprecation notices about the old PSR-0 class names. You should upgrade your code as soon as WordPress 6.2 becomes the minimum WordPress version for your plugin or theme.
If your code uses the WP_HTTP
APIs then no changes are needed, this only affects code that directly uses the raw Requests API.
For fixing it:
If your plugin or theme uses Requests directly, and only supports the latest version of WordPress, you should update your code to use the namespaced names. For example, to perform a request with a try-catch using the namespaced names:
// Old: Perform a request with a try-catch in Requests 1.x.
try {
$response = Requests::request( $url, $headers, $data, $type, $options );
} catch ( Requests_Exception $e ) {
return new WP_Error( 'http_request_failed', $e->getMessage() );
}
// New: Perform a request with a try-catch in Requests 2.x.
try {
$response = WpOrg\Requests\Requests::request( $url, $headers, $data, $type, $options );
} catch ( WpOrg\Requests\Exception $e ) {
return new WP_Error( 'http_request_failed', $e->getMessage() );
}
The most compatible way to fix this, and prevent it ever happening again, is to use the WP_HTTP
API and WP functions such as wp_remote_post
etc
本文标签: composerDebugging deprecatedrenamed PSR0 classes being requested
版权声明:本文标题:composer - Debugging deprecatedrenamed PSR-0 classes being requested 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736655344a1946239.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论