Opened 4 months ago
Closed 3 weeks ago
#64136 closed defect (bug) (fixed)
PHP Deprecated: Fetching multiple feeds with single SimplePie instance is deprecated since SimplePie 1.9.0
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.9.1 | Priority: | normal |
| Severity: | normal | Version: | 6.9 |
| Component: | Feeds | Keywords: | has-patch has-unit-tests commit fixed-major dev-reviewed |
| Focuses: | administration | Cc: |
Description
PHP version: 8.3
When using WordPress 6.9 Beta, I am getting this in my logs, error is triggered when I am on dashboard home page or Updates page on WordPress.
Change History (32)
#3
@
3 months ago
Indeed, it appears that multifeed support was deprecated in version 1.9.0. And SimplePie was updated to 1.9.0 by [60771], so this is a new issue in 6.9.
cc @swissspidy @SergeyBiryukov @TobiasBg
#5
@
3 months ago
I'm not sure how deprecation warnings from external libraries have been handled in the past, but this may be an issue that can be addressed in a point release.
- The functionality itself will continue to work as before.
- As far as I can tell, the core implementation does not emit this warning. It occurs when a theme or plugin is fetching multiple feeds using a single instance.
This ticket was mentioned in Slack in #core by akshayar. View the logs.
3 months ago
#7
@
3 months ago
In that case I would say it's a good 6.9.1 candidate. Perhaps something for the Field Guide in the meantime.
#9
@
2 months ago
I think there are two approaches to addressing this issue.
- Comment out the line that triggers an error: https://github.com/WordPress/wordpress-develop/blob/33a1a52a9109710f2e09dff9290bd8ecc545cfe7/src/wp-includes/SimplePie/src/SimplePie.php#L769
- Publish a Dev Note calling out this deprecation and providing the recommended code.
I prefer the latter approach. What do you think?
This ticket was mentioned in PR #10631 on WordPress/wordpress-develop by @peterwilsoncc.
2 months ago
#10
- Keywords has-patch has-unit-tests added; needs-patch removed
Handles passing an array to fetch_feed() by requesting each feed individually and then calling SimplePie\SimplePie::merge_items(); on the result before passing the data back in to a SimplePie object.
I don't love this so would love some suggestions of anything I am missing.
Trac ticket: https://core.trac.wordpress.org/ticket/64136
#11
@
2 months ago
I've pushed PR#10631 as a thought experiment to see how solvable this is.
It can be done but the PR is almost certainly missing something and, even if it isn't, the code is pretty ugly anyway.
I'm seeing some plugins that replace the primary and/or secondary feeds in the WP dashboard but wasn't able to see any that converted the value to an array.
@muryam Do you recall any plugins you were running when you discovered the deprecation message?
#12
@
8 weeks ago
https://wordpress.org/plugins/wp-maintenance-mode/ - This plugin is using several URLs (2) to fetch feeds.
Without the patch, we are getting the Warning, and with the patch https://github.com/WordPress/wordpress-develop/pull/10631 the widget is working as expected, and there are no deprecations. So, the code is working and can be beautified before testing if no one will come up with a more elegant approach, but because merging is recommended in the changelog: https://github.com/simplepie/simplepie/blob/master/CHANGELOG.md?plain=1#L75 it looks like the right approach.
For testers: there is the 'themeisle_sdk_feed_items' transient that this plugin sets to prevent fetching feeds each time. Other plugins should have similar behavior, so you have to disable this before testing.
@wildworks commented on PR #10631:
7 weeks ago
#13
If we simply want to handle multiple feeds, the following approach might work:
diff --git a/src/wp-includes/feed.php b/src/wp-includes/feed.php index 421bee7173..74f0ee77cd 100644 --- a/src/wp-includes/feed.php +++ b/src/wp-includes/feed.php @@ -832,7 +832,20 @@ function fetch_feed( $url ) { $feed->get_registry()->register( SimplePie\File::class, 'WP_SimplePie_File', true ); - $feed->set_feed_url( $url ); + if ( is_array( $url ) && count( $url ) > 1 ) { + $feed->multifeed_url = array(); + foreach ( $url as $value ) { + $feed->multifeed_url[] = $feed->get_registry()->call( + SimplePie\Misc::class, 'fix_protocol', + array( $value, 1 ) + ); + } + } elseif ( is_array( $url ) && count( $url ) === 1 ) { + $feed->set_feed_url( array_shift( $url ) ); + } else { + $feed->set_feed_url( $url ); + } + /** This filter is documented in wp-includes/class-wp-feed-cache-transien t.php */ $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifeti me', 12 * HOUR_IN_SECONDS, $url ) );
However, this may not be the recommended approach.
@peterwilsoncc commented on PR #10631:
5 weeks ago
#14
@t-hamano The hook will still run for each individual URL but it won't run with all of them.
IE fetch_feed( [ 'one.example.com', 'two.example.com' ] ) will fire the hook twice, once for each URL. At the moment it fires once with both URLs as the second parameter.
I'll take a look at your suggested diff. I don't know their plans but I wouldn't be surprised if $feed->multifeed_url[] is removed if/when SimplePie hard deprecate an array of URLs.
@wildworks commented on PR #10631:
5 weeks ago
#15
@swissspidy @TobiasBg This is my first time looking at SimplePie code, so I may have missed something, and I'd appreciate any feedback if there is anything.
@TobiasBg commented on PR #10631:
5 weeks ago
#16
This is my first time looking at SimplePie code
Sorry, I'm not familiar with this specific part either :-(
@swissspidy commented on PR #10631:
5 weeks ago
#17
Same here
#18
@
5 weeks ago
- Keywords needs-testing removed
Test Report
Description
This report validates whether the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/10631
Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.4
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 143.0.0.0
- OS: macOS
- Theme: Twenty Twenty-One 2.7
- MU Plugins: None activated
- Plugins:
- LightStart - Maintenance Mode, Coming Soon and Landing Page Builder 2.6.20
- Test Reports 1.2.1
Steps to Reproduce
- Install LightStart-Maintenance Mode plugin from https://wordpress.org/plugins/wp-maintenance-mode/
- Add the following code snippet to any classic theme's functions.php or using Code Snippets plugin to force timeout of "themeisle_sdk_feed_items" transient added to trigger fetching the feed each time dashboard home is loaded. Thanks to @oglekler for pointing this out.
// Force the timeout to always be in the past (already expired)
add_filter('option__transient_timeout_themeisle_sdk_feed_items', function($value) {
return time() - 1; // Set to 1 second ago
});
- Ensure WP_DEBUG and WP_DEBUG_LOG are enabled in wp-config.php
- Visit dashboard home a couple of times to trigger the feed loading
- The following log line is added with every pageload
PHP Deprecated: Fetching multiple feeds with single SimplePie instance is deprecated since SimplePie 1.9.0, create one SimplePie instance per feed and use SimplePie::merge_items to get a single list of items. in /var/www/src/wp-includes/SimplePie/src/SimplePie.php on line 769
Expected Results
- ✅ There should not be any PHP depreciation logs
Actual Results
Before applying the patch
- ❌ Even if transient is not manually forced to expire with the snippet, PHP Deprecated log is added to debug.log once.
After applying the patch
- ✅ Issue resolved with patch.
Supplemental Artifacts
debug.log before applying patch:
This ticket was mentioned in Slack in #core by jorbin. View the logs.
4 weeks ago
This ticket was mentioned in Slack in #core by wildworks. View the logs.
3 weeks ago
This ticket was mentioned in Slack in #core by jorbin. View the logs.
3 weeks ago
@peterwilsoncc commented on PR #10631:
3 weeks ago
#22
@aaronjorbin @t-hamano I've added a bunch of tests for various use cases for both multiple and single feed requests.
On the 6.8 branch there are two different results for unspecified feeds, $url = '' and $url = []:
// 6.8 branch results There were 2 failures: 1) Tests_Feed_FetchFeed::test_fetch_feed_returns_an_error_for_unspecified_url A WP_Error object is expected when no URL is provided. Failed asserting that SimplePie\SimplePie Object (...) is an instance of class "WP_Error". /vagrant/wordpress-develop/tests/phpunit/includes/abstract-testcase.php:838 /vagrant/wordpress-develop/tests/phpunit/tests/feed/fetchFeed.php:102 2) Tests_Feed_FetchFeed::test_fetch_feed_returns_an_error_for_unspecified_url_array A WP_Error object is expected when no URL is provided. Failed asserting that SimplePie\SimplePie Object (...) is an instance of class "WP_Error". /vagrant/wordpress-develop/tests/phpunit/includes/abstract-testcase.php:838 /vagrant/wordpress-develop/tests/phpunit/tests/feed/fetchFeed.php:115
Changing the first part of the if elseifs to the following results in the same result but I think a WP_Error is the best response. What would you prefer?
if ( empty( $url ) ) {
$url = ''; // Allow SP to do it's thing with an unspecified URL.
} elseif ( is_array( $url ) && count( $url ) === 1 ) {
@peterwilsoncc commented on PR #10631:
3 weeks ago
#23
For now, I'm leaning towards maintaining the behavior of the 6.8 branch.
#24
@
3 weeks ago
- Keywords commit added
I think https://github.com/WordPress/wordpress-develop/pull/10631 is ready to commit.
This ticket was mentioned in Slack in #core by jorbin. View the logs.
3 weeks ago
@peterwilsoncc commented on PR #10631:
3 weeks ago
#26
I've pushed https://github.com/WordPress/wordpress-develop/pull/10631/commits/c50c9f71ca851f286fe8a16da6c9f6976cef461d to work around the PHP 8.5 deprecation error.
Once https://github.com/simplepie/simplepie/pull/949 is released the commit can be reverted to avoid the duplicate code.
#27
@
3 weeks ago
https://github.com/WordPress/wordpress-develop/pull/10631 looks good to me. Thanks @peterwilsoncc!
#28
@
3 weeks ago
- Owner set to peterwilsoncc
- Resolution set to fixed
- Status changed from new to closed
In 61551:
#29
@
3 weeks ago
- Component changed from General to Feeds
- Keywords dev-feedback fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for merging to the 6.9 branch pending another committer's sign off.
This ticket was mentioned in PR #10812 on WordPress/wordpress-develop by @jorbin.
3 weeks ago
#30
#31
@
3 weeks ago
- Keywords dev-reviewed added; dev-feedback removed
[61551] looks good for backport to the 6.9 branch.
https://github.com/WordPress/wordpress-develop/pull/10812 tests the backport and the only issue is the flaky test being flaky.

see https://github.com/simplepie/simplepie/pull/795