Fetch Driver Classname
apply_filters( 'vikrestaurants_fetch_export_driver_classname', string $classname, string $driver )
Fires while instantiating the requested export driver.
Description
Trigger hook to let the plugins include external export drivers.
The plugins MUST include here all the resources needed to the driver, otherwise it wouldn't be possible to instantiate the returned classes.
The filter should return the PHP class
name related to the requested driver.
In case the specified class doesn't exist, an exception will be thrown. The class MUST extend the VREOrderExportDriver
abstract class.
NOTE: the file in which the driver class is located should NOT be included.
Parameters
- $classname
-
(string) The classname that will be used to instantiate the driver object.
- $driver
-
(string) The name of the driver to include, which is equals to the base name of the file (without
.php
).
Example
The example below provides the instantiation of the "test" driver located within the VikWP plugin.
/wp-content/plugins/vikwp/drivers/test.php
/**
* Trigger hook to let the plugins include external drivers.
* The plugins MUST include the resources needed, otherwise
* it wouldn't be possible to instantiate the returned classes.
*
* @param string $classname The classname of the driver object.
* @param string $driver The name of the driver to include.
*/
add_filter('vikrestaurants_fetch_export_driver_classname', function($classname, $driver)
{
if ($driver === 'test')
{
/**
* @todo it is possible to load here external resources...
*/
// return class name for the "test" driver
$classname = 'VikWPExportDriverTest';
}
return $classname;
}, 10, 2);
The class (shell) of the driver will be built as follows.
class VikWPExportDriverTest extends VREOrderExportDriver
{
/**
* Returns the driver title.
*
* @return string
*/
public function getTitle()
{
return 'VikWP - Test';
}
/**
* Returns the driver description.
*
* @return string
*/
public function getDescription()
{
return 'Driver for test purposes';
}
/**
* Override this method to return a list of
* arguments required to driver.
*
* @return array
*/
public function getForm()
{
return array();
}
/**
* Exports the reservations in the given format.
*
* @return string The resulting export string.
*/
public function export()
{
$buffer = '';
/**
* @todo generate string to export
*/
return $buffer;
}
/**
* Downloads the reservations in a file compatible with the given format.
*
* @param string $filename The name of the file that will be downloaded.
*
* @return void
*/
public function download($filename = null)
{
/**
* @todo send headers to download the file
*/
}
}
Changelog
Version | Description |
---|---|
1.0 | Introduced. |