Plugin modules enable Question2Answer to be extended in specific ways. Each module is implemented as a PHP
class with specific member functions. Some functions are relevant for all module types, as described below. Other functions are specific to a certain type of module, e.g. page modules implement the functions
process_request(). If you wish to use non English characters in the PHP code for a module, ensure your text editor is using UTF-8 encoding without a BOM (byte order mark).
Below is a list of the module types supported by Q2A - click for more information about each type:
Some functions are relevant for all module types, as listed below. You may also create a generic module which implements these functions by passing the type
'module' when registering a module with
load_module($directory, $urltoroot, $type, $name). If a module defines this function, it is called by Q2A before the module is used. The
$directory parameter contains the full local path of the module’s plugin directory, which can be used as a prefix for
include statements within the module. The
$urltoroot parameter contains the URL of the plugin directory, relative to the current page request. If the module outputs HTML that references other files (such as images) which are part of the plugin, this prefix should be used for the corresponding URLs. The
$name parameters were added in Q2A 1.6 and contain the module type and name, as originally passed to
option_default($option). If a module defines this function, it is called by Q2A when an option’s value is requested but the option has not yet been set (requires Q2A 1.4+). The
$option parameter contains the name of the option whose default value is needed. If the module recognizes the option name, it should return the appropriate default value, otherwise it should return
null. If no module returns a default value for an option, it will default to the empty string (
admin_form(&$qa_content). If defined, this function allows a module to include a form within Q2A’s admin panel. This function should return a nested array defining a Q2A form, after processing any input from the form if it was just submitted. It may also modify the passed
It is beyond the scope of this documentation to describe
$qa_content and Q2A form arrays in detail - you can find many examples by searching the Q2A code base for
$qa_content or ask here. Some particular points to note:
NAME=...of all buttons and fields (within
tagselements) should have a prefix which is unique to your plugin.
qa_post_text(), as described here, to check for button clicks and retrieve submitted fields.
qa_opt()to get or set an option that is stored in Q2A’s options table. To prevent interference with Q2A or other plugins, any options should be named using a prefix which is unique to your plugin.
init_queries($tableslc). If a module requires some database initialization, e.g. to create its own table, it can define this function to integrate into Q2A’s installation and updating process (requires Q2A 1.5+). For your convenience,
$tableslc contains an array of lower case names of tables currently in the Q2A database. Your function should examine the
$tableslc array and perform any other diagnostics in order to determine whether initialization is required. If so, return an array of one or more MySQL queries that should be run, otherwise return
null. If you are creating a table with a
CREATE TABLE query, you should add the appropriate prefix to the table name - see
qa-db.php or use the
^ symbol before the table name. This will prevent clashes between separate Q2A installations sharing a database.
A module can define any additional functions for its own purposes, in the usual way for a PHP class. These functions can also be used for communication between modules, either within a plugin, or between different plugins. To call a function defined in a module, call
qa_load_module() to retrieve an object of the module’s class, then call the object’s function in the usual PHP way. Note that multiple calls to
qa_load_module() will return the same object.