admin管理员组文章数量:1425815
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?
1 Answer
Reset to default 3You 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.
}
本文标签: Creating an endpoint in wordpress
版权声明:本文标题:Creating an endpoint in wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745412699a2657540.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
{"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