I am developing a plugin where I need to send an activation link to subscribers.
Now I am stuck at the creation of the activation link. I want something like www.page.com/newsletter/activate?key=xxxx&hash=xxx
.
But how to create this own slug without adding a content page? This page shouldn't have any output. After activation the script simply redirects to a confirmation page. This confirmation page shouldn't be a "real" content page too but should output a small text. How to do this from a plugin?
You can use the action of WordPress. In this case, you can handle the link like this:
add_action('init', 'check_newsletter_link');
function check_newsletter_link(){
if (preg_match('/newsletter\/activate/', $_SERVER['REQUEST_URI']) && isset($_GET['key'], $_GET['hash'])){
$key = $_GET['key'];
$hash = $_GET['hash'];
//Your code goes here
}
}
You can write your PHP code there. WordPress action is a magic :)
You are going to have to look into rewrite rules in Wordpress, to solve this the 'pretty' way.
I'm no fan of this plugin called WP Router, but it provides you with the functionality you desire: https://github.com/jbrinley/WP-Router
If you don't wanna use that plugin, build your own rewrite rules in your plugin:
Steps to take: