Make WordPress Core

Opened 4 years ago

#42455 new enhancement

WordPress Class methods and Single Responsibility (recent posts widgets)

Reported by: viewup Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9
Component: Plugins Keywords:
Focuses: docs, performance Cc:


WordPress uses PHP Classes a lot and this is great for extending and improving. The problem is, many class methods does a lot of things at once and this doesn't help extending at all.

For instance, I'm trying to extend the Recent Posts Widget (WP_Widget_Recent_Posts).

The plugin has it's internal settings and logic, query posts and apply filters.

I want to change it's render method, but just that. Don't want to mess with the plugin logic.

The problem is, the render method (widget method) does a lot of things instead of focusing only on rendering. This forces me to copy every logical actions and reproduce them on my extending class.

This could be solved by just splitting the plugin logic and rendering in separated functions (an function to get the posts and filters, separated from the widget function).

This would improve a lot the WordPress extending by plugins and themes. If we apply the single responsibility principle on WordPress classes and functions, plugins wouldn't need to have much more code.

Another point: this enhancement wouldn't impact old plugins/themes if the functions signatures keep the same.

Change History (0)

Note: See TracTickets for help on using tickets.