This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
plugins:creation [2011/12/19 23:25] n00dles101 |
plugins:creation [2014/02/07 09:51] datiswous [Additional plugin files] |
||
---|---|---|---|
Line 7: | Line 7: | ||
This section describes the different parts of a plugin. For this example, lets use this basic plugin that echos "Hello World" at the bottom of every front-end page. [[http://get-simple.info/data/uploads/hello-world.txt|Download Example Plugin]] | This section describes the different parts of a plugin. For this example, lets use this basic plugin that echos "Hello World" at the bottom of every front-end page. [[http://get-simple.info/data/uploads/hello-world.txt|Download Example Plugin]] | ||
- | <code> | + | <code php> |
<?php | <?php | ||
/* | /* | ||
Line 53: | Line 53: | ||
This code could always be hardcoded, but it's best if you define the below code right after your registration. | This code could always be hardcoded, but it's best if you define the below code right after your registration. | ||
- | <code> | + | <code php> |
# get correct id for plugin | # get correct id for plugin | ||
$thisfile=basename(__FILE__, ".php"); | $thisfile=basename(__FILE__, ".php"); | ||
Line 60: | Line 60: | ||
This code is what is used to display your plugin on the "Plugins" tab of the control panel. It also allows you to set the type of page your plugin should be shown as. | This code is what is used to display your plugin on the "Plugins" tab of the control panel. It also allows you to set the type of page your plugin should be shown as. | ||
- | <code> | + | <code php> |
# register plugin | # register plugin | ||
register_plugin( | register_plugin( | ||
Line 79: | Line 79: | ||
This code is what attaches your custom function to a particular hook or filter. | This code is what attaches your custom function to a particular hook or filter. | ||
- | <code> | + | <code php> |
# activate filter | # activate filter | ||
- | add_action('theme-footer','hello_world',array()); | + | add_action( 'theme-footer', 'hello_world', array() ); |
</code> | </code> | ||
**Syntax:** | **Syntax:** | ||
- | add_action(//'hook name'//,//'function to call'//,//Array of Args//); | + | add_action( //'hook name'//, //'function to call'//, //Array of Args// ); |
This code displays a link to a plugin specific page in the administration (it is a special case of //add_action//): | This code displays a link to a plugin specific page in the administration (it is a special case of //add_action//): | ||
- | <code> | + | <code php> |
# add a link in the admin tab 'theme' | # add a link in the admin tab 'theme' | ||
- | add_action('theme-sidebar','createSideMenu',array($thisfile,'Hello World description')); | + | add_action( 'theme-sidebar', 'createSideMenu', array( $thisfile, 'Hello World description' ) ); |
</code> | </code> | ||
**Syntax:** | **Syntax:** | ||
- | add_action('//tab-name//-sidebar','createSideMenu',array($thisfile,'//link text//')); | + | add_action( '//tab-name//-sidebar', 'createSideMenu', array( $thisfile, '//link text//' ) ); |
**Note:** | **Note:** | ||
Line 102: | Line 102: | ||
**Note:** | **Note:** | ||
- | As of version 3.1 you can include multiple menu items on the sidebar by adding an action to the add_action function | + | As of version 3.1 you can include multiple menu items on the sidebar by adding an **//action//** parameter to the ''add_action()'' function: |
- | <code> | + | <code php> |
# add a link in the admin tab 'theme' | # add a link in the admin tab 'theme' | ||
- | add_action('theme-sidebar','createSideMenu',array($thisfile,'Hello World description'),'action1'); | + | add_action( 'theme-sidebar', 'createSideMenu', array( $thisfile, 'Hello World description', 'action1' ) ); |
- | add_action('theme-sidebar','createSideMenu',array($thisfile,'Hello World description 2'),'action2'); | + | add_action( 'theme-sidebar', 'createSideMenu', array( $thisfile, 'Hello World description 2', 'action2' ) ); |
</code> | </code> | ||
This will display 2 menu items on the Theme sidebar, you must check for each action (action1 and action2 above) in your code and display pages accordingly. | This will display 2 menu items on the Theme sidebar, you must check for each action (action1 and action2 above) in your code and display pages accordingly. | ||
Line 114: | Line 114: | ||
The functions in this section would be the functions that are called as part of the registration, a [[plugins:hooks_filters|hook or a filter]]. | The functions in this section would be the functions that are called as part of the registration, a [[plugins:hooks_filters|hook or a filter]]. | ||
- | <code> | + | <code php> |
# functions | # functions | ||
function hello_world() { | function hello_world() { | ||
Line 140: | Line 140: | ||
Thus a sample plugin structure for a plugin ''my_plugin'' with additional php files and images that supports multiple languages might be: | Thus a sample plugin structure for a plugin ''my_plugin'' with additional php files and images that supports multiple languages might be: | ||
- | <code> | + | <code ini> |
- my_plugin.php | - my_plugin.php | ||
- my_plugin (directory) | - my_plugin (directory) | ||
Line 188: | Line 188: | ||
To use your script you must first register it with the system. | To use your script you must first register it with the system. | ||
- | <code> | + | <code php> |
// register_script($handle, $src, $ver, $in_footer=FALSE) | // register_script($handle, $src, $ver, $in_footer=FALSE) | ||
// $handle name for the script, must be unique for each script loaded | // $handle name for the script, must be unique for each script loaded | ||
Line 201: | Line 201: | ||
To queue and load a registered script use: | To queue and load a registered script use: | ||
- | <code> | + | <code php> |
// queue_script($name,$where); | // queue_script($name,$where); | ||
// $name name of the script to load | // $name name of the script to load | ||
Line 212: | Line 212: | ||
To register a script from your plugin folder use | To register a script from your plugin folder use | ||
- | <code> | + | <code php> |
register_script('pluginscriptname', $SITEURL.'plugins/my_plugin_folder/your.script.js', '0.1', FALSE); | register_script('pluginscriptname', $SITEURL.'plugins/my_plugin_folder/your.script.js', '0.1', FALSE); | ||
</code> | </code> | ||
Line 223: | Line 223: | ||
To use your own stylesheets you must first register them with the system. | To use your own stylesheets you must first register them with the system. | ||
- | <code> | + | <code php> |
// register_sstyle($handle, $src, $ver) | // register_sstyle($handle, $src, $ver) | ||
// $handle name for the style, must be unique for each style loaded | // $handle name for the style, must be unique for each style loaded | ||
Line 237: | Line 237: | ||
To queue and load a registered style use: | To queue and load a registered style use: | ||
- | <code> | + | <code php> |
// queue_style($name,$where); | // queue_style($name,$where); | ||
// $name name of the style to load | // $name name of the style to load |