Created
August 24, 2023 15:29
-
-
Save cagrimmett/2d1af12e8f95677394ac319c998c8d9c to your computer and use it in GitHub Desktop.
mu-plugin for /.well-known/feeds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Custom OPML Feed | |
Description: Implements a custom OPML feed at /.well-known/feeds/ | |
Author: cagrimmett | |
*/ | |
// Add custom rewrite rule | |
function custom_opml_rewrite_rule() { | |
add_rewrite_rule( '^\.well-known/feeds/?$', 'index.php?custom_opml_feed=1', 'top' ); | |
} | |
add_action( 'init', 'custom_opml_rewrite_rule' ); | |
// Add custom query variable | |
function custom_opml_query_vars( $query_vars ) { | |
$query_vars[] = 'custom_opml_feed'; | |
return $query_vars; | |
} | |
add_filter( 'query_vars', 'custom_opml_query_vars' ); | |
// Serve OPML file | |
function serve_custom_opml_feed() { | |
if ( get_query_var( 'custom_opml_feed' ) ) { | |
$opml_file_path = 'https://cagrimmett.com/opml/well-known-feeds.opml'; // Replace with your actual file path | |
header( 'Content-Type: text/x-opml' ); | |
readfile( $opml_file_path ); | |
exit; | |
} | |
} | |
add_action( 'template_redirect', 'serve_custom_opml_feed' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment