Using PHP Namespace Instead Of Class/Function Prefix?


There’s a requirement for WordPress themes to use a prefix that’s unique to the theme/author. However, the adoption of PHP 5.3 is now pretty good so I was considering using namespaces instead to avoid having, frankly, disgusting class/function names.

Has anyone else tried this? Or foresee any problems with it?

Always work to WordPress minimum requirements:

Until they drop PHP 5.2, sadly neither can we!

Also, prefixing is to help avoid clashes from plugins.


Well, they sort of support it. It technically will work on it, but they do advise not to run it:

Note: If you are in a legacy environment where you only have older PHP
or MySQL versions, WordPress also works with PHP 5.2.4+ and MySQL 5.0+,
but these versions have reached official End Of Life and as such may expose your site to security vulnerabilities.

I’ll give namespaces a whirl, see what happens at the review step! As it’s just so much better than random, seemingly disconnected classes!

Can someone from reviewers @kailoon please help and let us know whether we can use namespace as prefix in WordPress Themes and plugins

Hi, until you get an official reply from reviewers, please also check these Updated WordPress requirements published recently: Updated WordPress Requirements

Required Prefixes
A unique prefix must be used for all function names, classes, hooks, public/global variables, action/filter hooks, custom image sizes, constants, database entries, theme-specific scripts and theme-specific styles to avoid conflicts with plugins and other themes.
Prefixes should consist of either themename_, authorname_ or frameworkname_. While multiple prefixes are allowed (theme-specific, framework and external PHP libraries), they must be consistent, at least three characters, and unique (ie not using a common term such as ‘seo’). For more information, refer to Prefix all the things article: