• I’ve created a custom page which displays some data from the wordpress d/b and a form with action set to another php file, my_processForm.php. that file validates the form data and also accesses the wordpress d/b to get data and update data.

    The custom page works fine but in the action file, I get an error for every line that uses a wordpress function such as
    get_header(); (Call to undefined function get_header)
    and
    $table_prefix = $wpdb->prefix; (Trying to get property of non-object)

    How can I get access to these functions and objects?

Viewing 2 replies - 1 through 2 (of 2 total)
  • It sounds like, and I’m just guessing here, that your form is posting directly to the my_processForm.php file?

    If that’s the case, and you want to use WordPress functions, you would need to include the file ‘wp-blog-header.php’ from the root directory of your wordpress install.

    I’m not so sure that the way you’re doing things is necessarily best practice however. If I were you I would just have the form post back to itself (you can leave the action attribute in the form tag blank) and add in a nonce, as well as a hidden field that identifies your form to WordPress and secures it from CSRF or XSS attacks.

    This article provides a pretty decent example:
    http://voodoopress.com/how-to-post-from-your-front-end-with-no-plugin/

    I hope this helps!

    -gj

    Thread Starter margonline

    (@margonline)

    Thank you, that is helpful! I’ll have a go at it. I’ve been looking at creating a custom post, but your suggestion may be easier to implement. Thanks again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘custom page – access wordpress functions and objects’ is closed to new replies.