Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/devgeniem/wp-exhale
Developer friendly exporter framework for WordPress
https://github.com/devgeniem/wp-exhale
Last synced: 28 days ago
JSON representation
Developer friendly exporter framework for WordPress
- Host: GitHub
- URL: https://github.com/devgeniem/wp-exhale
- Owner: devgeniem
- Created: 2016-08-02T08:27:24.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-16T08:51:00.000Z (almost 8 years ago)
- Last Synced: 2024-05-10T02:41:12.758Z (6 months ago)
- Language: PHP
- Size: 16.6 KB
- Stars: 0
- Watchers: 10
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# WP Plugin: Exhale
Developer friendly framework for creating xml data exports from WordPress.
This works only with php7.0 or better because we use scalar type hinting.## Install plugin
```
$ composer require devgeniem/wp-exhale
$ wp plugin activate wp-exhale
```## Usage
You need to define class which extends our parent class `Exhale\Base\XML`.
This class is autocalled when suitable request comes and you don't need to hook it anywhere.For example this could look like:
```php
'value');
}/**
* If you need to wrap your data into custom element you can use this
* Empty array is ignored
*/
static public function xml_root_element() : array {
return array(
'name' => 'wrapper'
);
}/**
* This function can be used to map custom namespaces into the xml
* Empty array is ignored
*/
static public function xml_namespaces() : array {
return array(
'http://www.w3.org/2001/XMLSchema-instance' => 'xsi',
);
}
}
```This class now automatically provides custom data export from: `http://yoursite.com/api/export/myprovidername.xml`
With contents:
```xmlvalue
```
## How it works?
This plugin uses [sabre/xml](http://sabre.io/xml/writing/) inside.
The array from `get_export_data()` function is mapped into xml write operation in sabre/xml.
This way you get all the good things from sabre/xml as well.If the exhale url is requested the XML is produced in `plugins_loaded` hook and then process is stopped immediately.
## Settings
You can override default exporter url by defining in wp-config:
```php
define('EXHALE_URL_PREFIX','/my-custom/api/url/');
```
The earlier example would now be accessible from: `http://yoursite.com/api/export/myprovidername.xml`## Special cases
If you want to add attributes to your elements or have multiple elements with same key you can do this with sabre/xml compatible custom arrays:
```php
static public function get_export_data() {
return array(
[
'name' => 'item',
'attributes' => [
'url' => 'http://yoursite.com'
],
'value' => 'value'
],
[
'name' => 'item',
'attributes' => [
'url' => 'http://example.com'
],
'value' => 'nothing'
],
);
}
```
This will produce following xml:
```xml
value
nothing
```## License
GPLv3