WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#43174 closed defect (bug) (invalid)

Gutenberg uses deprecated recent posts

Reported by: LewisCowles Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.1
Component: Posts, Post Types Keywords:
Focuses: ui, administration Cc:

Description

Looking to use some work from latest posts widget in Gutenberg. It seems that it's pulling from a deprecated function which branches from the normal side-bar widget version (called recent posts, but recent / latest are mostly synonymous).

https://github.com/WordPress/gutenberg/blob/213c64bb495946deffa3b6fe260f95b87de5774a/blocks/library/latest-posts/index.php#L16

https://github.com/WordPress/wordpress-develop/blob/bd6f3f617a7170bedd7492cafd730b1831905f57/src/wp-includes/post.php#L3091

There is no filter for args (or anything else) in either the gutenberg decorator nor the wp_get_recent_posts method. I think this hints at inconsistency that could be problematic for new users.

It's been problematic for me when testing more control via tags in featured / curated content using post tags.

https://github.com/WordPress/wordpress-develop/blob/8f95800d52c1736d651ae6e259f90ad4a0db2c3f/src/wp-includes/widgets/class-wp-widget-recent-posts.php#L70 seems quite concise and seems to be able to drop-in fix the wp_get_recent_posts method with a change to the filter and WP_Query directly instead of via get_posts.

Happy to take up fixing.

Change History (7)

#1 @swissspidy
3 years ago

  • Component changed from General to Posts, Post Types

So what exactly should be fixed? If you want Gutenberg to use WP_Query for that block, you should open an issue on GitHub.

Note: wp_get_recent_posts() isn't deprecated. It's just not used in core except for the XML-RPC API.

#2 @LewisCowles
3 years ago

Hi @swissspidy,

Gutenberg already indirectly uses WP_Query that's how get_posts works. The issue is that there is no way to hook what is sent to WP_Query in either the gutenberg widget (which has a confusing name, hence ui tag), or get_posts.

I am looking into WP_Query but Imagine it will have the same result or lack of control (I only want to curate recent/latest posts).

Thanks for letting me know about Gutenberg. I will be raising an issue on the GitHub, but it looks like any change would likely need to be in core also (as it's simply using core, and the functionality I'd like is buried within a widget class).

I can understand why things are the way they are. But I also believe I can make them better without changing the main or edge cases, or making yet another take on recent posts...

Last edited 3 years ago by LewisCowles (previous) (diff)

#4 @peterwilsoncc
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

@LewisCowles Thanks for opening the issue on Gutenberg's GitHub issue tracker. I'm closing this ticket off now it's being tracked elsewhere.

#5 @LewisCowles
3 years ago

What happens if they accept the issue? It's not just a Gutenberg fix, it requires changes to core, or duplicate code...

#6 @swissspidy
3 years ago

Gutenberg switching to a custom WP_Query with the same filter as the Recent Posts widget doesn‘t require any change in core.

#7 @LewisCowles
3 years ago

You must understand that means it'll be broken for Gutenberg forever then?

Is it a planned degradation of recent post functionality?

I'd just like to understand what the logic is.

Right now Gutenberg pulls from WP core. It pulls from a method that cannot be hooked into.

If it switches to a WP_Query it seems to make sense to have it pull from recent posts, since recent and latest post do pretty much the same thing.

I'm finding it hard to understand why that wouldn't benefit core from moving that recent posts functionality into posts (because there is a similar function that does the same thing), and just having one place instead of three for themes, plugins and maintenance.

Version 0, edited 3 years ago by LewisCowles (next)
Note: See TracTickets for help on using tickets.