0

I have a form which is embedded in a custom post type.

The form action points to a PHP file that sits in my mu-plugins directory:

<form action="http://www.foo.com/wp-content/mu-plugins/FormCode/formprocess.php">

This works fine; upon 'submit', this PHP file is invoked.

The problem I'm having is that formprocess.php doesn't seem to "see" core WP functions as in-scope. For example, calling wp_verify_nonce() is throwing an HTTP 500 error.

I tried adding require_once(ABSPATH .'wp-includes/pluggable.php'); and it is still not working.

What else can I do to assure that core WP files are available to my form handler? Or, is there an entirely different approach I should be using?

1 Answer 1

0

Accessing files within WP installation directly is a bad practice. While you can implement a custom core load routine, it is fragile and impossible to reliably ship in public plugins.

There are different approaches to form submission in WP. On of the most appropriate ones (if slightly underknown) is sending form to wp-admin/admin-post.php and using hooks inside to attach processing logic.

1
  • Thanks, Rarst - you are 100% correct and I have used this method before, I had just forgotten about it. Unfortunately for this particular case I was not able to get it to work -- I'm doing this via AJAX with admin-ajax.php -- and I could not get the function to be called based on the wp_ajax_nopriv_ action firing. I think it's because I am trapping the output buffer and making string substitutions, and it's screwing up the execution sequence. Anyway I ended up using require_once( explode( "wp-content" , __FILE__ )[0] . "wp-load.php" ); in my handler function. Ugly, but simple. Commented May 27, 2016 at 2:57

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.