[wp-hackers] Questions regarding extending WP_Post
Dion Hulse (dd32)
wordpress at dd32.id.au
Wed Dec 4 01:50:19 UTC 2013
See the original implementation ticket:
In short: It's declared final to prevent people extending it as there
wasn't a full thought on how it should be utilised, so extending it was
disabled so as not to break back-compat when it's modified later.
As for why it doesn't have any methods for common things yet, that's also
due to the implementation not being final.
You might want to check out http://core.trac.wordpress.org/ticket/12267 too
On 4 December 2013 12:38, Funkatron <funkatronic at gmail.com> wrote:
> Hello, WP Hackers! I have a few questions on the implementation of the
> WP_Post class that WordPress uses. I was wondering if there was a
> technical reason why WP_Post is declared final? I was doing some research
> on ways to extend it and I found it strange that its declared final, making
> it impossible to extend the class other than to copy, paste and editing the
> code. Was there a particular reason or was it just the coder's preference?
> Second question is about posts and the filtered template functions like
> the_title, the_content, etc. Is there any reason why these functions
> weren't included as methods of the WP_Post class? To me it makes sense and
> would allow coders to not rely on the global variables and functions in
> secondary loops. Instead of using the global variables via the_post or
> using setup_postdata and having to call wp_reset_postdata afterwards to
> clean everything up, you could call the methods os the WP_Post class.
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers