Sage 10 - admin folder sibling of app

Hi.

I was wondering if anyone had to deal with an excessive amount of admin customizations through PHP and ended up creating e.g. a folder admin sibling of app.

I’m thinking of a way to better create all the files and directories under this admin folder.

Has anyone ever wondered or did something similar?

Illustration:
directory structure

Maybe I haven’t got it, sorry about that.
Why are you “trying” to use the theme for admin customization instead of a plugin?

Due to the way composer.json autoload is set maybe it’s better to have the admin folder under the app folder so everything under admin would be autoloaded without the need to edit the composer.json file.

Meaning:

If the admin folder is under app the file namespace would be:

namespace App\Admin;

Which means that file would be autoloaded with native setup.

Also, the admin folder should be named Admin to comply with psr-4 autoloading standard.

I ended up with this:

folder structure

I’d appreciate if anyone shared ideas…

@Davide_Prevosto thanks for replying!

That’s a good question.
I actually already have a plugin in which I have many WP tweaks for the admin.
In this case I’m just wondering how I could do it without a plugin.

I mean, I’m thinking of a way to have a structure where any developer could easily understand and edit/delete those admin features for instance.

I also do this a lot:

  • setup/login.php (login screen customizations (logo, title, …))
  • setup/gutenberg.php (barrel file to include the other files)
  • setup/gutenberg/block-types.php
  • setup/gutenberg/decorative-elements.php
  • setup/woocommerce.php (barrel file to include the other files)
  • setup/woocommerce/single.php
  • setup/woocommerce/list.php

Currently I am just requiring those files.
But the composer autoload feature looks cleaner.

@strarsis where is your setup folder located? And do you have a reason for that? I’m just asking to have insights…

Thanks for sharing.

I’ve got your point @filipecsweb
Thanks

1 Like

@filipecsweb: In app/setup/ directory of the Sage 8/9/10 theme.
The reason for naming the directory setup/ is that there is already a setup.php and the directory contains theme-setup-related files.

1 Like