WordPress-Plugin-Boilerplate icon indicating copy to clipboard operation
WordPress-Plugin-Boilerplate copied to clipboard

How to load dependencies that extend other classes

Open sc00 opened this issue 3 years ago • 2 comments

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?

sc00 avatar Aug 31 '21 21:08 sc00

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?

VoHoTv avatar Sep 01 '21 09:09 VoHoTv

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..

sc00 avatar Sep 01 '21 15:09 sc00