Plugin.php_Hints_and_Tips - e107inc/e107v1 GitHub Wiki
title: Plugin.php Hints and Tips permalink: /Plugin.php_Hints_and_Tips/
Introduction
This article aims to provide some hints and tips that can be employed in a plugins plugin.php file.
Setting $eplug_table_names/$eplug_tables
Normally, these variables are set directly in the plugin.php file.
Using the code outlined below, the values required can be obtained from the myplugin_sql.php file. This file, when provided, also allows the website administrator to run a database check against the plugin tables to ensure they are set up correctly. So, creating an sql file serves two purposes and helps maintain the integrity of the plugin.
Determining current action
This applies 2.0 release only
Whenever plugin.php is called from one of the core tasks (installer/upgrader/uninstaller/plugin scanner) the array variable $plug is set. Fields which are present depend on the circumstances. In most cases the relevant entries from the plugin_table database entry are included if the plugin has been installed.
In many cases $plug['plug_action'] is set to indicate the current action:
- 'scan' - plugin scanner
- 'install' - a fresh install is to be performed
This information is sometimes relevant to assist plugin.php in determining the values to return.
Determining if a plugin is installed
2.0 Version
To check whether a plugin is installed, call:
e107::isInstalled($plugname);
where $plugname is the plugin name (directory name).
The function returns TRUE if installed, FALSE otherwise.
0.7.9 to 1.0.x Versions
This applies to 0.7.9 and above
All installed plugins are entered into the $pref['plug_installed'] array - the array index is the path of the plugin (as a directory name) and the data is the current version.
So, the contents of a typical array might be:
This information can be used in two ways:
- To check whether a plugin is installed, use isset($pref['plug_installed']['calendar_menu']) for example.
- To test the installed version of a plugin. Note that the version string text will be exactly as specified in plugin.php.
Writing safe plugins
Read Wiki article integrate with e107 for safety tips.