I'm trying to implement a custom RSS feed that is formatted for podcasting and pulls in the audio file from an Advanced Custom Field. Basically I've been working off of the example provided here: /
My plugin looks like this:
// add a custom RSS feed
function podcast_rss(){
add_feed('podcast', 'run_podcast_rss');
}
add_action('init', 'podcast_rss');
function run_podcast_rss(){
require_once( dirname( __FILE__ ) . '/feed-template.php' );
}
This seems pretty straightforward, but when I navigate in my browser to my new feed URL (/) The browser tries to download a file. In Google Chrome, the console shows
Resource interpreted as Document but transferred with MIME type application/octet-stream: "/".
While in Firefox, when it attempts to download the file, it tells me it's a DMS file.
I've tried clearing cache, checking for errors in the code, checking .htaccess for odd settings, setting headers; nothing seems to have an effect. In fact, I can comment out the require_once line and simply try to echo plain text. It still forces a download. I've put this on a different server and it behaves the same.
I have a feeling it's something simple but I'm out of ideas. Any help?
I'm trying to implement a custom RSS feed that is formatted for podcasting and pulls in the audio file from an Advanced Custom Field. Basically I've been working off of the example provided here: https://css-tricks/roll-simple-wordpress-podcast-plugin/
My plugin looks like this:
// add a custom RSS feed
function podcast_rss(){
add_feed('podcast', 'run_podcast_rss');
}
add_action('init', 'podcast_rss');
function run_podcast_rss(){
require_once( dirname( __FILE__ ) . '/feed-template.php' );
}
This seems pretty straightforward, but when I navigate in my browser to my new feed URL (http://example/feed/podcast/) The browser tries to download a file. In Google Chrome, the console shows
Resource interpreted as Document but transferred with MIME type application/octet-stream: "http://example/feed/podcast/".
While in Firefox, when it attempts to download the file, it tells me it's a DMS file.
I've tried clearing cache, checking for errors in the code, checking .htaccess for odd settings, setting headers; nothing seems to have an effect. In fact, I can comment out the require_once line and simply try to echo plain text. It still forces a download. I've put this on a different server and it behaves the same.
I have a feeling it's something simple but I'm out of ideas. Any help?
Share Improve this question asked Mar 22, 2016 at 18:56 mrfolkbluesmrfolkblues 454 bronze badges 4- What is the content of that file? – fuxia ♦ Commented Mar 22, 2016 at 21:54
- If I just echo a string, the file contains the string. If I require_once that template file, it will usually throw an error into the file. For example, if I comment out a part like /* ... */ it errors out on the start of the comment. – mrfolkblues Commented Mar 23, 2016 at 0:12
- Did you check the line endings in that file? – fuxia ♦ Commented Mar 23, 2016 at 2:42
- The file is not being FTPd; it's running on a Vagrant/VirtualBox server on my machine and still has this behavior. – mrfolkblues Commented Mar 24, 2016 at 1:41
2 Answers
Reset to default 1You need to explicitly set the Content Type, otherwise WordPress defaults to octet-stream for unknown feeds.
function run_podcast_rss(){
header( 'Content-Type: application/rss+xml; charset=' . get_option( 'blog_charset' ), true );
require_once( dirname( __FILE__ ) . '/feed-template.php' );
}
As @mrfolkblues pointed out you need to add a filter for the feed_content_type. The code below solved the file download issue for me.
Code credit @swissspidy. https://core.trac.wordpress/ticket/36334#comment:7
<?php
// Example B:
function trac_36334_add_superduperfeed() {
add_feed( 'superduperfeed', 'trac_36334_superduperfeed_cb' );
}
add_action( 'init', 'trac_36334_add_superduperfeed' );
function trac_36334_superduperfeed_cb() {
header( 'Content-Type: text/html' ); // or any other content type
echo 'Do something...';
}
function trac_36334_superduperfeed_type( $content_type, $type ) {
if ( 'superduperfeed' === $type ) {
return feed_content_type( 'rss2' );
}
return $content_type;
}
add_filter( 'feed_content_type', 'trac_36334_superduperfeed_type', 10, 2 );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744910121a4600496.html
评论列表(0条)