• I experience a problem using xyz-shortcodes added to a page.
    When the page has been autosaved automatically then the page in the gutenberg editor as well as the real page will present “Fatal error: Cannot redeclare…” where … is Class or function.
    When I disable the snippet or the plugin I can access the page in the editor. If I then remove the autosaved page, reenable the snippet the page will load perfectly in the editor and the real page.

    I already increased the autosave timeout to 1 day and hoped that this would resolve my problem. But when I press preview in the editor, the page is autosaved and the script will fail again. Hence I’m stuck in a not workable situation.

    In some way the script appears to be run twice when a page is autosaved.
    If this post is in the wrong location then pleas point me to the correct location.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,
    Fatal error happened because the function what you are using is already existing in the snippet. However please send us the code what you are using for the same.

    Thread Starter richardstam

    (@richardstam)

    Thanks for your reply.
    I’m sure the function is not defined twice in my code.
    The issue is: I get the error only when the snippet is called from a page that has been saved by autosave. So when no autosave exists, then the error does not occur.

    My assumption is that the code is run from both the autosaved and the normal page.

    How to reproduce:
    – create a snippet containing a function
    – add the shortcode for the snippet to a page (in the gutenberg editor).
    – go to the page and see that all is fine.
    – wait until the page is autosaved (normally after 1 minute)
    – open the page in the gutenberg editor
    result: The editor does not open, but you will get an error stating the redefinition of the function.

    Thanks for your help!

    • This reply was modified 4 years, 1 month ago by richardstam.
    Thread Starter richardstam

    (@richardstam)

    Addition: instead of waiting for an autosave, you could also press preview (then the page is also autosaved) and refresh the tab in which you are editing the page. This will also cause the script to fail with a “redefine”-error

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Autosave of pages causes “Fatal error: Cannot redeclare… “’ is closed to new replies.