Skip to content

Instantly share code, notes, and snippets.

@cagrimmett
Created August 24, 2023 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cagrimmett/2d1af12e8f95677394ac319c998c8d9c to your computer and use it in GitHub Desktop.
Save cagrimmett/2d1af12e8f95677394ac319c998c8d9c to your computer and use it in GitHub Desktop.
mu-plugin for /.well-known/feeds
<?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