Question

I want to have a url like this:

http://example.com?user_id=23&entry_id=34$nonce=4j54hgc465

When a user clicks on this link, I want to do something with this information like update the user or post and show a message to user. How can i do this? Should I go with HTTP API or REST API or another easier solution?

More information about what i'm gonna do: I want send an email with a link to the user. This link can be something like this: http://example.com?user_id=23&entry_id=34$nonce=4j54hgc465 When the user gets this email and clicks on this link, I want to publish the post with id=entry_id that user with user_id created. Is this possible?

Was it helpful?

Solution

One option would be to create a Page dedicated to processing these GET requests. Something like http://example.com/create/?yourquerystringhere`.

You can then create a page template, either page-create.php to automatically apply to that page, or a custom template you manually apply from the dropdown. That page template can contain your custom code:

<?php
// if any variables are missing, redirect to homepage
if(empty($_GET['user_id']) || empty($_GET['entry_id']) || empty($_GET['nonce'])) {
    wp_redirect();
// otherwise, process the request
} else {
    // add your code here to make sure user_id, entry_id, and nonce are valid
    // if they're valid, publish the post - you can then display a success
    // message, or redirect to the newly published post
    // you should also check whether entry_id is already published
    // and if so, auto redirect to that rather than re-publishing
}
?>

This way you're just creating a Page template (and a child theme if you don't already have a child theme or a custom one) and one Page to handle all the processing.

Another option would be to set this type of code in your child theme's front-page.php so you don't have to create a Page at all, and if the GET vars are empty or invalid, carry on displaying whatever normally goes on the homepage, else process as above.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top