[wp-trac] [WordPress Trac] #43740: Filter WP_Post methods (vs. removing final/'get_post' filter)

WordPress Trac noreply at wordpress.org
Wed Apr 11 21:33:26 UTC 2018


#43740: Filter WP_Post methods (vs. removing final/'get_post' filter)
-------------------------+-------------------------------------------------
 Reporter:               |      Owner:  (none)
  MikeSchinkel           |
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Posts, Post  |    Version:
  Types                  |   Keywords:  has-patch dev-feedback needs-
 Severity:  normal       |  testing
  Focuses:               |
-------------------------+-------------------------------------------------
 There has been a lot of demand to remove `final` from `WP_Post` and to add
 a `get_post` filter, for good reason.  There as also be a lot of pushback
 on those actions, also for very good reason.  Both sets of reasons can be
 found in ticket #24672 and #12955, respectively.

 In a nutshell for, there are many valid use-cases where being able to
 extend `WP_Post` would make for more robust and maintainable code. In the
 against case, removing `'final'` could easily resolve in an explosion of
 incompatible child classes making plugin interoperability challenging, and
 backward compatibility almost impossible if code decided to evolve WP_Post
 in any way.  And the `'get_post'` filter would be almost as bad as
 removing `final`, and I am one who advocated for both for years.

 However, we actually already have an extensibility mechanism that has
 shown the test of time and that is the use of filter hooks. Given a
 judicious use of filter hooks we could actually allow developers to extend
 `WP_Post` in a compossible manner thus minimizing plugin integration
 problems and also safeguarding core's ability to add enhancements in the
 future.

 The proposal is basically to add filter hooks in the methods of `WP_Post`,
 and to add a `__set()` and `__call()` magic method as a companion to the
 existing `__get()` magic method. Here are the filters I am proposing:

 ||= Filter Hook=||=Method=||
 || `'wp_post_supports_instance'` ||  `__construct()`||
 || `'pre_wp_post__isset'` ||`__isset()`||
 || `'wp_post__isset'`  ||`__isset()` ||
 || `'wp_post__call'`  || `__call()` ||
 || `'wp_post__set'`  || `__set()` ||
 || `'pre_wp_post__get'`  || `__get()` ||
 || `'wp_post_filter'`  ||`filter()` ||
 || `'wp_post_to_array'`  || `to_array()` ||

 And then this action hook:

 * `'wp_post__construct'` in `__construct()`

 I have attached a patch for `class-wp-post.php` that would implement these
 hooks.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43740>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list