admin管理员组

文章数量:1025202

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.

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.

本文标签: wp list tableRemove Admin Notice on page refresh