Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
fix(autoload): register fallback autoload as needed (#255)
Browse files Browse the repository at this point in the history
x-ref #254
  • Loading branch information
QWp6t authored Aug 31, 2020
1 parent e88ee19 commit 5036bf6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 4.0.1: August 31st, 2020
* Add fallback autoloader when Composer isn't present

### 4.0.0: August 29th, 2020
* BREAKING CHANGE - Refactor entire code base
* Add options support for modules
Expand Down
10 changes: 7 additions & 3 deletions soil.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: Soil
* Plugin URI: https://roots.io/plugins/soil/
* Description: A collection of modules to apply theme-agnostic front-end modifications to WordPress.
* Version: 4.0.0
* Version: 4.0.1
* Author: Roots
* Author URI: https://roots.io/
* GitHub Plugin URI: https://github.com/roots/soil
Expand All @@ -15,9 +15,13 @@

namespace Roots\Soil;

require_once __DIR__ . '/vendor/autoload.php';

add_action('plugins_loaded', function () {
if (!class_exists(Soil::class)) {
require_once file_exists($autoloader = __DIR__ . '/vendor/autoload.php')
? $autoloader
: __DIR__ . '/src/autoload.php';
}

$modules = Soil::discoverModules();

add_action('after_setup_theme', new Soil($modules), 100);
Expand Down
13 changes: 13 additions & 0 deletions src/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

require_once __DIR__ . '/helpers.php';

spl_autoload_register(function ($className) {
$relativeClassName = array_slice(explode('\\', $className), 2);
$file = __DIR__ . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $relativeClassName) . '.php';
if (file_exists($file)) {
require $file;
return true;
}
return false;
});

0 comments on commit 5036bf6

Please sign in to comment.