最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Creating an endpoint in wordpress

programmeradmin2浏览0评论

I'm writing a plugin that will allow some of my installs to talk to each other and share specific information. I wish to specify an endpoint such that example/path/here is where the other site can GET some nicely formed XML or POST some nicely formed XML (depending on which way the data is flowing).

As a rough hack, I set up ./wp-content/plugins/myplugin/endpoint.php but I get the impression that direct calling is going to be bad. How do I do this the WordPress way?

I'm writing a plugin that will allow some of my installs to talk to each other and share specific information. I wish to specify an endpoint such that example/path/here is where the other site can GET some nicely formed XML or POST some nicely formed XML (depending on which way the data is flowing).

As a rough hack, I set up ./wp-content/plugins/myplugin/endpoint.php but I get the impression that direct calling is going to be bad. How do I do this the WordPress way?

Share Improve this question asked Jun 11, 2019 at 11:19 Matthew Brown aka Lord MattMatthew Brown aka Lord Matt 1,0683 gold badges13 silver badges34 bronze badges 7
  • 2 How about creating a custom REST API endpoint? – Sally CJ Commented Jun 11, 2019 at 11:32
  • That might work. How do I do that? – Matthew Brown aka Lord Matt Commented Jun 11, 2019 at 11:35
  • 2 It's all explained in Sally's link. – Jacob Peattie Commented Jun 11, 2019 at 11:36
  • 1 @MatthewBrownakaLordMatt You can send the data as XML in JSON... {"myXml":"xml data here"} ... if it's not easier to just convert the data to JSON.. – Sally CJ Commented Jun 11, 2019 at 14:01
  • 1 I'm coming round to JSON. Conversion is not so hard. – Matthew Brown aka Lord Matt Commented Jun 12, 2019 at 7:39
 |  Show 2 more comments

1 Answer 1

Reset to default 3

You can create a custom endpoint using the add_feed function. I have used this in the past to create custom iCal feeds.

// Initialize the feed
function your_add_custom_feed() {
    // This adds a feed http://example/?feed=myfeed
    add_feed('myfeed', 'your_create_feed');
}
add_action('init','your_add_custom_feed');

// Create a function to form the output
function your_create_feed() {

    // Query variables are accessible here ($_GET)
    $myvar = get_query_var('myvar');

    // You may need to specify the header before output here depending on your type of feed
    // header(...)

    // Echo your feed here.

}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论