Eseye Eseye - 15 days ago 4
PHP Question

Send $_POST data to custom Wordpress plugin

I have a custom Wordpress plugin that handles many things including download pages for my products. The links are not the path to the actual PHP page to my plugin. For example...

http://myurl.com/download/product


But the path to my plugin that actually handles the download function is this path:

http://myurl.com/wp-content/plugins/myplugin/myplugin.php


I have built an app that uses these download links to grant a user the ability to download a product after purchase. But now I need to send extra data along with the url. How can I send some additional $_POST data when the users click on the download link. I have tried

http://myurl.com/download/product?id=2345&user=tom


But when I try to echo out the variables in myplugin.php I get nothing.

echo $_GET['id'];

echo $_GET['user'];


I have also tried to use a form and send hidden inputs but still the same result.

Any help would be greatly appreciated.

Answer

Create a new shortcode (maybe empty that does nothing) and put it on some page you created from WordPress. Then, form action will be the URL to new page where you send data you need to send and method will be post. You can handle the data you sent in new shortcode function in your plugin using $_POST['data']

This might help you as an alternative solution.