Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

PHP plugin system

Name: Anonymous 2007-01-22 1:41

So every PHP plugin system I've seen is OO.
Is there any way to make a plugin system using functions?

Name: Anonymous 2007-01-23 4:29

>>6
Simple "plugin" system:

<?php
function Plugin($plugin, $args) {
    extract $args;
    require "plugins/$plugin.php";
}
?>



How to use: You save that bit of code anywhere, and require it from your PHP code. Then you create "plugins" in the "plugins" subdirectory, an example of which would be this "greeting.php" plugin:

<?php
echo "Hello, $name";
?>



Whenever you want to call it, after you've required the first bit of code, you just do:

Plugin('greeting', array('name' => 'Pete'));

To pass arguments to plugins, define them in a dictionary like this. To use them from plugins, just use $xxx.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List