Namespacing BEDROCK

Hello everyone,

thanks again for awesome Bedrock stack!

Today, I posted the question about best practices of Wordpress namespacing on Wordpress StackExchange and as it is connected to Bedrock & does not seem to be very popular at WPSE, I thought I would try my luck here.

How to mimic the file structure by namespaces and in the same time, by
as much FIG-friendly as possible? In the same time, “the packages” of
“the app” should be stored in separate folders, so they can be required
by composer.json files and monitored by GIT.

If the scope of the question extends Roots/Bedrock support forum, please feel free to delete me. :slight_smile:

Thank you, Petr!

When I was trying to post the link to question, for some reason I was getting “500 internal server error” in both Firefox and Chrome. Any idea why?

In this reply, including link works: WPSE Question

There’s some standards that aren’t worth trying to adhere to (especially when it comes to WordPress). This isn’t really an answer, but I’m just not sure it’s worth the trouble trying to do proper FIG/PSR folder structures of namespaces.

You’d have to implement your own custom autoloaders for plugins since WP has expectations about root php files for instance.

Hello again :),

ultimately I’ve created my own autoloader - both SPL for automatic inclusion of class files sitting somewhere along my namespaces AND for mu-plugins sitting in subfolders.

If anyone happened to be interested in the sollution, I faked the namespace in the following manner:

  • Wpgrouse\MuPlugins\Base\Src for folder app/mu-plugins/wpgrouse-mu-plugin-base/src/someclass.class.php
  • Wpgrouse\Themes\WpgrouseThemeParent for folder app/themes/wpgrouse-theme-parent
  • … and so on

Autoloader than translates relevant parts of the string to work with the basic Wordpress & Bedrock file structure.

If interested, check a “very beta” version of the autoloader.

1 Like