[wp-trac] [WordPress Trac] #42455: WordPress Class methods and Single Responsibility (recent posts widgets)
WordPress Trac
noreply at wordpress.org
Tue Nov 7 13:24:36 UTC 2017
#42455: WordPress Class methods and Single Responsibility (recent posts widgets)
-------------------------------+-----------------------------
Reporter: viewup | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version: 4.9
Severity: normal | Keywords:
Focuses: docs, performance |
-------------------------------+-----------------------------
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42455>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list