kirki-helpers icon indicating copy to clipboard operation
kirki-helpers copied to clipboard

Error with include-kirki.php in a plugin

Open blogjunkie opened this issue 8 years ago • 2 comments
trafficstars

I'm trying to include Kirki in a plugin. This plugin adds Customizer settings to any theme when the plugin is active. I modified the instructions and included the helper file like this:

require_once plugin_dir_path( __FILE__ ) . 'customizer/include-kirki.php';

When I launch the customizer, I get a fatal error:

[26-Feb-2017 01:09:27 UTC] PHP Fatal error:  Class 'Kirki_Installer_Section' not found in /app/public/wp-content/plugins/blank-slate/customizer/include-kirki.php on line 77
[26-Feb-2017 01:09:27 UTC] PHP Stack trace:
[26-Feb-2017 01:09:27 UTC] PHP   1. {main}() /app/public/wp-admin/customize.php:0
[26-Feb-2017 01:09:27 UTC] PHP   2. require_once() /app/public/wp-admin/customize.php:13
[26-Feb-2017 01:09:27 UTC] PHP   3. require_once() /app/public/wp-admin/admin.php:31
[26-Feb-2017 01:09:27 UTC] PHP   4. require_once() /app/public/wp-load.php:37
[26-Feb-2017 01:09:27 UTC] PHP   5. require_once() /app/public/wp-config.php:81
[26-Feb-2017 01:09:27 UTC] PHP   6. do_action() /app/public/wp-settings.php:470
[26-Feb-2017 01:09:27 UTC] PHP   7. WP_Hook->do_action() /app/public/wp-includes/plugin.php:453
[26-Feb-2017 01:09:27 UTC] PHP   8. WP_Hook->apply_filters() /app/public/wp-includes/class-wp-hook.php:323
[26-Feb-2017 01:09:27 UTC] PHP   9. call_user_func_array:{/app/public/wp-includes/class-wp-hook.php:298}() /app/public/wp-includes/class-wp-hook.php:298
[26-Feb-2017 01:09:27 UTC] PHP  10. WP_Customize_Manager->wp_loaded() /app/public/wp-includes/class-wp-hook.php:298
[26-Feb-2017 01:09:27 UTC] PHP  11. do_action() /app/public/wp-includes/class-wp-customize-manager.php:734
[26-Feb-2017 01:09:27 UTC] PHP  12. WP_Hook->do_action() /app/public/wp-includes/plugin.php:453
[26-Feb-2017 01:09:27 UTC] PHP  13. WP_Hook->apply_filters() /app/public/wp-includes/class-wp-hook.php:323
[26-Feb-2017 01:09:27 UTC] PHP  14. call_user_func_array:{/app/public/wp-includes/class-wp-hook.php:298}() /app/public/wp-includes/class-wp-hook.php:298
[26-Feb-2017 01:09:27 UTC] PHP  15. kirki_installer_register() /app/public/wp-includes/class-wp-hook.php:298

include-kirki.php is unmodified. Is there a reason this is not working in a plugin, rather than a theme as originally intended please?

blogjunkie avatar Feb 26 '17 01:02 blogjunkie

Hey there!

Would it be possible to see your plugin code in order to figure out what goes on? Is it perhaps on a repository somewhere I can see it and test this?

aristath avatar Mar 04 '17 09:03 aristath

Hi Blogjunkie,

I know this is a bit old, but I had the same issue recently.

The problem is, plugins are loaded slightly before themes, so this check is failing:

if ( class_exists( 'WP_Customize_Section' ))

as WP_Customize_Section is not yet available to use, and even if you removed the check the Kirki_Installer_Section class extends WP_Customize_Section again, we get stuck.

The way I got round it was using after_setup_theme to load the include-kirki.php file, and all worked fine from then on:

function my_function_name() {
    require_once( dirname(__FILE__) . '/inc/include-kirki.php');
}
add_action( 'after_setup_theme', 'my_function_name');

VidalThemes avatar Jul 21 '17 19:07 VidalThemes