• Hi all

    I’m developing a WordPress plugin for my own needs.
    Maybe, I will try to release it later, but I need to fix some stuff first.

    First of all, I have created a “Delete” link, which will delete the URL with the ID thats provided. The link i working perfectly fine – I have another problem though. Whenever I delete something, I have to refresh the page to see the result (result = URL is gone) – this annoys me!

    I have tried almost anything, but I really can’t make it work. No matter what I do, I get the message “Your URL was deleted successfully!” – but the link is still visible until I refresh the page 🙁

    Here is how my link is built:

    <a href="admin.php?page=comment-reminder&pageSet=true&action=del&id=<?php echo $print->id; ?>&_wpnonce=<?php echo $nonce; ?>">Delete</a>

    And I use an “isset” to handle the links info – it goes like this:

    if(!isset($_GET['pageSet'])){
    	// Nothing happens if the link isn't clicked
    }
    
    else{
    	global $wpdb;
    	$table_name = $wpdb->prefix . "my_new_plugin";
    	$blogid = mysql_real_escape_string($_GET['id']);
    	if (!wp_verify_nonce($_GET['_wpnonce'],'my_new_plugin_nonce') ) { wp_die('Oops, your nonce didn\'t verify. So there.'); }
    	else {
    	$wpdb->query("DELETE FROM $table_name WHERE id = '$blogid'") or wp_die(mysql_error());
    
    	if($wpdb) {
    		echo '<div class="updated"><p>URL successfully deleted!</p></div>';
    	}
    	}
    }

    What do I have to do?
    I’m really stuck here 🙁

    Once I figure this out, I’m sure I can make it work for the “Add new URL” fom also – same problem here … I can’t see the entered URL before I refresh the page. What am I doing wrong??

    – Kucko

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter In10se

    (@in10se)

    Update:

    Well, I’ve read that AJAX can do the trick.
    But since I’m not familiar wit AJAX (what so ever) – I would prefer the “correct” way, if you can put it that way.

    I’m really running out of ideas.. 🙁

    Moderator bcworkz

    (@bcworkz)

    Too bad, AJAX would be ideal, as then you only update the changed element instead of reloading the entire page. I believe the proper way to ensure the page reloads is to prevent the browser from caching the page. There’s a few headers that need to be sent to do this, I’m not sure exactly what they are. To send headers in WP, hook ‘wp_headers’ and add your headers to the passed array. var_dump the array to get an idea of the format.

    I’ve heard you can get the browser to reload by sending a random URL parameter with the link so that each link’s complete text is always slightly different. YMMV.

    If your message is included with the page, I wonder if the browser is reloading and the real issue is the WP cache is not updating until it gets the right sort of request. I don’t know why one request works and the other doesn’t. Just that the solution may be flushing the WP cache rather than forcing a browser reload. Just a thought.

    Thread Starter In10se

    (@in10se)

    Hi bcworkz,

    I would LOVE to use AJAX – but as I already said, I really don’t know how to use it 🙁 Maybe I should practice it a little bit – it’s very useful in general.

    But thanks for your answer anyways, I appreciate it 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Can't reload after "Delete"’ is closed to new replies.