For our first Omeka plugin, we will create a HelloWorld plugin that allows you to append your name to an item's show page.
1. Create a directory for your plugin in the plugins/ directory. The name of the directory has to be camel-cased with the name of your plugin. In our case, we will created plugins/HelloWorld
2. Create two new files in the plugins/HelloWorld directory named plugin.php and plugin.ini
3. In the plugin.php file, add the following code:
<?php // add plugin hooks add_plugin_hook('public_append_to_items_show', 'hello_world_print_message'); add_plugin_hook('config', 'hello_world_config'); add_plugin_hook('config_form', 'hello_world_config_form'); // save plugin configuration page function hello_world_config() { // save the message as a plugin option set_option('hello_world_message', trim($_POST['hello_world_message'])); } // show plugin configuration page function hello_world_config_form() { // create a form inputs to collect the user's message echo '<div id="hello_world_config_form">'; echo '<label for="hello_world_message">Your Message:</label>'; echo text(array('name'=>'hello_world_message'), get_option('hello_world_message'), null); } function hello_world_print_message() { // print a paragraph with the user's message echo '<p>Hello World, ' . get_option('hello_world_message') . '</p>'; } ?>
Notice that the function names in your plugin are prefixed with the name of your plugin. In this case, the function prefix is "hello_world_".
4. In the plugin.ini file, add the following code:
[info] name="HelloWorld" author="Your Name" description="Allows users to add Hello World message on their item show pages." omeka_minimum_version="1.0" omeka_tested_up_to="1.0" version="0.1" tags="silly"
5. Login as an administrator to your Omeka website and install the HelloWorld plugin. On the plugin configuration page enter your message.
6. Goto any item's show page and you will see your message.