admin管理员组文章数量:1384098
I know how to register custom endpoints for Wordpress REST API and actually use it to output podcasts from my website like this:
register_rest_route( 'myradio/v1', '/podcasts/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => 'myradio_podcasts_api_endpoint',
'args' => array(
'id' => array(
'description' => esc_html__( 'Unique identifier for the object.', 'myradio' ),
'type' => 'integer',
'prop_format' => 'int64',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
},
),
),
));
Now I want to register an additional route to allow users to subscribe to my podcasts. For that I offer a RSS feed with the same data, right now as a custom link using a wordpress template, setting the header as Content-Type: application/rss+xml.
To integrate this functionality directly in the REST API I want to register a RSS feeds endpoint adding /rss to the route with something like that:
register_rest_route( 'myradio/v1', '/podcasts/(?P<id>\d+/rss)', .array(...) );
Where and how do I define the response content type as application/rss+xml?
When I tried to echo the RSS feed directly at my callback function, the browser complains about an not well-formed document because the header is application/json.
本文标签: Wordpress Rest API custom endpoint for RSS feed
版权声明:本文标题:Wordpress Rest API custom endpoint for RSS feed 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744535601a2611295.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论