First, my problem is similar to this thread. However, the solution posted there doesn't work for me.
I'm creating a plugin that displays a contact form on a page using the Shortcode API.
Plugin folder contents:
- contact.php (main plugin file)
- validate.php (included php file)
The main file has the usual plugin header, and WordPress functions called in it work as expected [i.e: get_permalink()]
The validate.php file is included in contact.php as follows:
define ("PLUGIN_PATH", plugin_dir_path(__FILE__));
include_once dirname( __FILE__ ) . '/validate.php';
My problem is any WordPress functions called in validate.php will throw a fatal error. PHP functions work as expected, only WordPress functions are throwing a fatal error:
Fatal error: Call to undefined function sanitize_text_field() in /{FULL WEBSITE PATH}/ralrom-contactform/validate.php
How should I be including the validate.php file to be able to call WordPress functions from it?
I have tried "require" and "include" variations and all throw the same fatal error.
Before using multiple files, I had a working version as a single file shown here:
Orignal working code under a single php file: http://pastebin.com/qM5aj9qY
Broken code under two php files: http://pastebin.com/KUCbg6rJ
include_once
call directly in plugin body? Not nested in any functions? Is it possible something tries to loadcontact.php
directly?