<?php
// Set the path of the plugin folder
define('PATH_PLUGINS','plugins');
$plugin_path = "." . DIRECTORY_SEPARATOR . PATH_PLUGINS . DIRECTORY_SEPARATOR;
if ($handle = opendir($plugin_path)) {
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
switch($file) {
case ".":
case "..":
break;
default:
if(is_dir($plugin_path . $file)) {
// INITIALIZE PLUGIN HERE
$plugin_name = $file;
$plugin_load = $plugin_path . $file . DIRECTORY_SEPARATOR . $file . ".php";
if(file_exists($plugin_load)) {
try {
// CHECK IF PLUGIN INITIALIZED OR CONFLICTING INIT FUNCTION
if(!function_exists($file . '_init')) {
include($plugin_load);
// CHECK IF PLUGIN_INIT() FUNCTION EXISTS AND EXECUTE IT
if(function_exists($file . '_init')) {
eval($file . '_init();'); // Execute the INIT function in the plugin;
}
}
} catch (Exception $e) {
echo "PLUGIN [" . $file . "] FAILED TO LOAD: " . $e->getDescription();
}
} else {
echo "PLUGIN [" . $file . "] MISSING BOOTSTRAP.";
}
}
break;
}
}
closedir($handle);
}
?>
function example_init() {
try{
// Do some stuff here
echo "PLUGIN INITIALIZED";
} catch (Exception $e) {
// Save debug to log file or whatever -- returns false as init failed.
return false;
}
return true;
}
function example_displaystuff() {
echo "This should be displayed if the function exists";
}
eval($plugin_name . '_yourfunctionname();');
eval($plugin_name . '_yourfunctionname(' . $myparam1 . ',' . $myparam2 .');');
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)