devgeniem/wp-exhale 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

devgeniem/wp-exhale

Composer 安装命令:

composer require devgeniem/wp-exhale

包简介

Creates Developer friendly xml api endpoint for 3rd party integrations on your data.

README 文档

README

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
/**
 * This class exists so that users of Exhale can start producing xml really quickly
 */
class MyProviderName implements \Exhale\Type\XML {
    /**
     * Returns exportable apartments to Vuokraovi
     */
    static public function get_export_data() : array {
        return array('item' => '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:

<wrapper xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <item>value</item>
</wrapper>

How it works?

This plugin uses sabre/xml 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:

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:

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:

<item url="http://yoursite.com">value</item>
<item url="http://example.com">nothing</item>

License

GPLv3

统计信息

  • 总下载量: 830
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 8
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-08-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固