DevinVinson / WordPress-Plugin-Boilerplate

[WordPress] A foundation for WordPress Plugin Development that aims to provide a clear and consistent guide for building your plugins.
http://wppb.io
7.62k stars 2.25k forks source link

How to load dependencies that extend other classes #569

Open sc00 opened 2 years ago

sc00 commented 2 years ago

I'd like to load ColorAlpha as a dependency in my plugin.

I've tried to use...

require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-color-alpha.php';

... in includes/class-my-plugin.php with the load_dependencies() method, but I get a critical error.

Apparently the problem lies with the dependency being a class, that extends another class:

namespace WPTRT\Customize\Control;

use WP_Customize_Color_Control;

class ColorAlpha extends WP_Customize_Color_Control { 
   ...
}

Does anyone know how to solve this?

VoHoTv commented 2 years ago

The fact that the class simple extends another class cannot be the issue. Do you have any error message? Did you make sure WP_Customize_Color_Control is available when extending it? Is the file path to the class correct?

sc00 commented 2 years ago

The fact that the class simple extends another class cannot be the issue. Do you have any error message? Did you make sure WP_Customize_Color_Control is available when extending it? Is the file path to the class correct?

No specific error message - only the generic wordpress one (critical error). The file path is correct. Once I omit the "extends"-part, I can access the CMS with no issues. I guess WP_Customize_Color_Control is not available when the dependencies are being loaded then. Do you know how I can check for that or make it available? Or is it perhaps recommended to load the dependency from a $plugin_admin method?

I was actually able to make it work with this method. But it feels like it's the wrong location to place it..