Skip to content

Commit

Permalink
Framework: Provide methods to register plugin features and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
eliot-akira committed Oct 24, 2024
1 parent 27a6a3c commit 5c03c65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions framework/plugin/dependencies/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ function check_plugin_dependencies($plugin) {
$deps = $plugin->dependencies ?? [];
if (empty($deps)) return true;

$missing = [];
$missing_deps = [];

foreach ($deps as $dep) {
if (
(isset($dep['active']) && !$dep['active'])
|| (isset($dep['callback']) && !$dep['callback']())
) {
$missing []= $dep;
$missing_deps []= $dep;
}
}

if (empty($missing)) return true;
if (empty($missing_deps)) return true;

$plugin->missing_dependencies = $missing_deps;

Expand All @@ -37,7 +37,7 @@ function check_plugin_dependencies($plugin) {
}

// Default notice
framework\register_admin_notice(function() use ($missing_deps) {
framework\register_admin_notice(function() use ($plugin, $missing_deps) {
?>
<div class="notice notice-warning">
<p><b>Missing plugin dependencies for <?php echo $plugin->title; ?></b></p>
Expand Down
5 changes: 5 additions & 0 deletions framework/plugin/features/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

require_once __DIR__ . '/settings.php';

function register_plugin_features($plugin, $features) {
$plugin->features = $features;
framework\load_plugin_features( $plugin );
}

function load_plugin_features($plugin) {

$features = $plugin->features ?? [];
Expand Down

0 comments on commit 5c03c65

Please sign in to comment.