Creating an endpoint in wordpress

I'm writing a plugin that will allow some of my installs to talk to each other and share specific information. I wi

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.

}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745412700a4626604.html

相关推荐

  • Creating an endpoint in wordpress

    I'm writing a plugin that will allow some of my installs to talk to each other and share specific information. I wi

    4小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信