2017 © Pedro Peláez
 

library ll-plugin-autoloader

image

level-level/ll-plugin-autoloader

  • Monday, April 9, 2018
  • by level-level
  • Repository
  • 5 Watchers
  • 0 Stars
  • 1,645 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 6 Versions
  • 43 % Grown

The README.md

Level Level plugin autoloader

When 0-loader.php is inserted into the mu-plugins directory it will load all subdirectory plugin as it would normal plugins., (*1)

Configuration options

You have multiple options to manipulate where the Plugin Loader will look for a vendor folder. Define one of the following values in wp-config:, (*2)

1. Default == wp-content directory

If you define nothing it will load the same as 2. wp-content directory., (*3)

2. wp-content directory

Load from the parent directory above mu-plugins (should be the wp-content dir). This is only used when no LL_AUTOLOAD_DIR is set., (*4)

define('LL_AUTOLOAD_CONTENT_DIR', true);

3. Child theme

Use the current Child theme via get_stylesheet_directory as the theme folder containing the vendor folder. This is only used when no LL_AUTOLOAD_DIR is set., (*5)

define('LL_AUTOLOAD_USE_CHILD', true);

4. Parent/default theme

Use the current parent theme via get_template_directory as the theme folder containing the vendor folder. This is only used when no LL_AUTOLOAD_DIR is set., (*6)

define('LL_AUTOLOAD_USE_PARENT', true);

5. Custom path

Use a specific directory. The script will still append /vendor/autoload.php to this path., (*7)

define('LL_AUTOLOAD_DIR', '/path/to/wordpress/theme/');

Overview

Setting Result
Nothing wp-content directory
define( 'LL_AUTOLOAD_DIR', '/tmp/' ); /tmp/
define( 'LL_AUTOLOAD_CONTENT_DIR', true ); wp-content directory
define( 'LL_AUTOLOAD_USE_CHILD', true ); Stylesheet directory (child theme)
define( 'LL_AUTOLOAD_USE_PARENT', true ); Template directory (parent theme)

Pre and Post autoload

Pre autoload

Right before the vendor autoload file is loaded, the pre-autoload.php file in the directory specified as the autoload directory is required if it exists., (*8)

This file can be used to set environment variables required in composer loaded dependencies., (*9)

Post autoload

Right after the vendor autoload file is loaded, but before the mu-plugins are loaded, the post-autoload.php file in the directory specified as the autoload directory is required if it exists., (*10)

This file can be used to bootstrap/configure mu-plugin loaded dependencies, or trigger actions that need to happen as early as possible, but autoloading to be set up., (*11)

Adding logging is an example of this. You probably require the Monolog composer dependency, but want it to be bootstrapped before we load the mu-plugins., (*12)

Force load normal plugins

In some cases, loading a plugin as must-use plugin can cause issues with the plugin. Instead, you have the option to force load plugins like normal plugins., (*13)

In the path where also your vendor folder is, create a file called ll-forced-plugins.json. Inside, paste the following content., (*14)

{
    "forced_plugins": [
        {
            "slug": "first-plugin/first-plugin.php",
            "network": false
        },
        {
            "slug": "second-plugin/second-plugin.php",
            "network": true
        }
    ]
}

The slug references the plugin file to load. Network determines if a plugin should be network activated if it's a multisite installation., (*15)

Please note these force activated plugins will only be activated when visiting the WP-admin. This is needed because some plugins want to perform actions like redirects directly after activation., (*16)

Upgrading from v2.x to v3.x

In v3, the wp-content directory loads by default, instead of the template directory in v2. To restore behaviour, set define( 'LL_AUTOLOAD_USE_PARENT', true ); in wp-config.php., (*17)

The Versions

09/04 2018

dev-master

9999999-dev

  Sources   Download

09/04 2018

v2.1.0

2.1.0.0

  Sources   Download

06/04 2018

dev-pre-post-files

dev-pre-post-files

  Sources   Download

21/09 2017

v2.0.0

2.0.0.0

  Sources   Download

31/08 2017

v1.1.0

1.1.0.0

  Sources   Download

23/11 2016

v1.0.0

1.0.0.0

  Sources   Download