====== Writing a plugin back-end ======
===== Minimal Structure =====
==== _admin.php ====
The plugin should contain an ''_admin.php file'' :
if (!defined('DC_CONTEXT_ADMIN')) {return;}
# add the plugin in the plugins list of the administration menu
$_menu['Plugins']->addItem(
# link name
__('Example'),
# base URL of the back-end
'plugin.php?p=example',
# URL of the image used as an icon
'index.php?pf=example/icon.png',
# URL regular expression
preg_match('/plugin.php\?p=example(&.*)?$/',
$_SERVER['REQUEST_URI']),
# permessions needed to display the link
$core->auth->check('usage,contentadmin',$core->blog->id));
In the previous code, remplace ''example'' by the plugin directory's name. The icon should be 16×16 pixel wide, you can find some in the [[http://www.famfamfam.com/lab/icons/silk/|Silk Icons]] pack.
A link to the administration page is now visible in the sub-menu Extensions of the administration page:
{{:2.0:resources:plugins:admin:menu_item.png|}}
Besides the fact that the plugin defins general permissions in the [[public-page#le-fichier-_define.php|_define.php]] file, it can sometimes be necessary to limit access to the back-end page to fewer users. For that purpose, you have to add after if (!defined('DC_CONTEXT_ADMIN')) {return;}
the following code:
if (!$core->auth->isSuperAdmin()) {return;}
It is of course possible to adapt this code to specific permissions with the ''check()'' function from the ''dcAuth'' class.
==== index.php ====
Here is the base structure of the ''index.php'' file. Note that the '''' doesn't have any attributes : Dotclear adds them when the page is displayed.
blog->name).' › '.
__('Example'); ?>
Here is the result :
{{:2.0:resources:plugins:admin:page.png?300|}}
===== Download the example plugin =====
[[http://lab.dotclear.org/raw-attachment/wiki/plugin/adminExample/plugin-adminExample.zip|plugin-adminExample.zip]]
===== Customize the administration page =====
{{{pagetoc
.:admin:tabs
.:admin:message
.:admin:columns
.:admin:forms
.:admin:example
.:help
}}}