wp-plugin-init
Version:
CLI to scaffold a PHP plugin boilerplate structure
24 lines (20 loc) • 680 B
JavaScript
/**
* Reads the config object injected by the PHP AssetHandler via
* wp_localize_script (window.__PLUGIN_GLOBAL__). Centralising access here
* keeps components free of direct `window` reads and makes the data source
* easy to mock or swap.
*/
const settings = window.__PLUGIN_GLOBAL__ || {};
const AppConfig = {
/**
* @param {string|null} key Dot-free key, or null for the whole object.
* @param {*} fallback Returned when the key is absent.
*/
get(key = null, fallback = null) {
if (!key) {
return settings;
}
return key in settings ? settings[key] : fallback;
},
};
export default AppConfig;