Created
May 24, 2013 18:54
-
-
Save hice3000/5645726 to your computer and use it in GitHub Desktop.
This is an example plugin for the plugin system I wrote for the CodeIgniter PHP Framework.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Remember to set the class name equal to the folder and file name! | |
class Test { | |
// If this function is not found, the script will exit with an error | |
public function get_information() { | |
return array( | |
// Enter every name you want to call your plugin | |
'name' => 'Very Cool Test Plugin', | |
// The id of the plugin, this should not contain spaces or other special characters except of '_' | |
'ID' => 'test_plugin', | |
// Short description of what your plugin does | |
'description' => 'This is the first plugin I wrote, and it does ... nothing', | |
// Your name (doesnt matter which one - nickname or your real name) | |
'author' => 'hice3000', | |
// The version of your plugin, should be numeric | |
'version' => 0.1 | |
); | |
} | |
public function register_hooks() { | |
return array( | |
// pairs of key-value-entries, the key is the name of the hook, and the value the method in this class | |
// CodeIgniter should call when an event is fired. The method name can be anyone you like! I prefer | |
// 'on_<hook_name>'. | |
'user.change_name' => 'on_change_username' | |
); | |
} | |
// This method is called when the event 'system.pre_controller' was fired. Be sure to define the first parameter! | |
// You can change the parameters like you want, but if you do, you have to return them again. | |
public function on_change_username($params) { | |
// In my plugin I want to do something really useless! Lets uppercase the username and put an 'i' in front of it! | |
$new_name = $params['username']; | |
$new_name = ucfirst($new_name); | |
$new_name = 'i'.$new_name; | |
$params['username'] = $new_name; | |
return $params; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment