1

I just created a WordPress plugin with a custom template that handles a $_GET request before the HTML code. Wordpress team is asking me to put this code inside a function.

I understand that for admin panel forms the way is to use

admin-post.php

or

add_action( 'admin_post_****', '****' );

But how do you handle a front-end form post (not that of admin panel). In what kind of a function should I put my template's $_GET or $_POST handling code. Because wordpress.org is not accepting my plugin without these request handles to be inside a function.

1
  • 1
    admin-post is acceptable for front-end form processing, there are actions for both logged-in and not-logged-in users. It might help to explain what your form does exactly- are you adding data to the database, filtering a query, etc..
    – Milo
    Commented Sep 23, 2017 at 17:25

1 Answer 1

0

you can use something like this:

add_action( 'admin_post_add_foobar', 'prefix_admin_add_foobar' );
//this next action version allows users not logged in to submit requests

//if you want to have both logged in and not logged in users submitting, you have to add both actions!

add_action( 'admin_post_nopriv_add_foobar', 'prefix_admin_add_foobar' );


function prefix_admin_add_foobar() {
    status_header(200);
    die("Server received '{$_REQUEST['data']}' from your browser.");
    //request handlers should die() when they complete their task
}

for more information you can check this page

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.