I am creating my first wordpress plugin.
one of the questions i have is understanding what files i should be included in php files that are not directly called by wordpress.
For example:
I have the user submitting a form. In the form on a page i use the constant WP_PLUGIN_URL, which works fine. The form posts to
<form action="<?=WP_PLUGIN_URL?>/myplugin/lib/functions.php" method="post">
The constant works fine.
In functions.php I have and it does not recognize WP_PLUGIN_DIR. i get the message
Use of undefined constant WP_PLUGIN_DIR
So what is the proper way to included whats needed. Do i just include wp-includes/default-constants.php or is there a better way to do it?
Thanks
<?php
global $current_user;
global $wpdb;
if ( isset($_POST['action']) ){
switch($_POST['action']){
case 'newpost':
include_once(WP_PLUGIN_DIR.'/myplugin/lib/insert.php');
insertDB();
break;
}
}
?>
Try this
WordPress’ core function designed for plugin designing purpose. For more help and guidelines take a look at this and this nice article that all you need.