Site icon Hip-Hop Website Design and Development

Delete user meta but only if found in array

I created a SAVE button that saves a page’s URL to the user meta in an array. I’m trying to now create a REMOVE button but I’m finding that when delete_user_meta is used it deletes all entries in the array and the one equal to the current page.

I’m very new to all this so maybe this isn’t the best way to go about this…any tips on how to just remove the part of the array that is equal to $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 -->