widoz / template-loader Goto Github PK
View Code? Open in Web Editor NEWA WordPress template loader to use within your plugin
License: GNU General Public License v2.0
A WordPress template loader to use within your plugin
License: GNU General Public License v2.0
Add a facade.
Everything must be defined during instantiation.
Creating an interface will allow us to pass every type of instance instead of manipulate objects to obtain the properties values.
In this way the loader will be indipendently by the data type and the view will be able to use any kind of data.
namespace TemplateLoader;
interface TemplateData {}
Render method has just to render and returing a string.
Sometimes the $data object isn't necessary but we must create an instance in anycase.
So, let's use null if no data is used.
In order to prevent third party code to hook and edit in wrong way the path for the template file I think a validation/sanitization may be useful for the path.
Also, we should be sure that the path belong to the wp-content/plugins
or wp-content/themes/{current-active-theme}
or the parent theme.
Instead of looking every time for the same files, using an additional static property as array where store the found paths will improve speed.
The plugin path will not be correctly if the template loader is used as composer package.
So, remove the Plugin
class and introduce an additional arguments to the contructor for Loader
that will be the plugin directory path.
public function __construct($slug, DataStorage $storage, $templatePath = null, $pluginPath = '')
{
$this->slug = Sanitizer::sanitizeSlugRegExp($slug);
$this->data = null;
$this->dataStorage = $storage;
$this->pluginPath = $pluginPath;
$this->setTemplatePath($templatePath);
}
then in pluginFilePath
...
} elseif (is_string($tmplPath)) {
$pluginPath = untrailingslashit($this->pluginPath);
$tmplPath = ltrim($tmplPath, '/');
$path = Sanitizer::sanitizePath("{$pluginPath}/{$tmplPath}");
}
...
```
Check for unneeded methods.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.