0

My background is .NET/C#/Laravel e.t.c

I am beginning to like very much WP and i started educating myself on using WordPress as a development framework.

I tried something very simple. Create an entity and have a basic CRUD on this entity and then show it up in my frontend. Nothing tricky right?

So after reading i found out that one way to do this is to create the entity (aka Custom Post Type) , create custom fields (aka my entity properties) and let WP backend do the CRUD.

Then i could use various techniques to show the data in the frontend.

To my great surprise i found out that the CPT are not persisted in any wp table, and that when i disable my plugin i loos ethe CPT but i do NOT loose the underlying data!!

Imagine my surprise , due to the fact that i am used in having absolute db integrity.

And i wonder , why was it decided that CPTs are working in this way?

  • 2
    I don't understand the problem. If a plugin that register a CPT is disabled, then that content type won't exist anymore, it's fine. I think it is not good idea to delete the data on plugin deactivation but it could be fine to delete it when the plugin is removed. Most plugins do nothing and leave the data on database but you can choose to delete it, it is totally up to you. Anyway, if you develop a plugin for the public, you should notice to the users that data will be lost if they remove the plugin or make it optional. Imaging users loosing data just because they click on a button. – cybmeta Oct 27 '15 at 17:14
  • What db integrity is lost? Per your own statements, the data persists in the database, unless intentionally removed by the plugin that created it. – s_ha_dum Oct 27 '15 at 17:29
  • @s_ha_dum You can remove the CPT and leave custom taxonomy data for thsi CPT to exist in db. In my eyes things like these seem strange. I am just trying to understand and "feel" the WP way...dont get me wrong... – e4rthdog Oct 27 '15 at 18:23
1

I don't think there is definitive answer (there might be old discussion buried in some ticket), but I can offer some historical perspective.

WordPress didn't start with Custom Post Types. They were relatively late addition. While they were modeled after native post types, those still remain kind of special case.

So the concept of such split was kind of already in place — post data was stored in database and logic governing it was stored in runtime code, before CPTs even existed.

In addition WP hooks system and plugin activation/deactivation favor runtime code approach as well. Implementing activation/deactivation in plugins is kind of clunky and most plugins simply don't bother with those routines. For a long time themes didn't even have a way to run activation/deactivation logic without some creative hacks.

Additionally post registrations contain localized strings and WP localization workflow works by extracting strings from source code. Storing those in database would require having two different workflows for compiling list of localized strings. As well as hugely complicate their changes on updates.

In a nutshell — the implementation is simply consistent with WP history and typical practices.

  • Things are clearer..i am navigating probably in the line that decides if you need WP for your needs or not. Ultimately if one want to have a simple /moderate CRUD operation where he turns too? CPTs with Custom taxonomies and custom fileds, or he does go the way of custom tables? – e4rthdog Oct 27 '15 at 18:21
  • Custom tables are considered kind of last resort in WP. People use them, but not until they are really sure they need them. – Rarst Oct 27 '15 at 18:43
  • So if someone needs to make a simple CRUD and display operation what he does? Take Gravity forms to interact with CPT? I mean that eventaully i am feeling like WP has a very very distinct line that says dotn use me from this point on..A line that many people seem to ignore and try to hack wp to do what they need. – e4rthdog Oct 27 '15 at 18:46
  • Yeah, plugins/frameworks are basic approaches to it. – Rarst Oct 27 '15 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.