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.
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745412700a4626604.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