Skip to content

Instantly share code, notes, and snippets.

@dbernar1
Last active December 18, 2015 19:29
Show Gist options
  • Save dbernar1/5833460 to your computer and use it in GitHub Desktop.
Save dbernar1/5833460 to your computer and use it in GitHub Desktop.
A basic WordPress controller
<?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