Last active
December 18, 2015 19:29
-
-
Save dbernar1/5833460 to your computer and use it in GitHub Desktop.
A basic WordPress controller
This file contains 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 | |
define( 'DB_VH_REWRITE_TAG', 'feed-relay' ); | |
add_action( 'init', 'db_vh_create_feeds_relay_urls' ); | |
function db_vh_create_feeds_relay_urls() { | |
add_rewrite_rule( | |
$rule = 'feeds/(.*)/?', | |
$rewrite = 'index.php?' . DB_VH_REWRITE_TAG . '=$matches[1]', | |
$position = 'top' | |
); | |
add_rewrite_tag( '%' . DB_VH_REWRITE_TAG . '%', '([^&]+)' ); | |
} | |
add_action( 'wp', 'db_vh_feed_relay_controller' ); | |
function db_vh_feed_relay_controller() { | |
global $wp_query; | |
if ( isset( | |
$wp_query->query_vars[ DB_VH_REWRITE_TAG ] | |
) ) { | |
$requested_feed = $wp_query->query_vars[ DB_VH_REWRITE_TAG ]; | |
// Do something. Probably a switch on $requested_feed. | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment