Support » Plugins » Hacks » Custom types and related actions

  • Hello,

    i am capable of creating my own site in “bigger” CMSs or Frameworks or even from scratch, but i truly respect what the folks at wordpress have done and i want to use it so I was wondering, with having global* actions like “save_details”, isn’t there anyway to make sure variables won’t collide? i mean, yeah i will name my variables with meaningful names, i might even do a switch case to check what’s the custom type i am working with and execute a callback function, but why not add another argument to the add_action function that allows it to work only on a specific type or custom type! what if i just want to save my “Cars” custom field without having to worry about the variables scope!

    tl;dr what techniques do you use/suggest for dealing with numerous custom types with numerous custom fields?


    * I am not sure about the scope of add_post function though.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    For actions, it would be difficult to anticipate all the possible constraints a developer may wish to apply. I think it’s better left to the developer to define the scope they desire and implement it.

    The only collision avoidance suggestion I’m aware of is to preface names with an unlikely string such as the initials of your plugin or theme name. This is fine for internal names, but is messy for names that are part of the user experience. At least for fields, you can be highly descriptive, but for post types, this is challenging since we are limited to 20 characters.

    About all you can really do is be aware of the collision issue and avoid highly generic names. Also perhaps organize your code so it’s easy to change names in case of conflict. Perhaps by using defined constants, filter hooks, pluggable code, etc. In particular a way to change names that will not get overwritten during an update, similar to how child themes are implemented.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom types and related actions’ is closed to new replies.