anthonybudd / WP_Model

A simple drop-in abstract class for creating active record style eloquent-esque models of WordPress Posts
MIT License
100 stars 20 forks source link

Why use Self::getPostType() in non-static save()? #4

Closed stuporglue closed 7 years ago

stuporglue commented 7 years ago

Hi Anthony,

Is there a reason that you use the static getPostType() method inside of save(), instead of first checking if the instance has $this->postType set?

I'm looking at using WP_Model as part of a user-configurable syncing process, so hard-coded classes won't exist. Instead, based on the configuration that the user has set up, I want to create an instance of $userConfedPostType = new MyDynamicPostType(), set $userConfedPostType->postType, set the data and then call $userConfedPostType->save().

MyDynamicPostType extends WP_Model to handle the custom syncing details.

$userConfedPostType->save() fails because save() calls WP_Model::getPostType() which uses reflection to check the post type in the base class, and completely ignores the postType value that I have set.

I'm happy to fork and apply my changes, but I'm wondering if I missed some a reason for it, or if I'm just trying to do something that's unsupported.

Thanks, Michael Moore

anthonybudd commented 7 years ago

Hi Micheal,

Honestly I'm not sure why I made the save method work like that.

Please feel free to fork and I will have a look at your improvements!

Thanks