If you are building a WordPress plugin, you typically need to reference specific values repeatedly—for example, the version or base path. The same is true for a theme or a library.
A pretty common approach is to
define these as constants. There are boilerplates that suggest this approach.
If you have a "main" plugin class, you might have these "constants" as properties too.
Propreties classes of Inpsyde Modularity deal with this topic. They centralize the "constants" in one place, but it also conveniently sets them up.
Instead of defining typical constants one by one:
you can do this:
$pluginPropreties = PluginProperties::new('/path/to/plugin-main-file.php');
and it will parse the plugin's header and set up the properties. You can then access the values by calling methods on the object:
$pluginPropreties->version(); // version of the plugin
$pluginPropreties->name(); // name of the plugin
If you are using Modularity for a theme, you have the
$themeProperties = ThemeProperties::new('/path/to/theme-directory/');
For completeness, there are two more classes, the
LibraryPropreties and the
BasePropreties doesn't parse any file; it expects you to pass some values manually to it. The
LibraryProperties parses a
composer.json file. More about these two somewhere else.
For more detailed information, check the documentation.
Next up the ...