我创建了一个保存按钮,将页面的URL保存到数组中的用户元。我现在试图创建一个删除按钮,但我发现当使用delete\\u user\\u meta时,它会删除数组中的所有条目,以及与当前页面相等的条目。
我对这一切都很陌生,所以也许这不是最好的方式。。。有没有关于如何删除数组中等于$currentpage的部分的提示?
<?php
$currentpage = home_url( add_query_arg( NULL, NULL ) ); //Get current page
$user_id = get_current_user_id(); //Get current user ID
if(!$user_id){
wp_loginout();
} else {
if(isset($_POST["submit"])){
$data["pluginlink"] = $_POST["pluginlink"];
foreach ($data as $key => $value)
{
add_user_meta($user_id, $key, $currentpage);
}//end for each
}//end else
}//end if user id
if(!$user_id){
wp_loginout();
} else {
if(isset($_POST["Remove"])){
$data["pluginlink"] = $_POST["pluginlink"];
foreach ($data as $key => $value)
{
delete_user_meta($user_id, $key, $currentpage);
}//end for each
}//end else
}//end if user id
$userdata = get_userdata($user_id);
$meta = get_user_meta($user_id);
$data["pluginlink"] = $meta["pluginlink"][0];
?>
<?php
if(in_array($currentpage,$meta["pluginlink"])) {
echo "Page has already been saved";
$savebutton = "display: none;";
$deletebutton = "display: block;";
} else {
echo "page not saved yet";
$savebutton = "display: block;";
$deletebutton = "display: none;";
}
?>
<div class="buttondisplay" style=" <?php echo $savebutton; ?> ">
<form method="post" enctype="multipart/form-data">
<table class="ui collapsing striped table">
<tr></tr>
<tr><td>Current URL: <?php echo $currentpage; ?></td>
<td><input type="submit" name="submit" value="Save" class="ui blue mini button"></td></tr>
</table>
</form>
</div><!-- end save button -->
<div class="deletebutton" style=" <?php echo $deletebutton; ?> ">
<form method="post" enctype="multipart/form-data">
<table class="ui collapsing striped table">
<tr></tr>
<tr><td>Current URL: <?php echo $currentpage; ?></td>
<td><input type="submit" name="Remove" value="Remove" class="ui blue mini button"></td></tr>
</table>
</form>
</div><!-- end delete button -->