【发布时间】:2014-09-06 12:58:19
【问题描述】:
我正在开发一个插件,在插件中我想在新表中添加数据。我在我创建的这个文件中创建了一个文件“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
我在“global $wpdb”上面包含了这一行
include "../../../../wp-includes/wp-db.php";
但是什么都没发生
我的文件路径结构是
wp-content/plugins/foo_pro/lsp_foo/lsp_manage_process.php
任何想法。
【问题讨论】:
-
var_dump($wpdb);给你什么?文件是单独加载还是插件核心的一部分?I think this might help you