0

I'm trying to include the Minit plugin in the inc folder of my WordPress theme and calling it in my functions.php file:

require get_template_directory() . '/inc/minit-master/minit.php';

However, after its added it doesn't work as it does when it is a plugin and I can't see why.

1

Well, Minit for WordPress is hooked into the plugins_loaded action hook (you can see that checking the file minit.php).

And the thing is you are requiring the file minit.php in your functions.php, which is a file loaded after the hook plugins_loaded is called. This means that Minit is not being initialized the proper way.

So, basically, you have two choices:

  1. Put minit-master directory inside your plugins directory so you can load minit.php like it should be loaded, as a WordPress plugin.

  2. Or you could keep the way you want by changing the source code of minit.php to be loaded within after_setup_theme hook:

<?php
/*
Plugin Name: Minit
Plugin URI: https://github.com/kasparsd/minit
GitHub URI: https://github.com/kasparsd/minit
Description: Combine JS and CSS files and serve them from the uploads folder.
Version: 1.4.1
Author: Kaspars Dambis
Author URI: https://kaspars.net
*/
// Until we add proper autoloading.
include dirname( __FILE__ ) . '/src/minit-assets.php';
include dirname( __FILE__ ) . '/src/minit-asset-cache.php';
include dirname( __FILE__ ) . '/src/minit-js.php';
include dirname( __FILE__ ) . '/src/minit-css.php';
include dirname( __FILE__ ) . '/src/minit-plugin.php';
include dirname( __FILE__ ) . '/src/admin.php';
include dirname( __FILE__ ) . '/src/helpers.php';

// Here we changed from `plugins_loaded` to `after_setup_theme`.
add_action( 'after_setup_theme', array( 'Minit_Plugin', 'instance' ) );
  • Ahh, of course! I can't believe I missed that. Was too busy digging around in the other files. Thanks @filipecsweb ! – Troy Templeman May 26 at 1:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.