最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp list table - Remove Admin Notice on page refresh

matteradmin8PV0评论

I have a simple question about admin notices. I want to display a message like 'Record updated successfully', and when user refresh again same page, then this notice should not be there as no record is updated again.

Just like settings Api, there is notice as 'Settings saved.' and when we refresh the page the notice is not there. I see in URI argument is there as

.php?page=xyz&settings-updated=true

I know here settings-updated=true is the key, and it disappear immediately and user can hardly notice it. But I don't know how it disappears after taking effect. I think I am missing very simple and basic trick.

Any help highly appreciated

I have a simple question about admin notices. I want to display a message like 'Record updated successfully', and when user refresh again same page, then this notice should not be there as no record is updated again.

Just like settings Api, there is notice as 'Settings saved.' and when we refresh the page the notice is not there. I see in URI argument is there as

http://example/wp-admin/admin.php?page=xyz&settings-updated=true

I know here settings-updated=true is the key, and it disappear immediately and user can hardly notice it. But I don't know how it disappears after taking effect. I think I am missing very simple and basic trick.

Any help highly appreciated

Share Improve this question edited Apr 8, 2019 at 12:30 W.Ahmed asked Apr 8, 2019 at 12:24 W.AhmedW.Ahmed 233 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

This is done by wp_admin_canonical_url:

  • It calls wp_removable_query_args to fetch a list of query string parameters to remove, which includes settings-updated.
  • It then writes some script into the page header to use window.history.replaceState to remove the query string from your browser's URL bar.

    <link id="wp-admin-canonical" rel="canonical"
          href="http://example/wp-admin/admin.php?page=xyz">
    <script>
        if ( window.history.replaceState ) {
            window.history.replaceState( null, null,
                document.getElementById( 'wp-admin-canonical' ).href +
                    window.location.hash );
        }
    </script>
    

If you want to add your own arguments to the list that gets removed then you can hook removable_query_args.

Post a comment

comment list (0)

  1. No comments so far