Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/*
Plugin Name: rewrite test
Description: rewrite test
Author: Nick
Version: 1.0
*/
register_activation_hook(__FILE__, 'activate');
function activate()
{
// matches https://www.mycelltracker.com/tracker/8BA21D90-3F90-407F-BAAE-800B04B1F5EB
add_rewrite_rule('tracker/[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}/?', 'index.php?pagename=tracker&t=$matches[1]', 'top');
//add_rewrite_tag('%tracker%','([^&]+)');
flush_rewrite_rules();
}
add_filter( 'query_vars', 'my_query_vars' );
function my_query_vars($query_vars)
{
$query_vars[] = 't';
return $query_vars;
}
add_filter('template_redirect', 'my_template_redirect');
function my_template_redirect()
{
exit(var_dump(get_query_var('t')));
}
register_deactivation_hook(__FILE__, 'deactivate');
function deactivate()
{
flush_rewrite_rules();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.