WordPress-Plugin-Boilerplate
WordPress-Plugin-Boilerplate copied to clipboard
Can't access properties in nested class
I'm having huge trouble in getting the boilerplate to share data between classes. As an example, I'm defining a protected property protected $plugin_url;
in includes/class-plugin-name.php. It's populated when __construct() runs. I can access the property in that class using $this->plugin_url
. However, I can't get it to work in public/class-plugin-name-public.php. Tried all of the following with no success:
$this->plugin_url
$plugin_url
parent::plugin_url
self::plugin_url
...
I've noticed that none of the Boilerplate classes extend the core class, which means that none of the properties or methods can be easily shared. I thought that replacing
class Plugin_Name_Public {
with
class Plugin_Name_Public extends Plugin_Name {
would do the trick, but no luck. Any suggestions?
I see that overall the Boilerplate works around this by re-defining $plugin_name and $version in each class. Seems like a massive duplication of data every single time. Particularly with a plugin that may end up growing to dozens of extra classes/files.
Is there a reason why the boilerplate uses nested classes? Could this be why I can't access properties defined in one class in a sub-class like Plugin_Name_Public?
Please help. Thanks!
Did you require the Plugin_Name
class when extending the Plugin_Name_Public
class? If I'm not mistaken, there is no autoloader in this boilerplate so things won't just work on their own...