-1

How do I send a $_POST request to my WordPress application from an external website, and handle it here? I want to send user credentials, along with additional login data, to perform an auto-login.

  1. Do I need to define a new URL for handling the $_POST request?
  2. Which action hook do I need to use for handling such a request?

1 Answer 1

1
1. Do I need to define a new URL for handling the $_POST request?

No, you don't need to define new URL.

2. Which action hook do I need to use for handling such a request?

You can use init hook.

Sample code

function my_theme_send_email() {

    if ( isset( $_POST['email-submission'] ) && '1' == $_POST['email-submission'] ) {

        // Send the email...

    } // end if

} // end my_theme_send_email
add_action( 'init', 'my_theme_send_email' );

Now you can call your website with POST required POST parameters.

Update:

Executed function on init method

Executed function on init method

my code

my code
8
  • init is used when you're handling requests within the WordPress site. Not the requests coming from an external source. This is what the Codex says: Fires after WordPress has finished loading but before any headers are sent. Sep 25, 2015 at 11:58
  • I think you misunderstood it. When you call your website url, WordPress is already initialized. And it will handle request. Sep 25, 2015 at 12:35
  • Check my updated answer. Sep 25, 2015 at 12:39
  • But then the email address is still a $_GET parameter in the same context, right? I need to send the $_POST request from an external URL. The website will not necessarily be loaded. Sep 25, 2015 at 13:06
  • How does $_GET or $_POST make any difference with WordPress loading? I think you first try your code before arguing. Sep 25, 2015 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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