My situation: I have build a few simple ("procedural") WP plugins by now, and now I want to move my plugin skills to a higher, advanced level

In my WP plugin handbook I read: "In order to avoid conflicts with other WP plugins or WP itself; prefix everything!" Which is of course a very good idea for the mentioned reason. But at the same time I'm trying to find a way to limit the prefixing to only the parts where it is really necessary. Since 'everything' is a lot.

There are two reasons why I try this:

  • All this prefixing doesn't do much good to the readability of my code
  • I'm busy building my own plugin foundation and I want to limit search/replace when adding a plugin specific prefix to the entire project later on as much as possible. (Or is there some nifty other way to do this?)

Anyhow, As I see it now, it's important to prexif everything EXCEPT:

  • Vars inside functions which don't have a global scope
  • vars/properties inside classes
  • functions/methods inside classes

(Class names themselves however do need to be prefixed because they are used upon instantianation of the objects.) The reason for my assumption is that these exceptions are being used inside a function name or object handler which is already prefixed.

My first question is: are my assumptions right?

My second(ary) question is: are there smarter ways to handle my objections against 'too much' prefixing, in the scope of my situation?

1 Answer 1


You should use php namespaces and then you will not need to prefix any code. You will do need to prefix things that you store in the DB, like option and meta names.

  • Thanks Mark. You said the magic word. My next step is diving into the wonderful world of PHP namespaces :) Another step further.
    – Gooly
    Commented Nov 24, 2017 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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