我工作的一个插件,插件中我想在新表中添加数据。 我创建这个文件我创建了一个文件“lsp_manage_foo.php”
<form action="<?php echo plugin_dir_url(__FILE__) ?>lsp_foo/lsp_manage_process.php" method="post" name="lsp_add_foo">
<table width="100%" border="0" cellspacing="4" cellpadding="0">
<tr>
<td width="25%">
<label>
foo Name
</label>
</td>
<td width="58%">
<input type="text" name="lsp_add_foo" id="lsp_add_foo" value="">
</td>
<td width="10%" align="right">
<input type="submit" name="lsp_save_foo" value="Add Foo">
</td>
</tr>
</table>
</form>
而在“lsp_manage_process.php”
<?php
global $wpdb;
$foo_add = $wpdb->prefix."lsp_foo";
$lsp_foo_name = stripslashes(strip_tags($_POST['lsp_add_foo']));
$foo_shortcode = str_replace(" ", "_", $lsp_foo_name);
$foo_shortcode = strtolower($foo_shortcode);
$foo_data = array(
'foo_name' => $lsp_foo_name,
'foo_shortcode' => $foo_shortcode
);
$foo_insert = $wpdb->insert($foo_add,$foo_data);
header("Location: lsp_manage_foo.php");
?>
我所面临的问题是,当我点击提交进入“lsp_manage_process.php”文件,并告诉我这个错误
Notice: Trying to get property of non-object in /var/www/dev/lgs_pro/wp-content/plugins/foo_pro/lsp_foo/lsp_manage_process.php on line 5
Fatal error: Call to a member function insert() on a non-object in /var/www/dev/lgs_pro/wp-content/plugins/foo_pro/lsp_foo/lsp_manage_process.php on line 18
我加入这一行上面的“全球WPDB $”
include "../../../../wp-includes/wp-db.php";
但是,没有发生
我的文件路径结构
wp-content/plugins/foo_pro/lsp_foo/lsp_manage_process.php
任何想法。