我在 wordpress 中创建了自定义插件,用于从数据库中获取数据。我添加了两个链接来对记录执行操作。一个是编辑,另一个是删除。我已经为这样的删除链接编写了代码
<a href="<?php bloginfo('url');?>/wp-admin/admin.php?page=delete_my_review&id=<?php echo $res->review_id; ?>">Delete</a>
当我单击删除链接时,它会显示错误,例如
You do not have sufficient permissions to access this page
我的插件代码是
function submit_review()
{
add_options_page("Submit Review","Submit Reviews",1,"submit_review","submit_review");
global $wpdb;
$id = get_current_user_id();
$q = "select * from wp_submit_review where user_id = " . $id;
$result = $wpdb->get_results($q,OBJECT);
if(!empty($result))
{
?>
<div class="wrap">
<h1>Submitted Reviews</h1>
<div style="width: 100%;">
<table cellpadding="5" class="wp-list-table widefat fixed pages">
<thead>
<tr>
<th><b>Review Id</b></th>
<th><b>User Name</b></th>
<th><b>Submitted Category</b></th>
<th><b>New Listing Name</b></th>
<th><b>New Listing Address</b></th>
<th><b>New Listing City</b></th>
<th><b>New Listing Description</b></th>
<th><b>Image</b></th>
<th><b>R-option</b></th>
<th><b>New Listing Rating</b></th>
<th><b>New Listing Review</b></th>
<th><b>Actions</b></th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $res)
{
?>
<td><?php echo $res->review_id; ?></td>
<td><?php echo get_the_author_meta('user_login',$res->user_id); ?></td>
<td><?php
if($res->submit_category == 1)
{
echo "Service";
}
else if($res->submit_category == 2)
{
echo "Restaurant";
}
else
{
echo "Product";
}
?>
</td>
<td><?php echo $res->newlistingname; ?></td>
<td><?php echo $res->newlistingaddress; ?></td>
<td><?php echo $res->newlistingcity; ?></td>
<td><?php echo $res->newlistingdesc; ?></td>
<td><img src="<?php echo home_url()."/uploads/".$res->image; ?>" height="50px" width="50px"/></td>
<td><?php echo $res->roption; ?></td>
<td><?php echo $res->newlistingrating; ?></td>
<td><?php echo $res->newlistingreview; ?></td>
<td><a href="<?php bloginfo('url');?>/wp-admin/admin.php?page=submit_review">Edit</a> | <a href="<?php bloginfo('url');?>/wp-admin/admin.php?page=delete_my_review&id=<?php echo $res->review_id; ?>">Delete</a></td>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<?php
}
else
{
echo "No review find";
}
}
function delete_my_review()
{
echo $_GET['id'];
}
add_action("admin_menu","delete_my_review");
function submit_review_menu()
{
add_menu_page("Submit Review","Submit Review","manage_options","submit_review", submit_review);
}
//add_action("admin_menu","submit_review");
add_action("admin_menu","submit_review_menu");
那么如何调用 delete_my_review() 函数来执行删除操作呢?