• Resolved atkulp

    (@atkulp)


    Any new snippet I try to save fails with no details. When I click to save and activate, the page returns a 302 with a redirect to “…/page=add-snippet&result=save-error”. The code block is for setting Google API key for Advanced Custom Fields and is this:

    function my_acf_google_map_api( $api ){
        $api['key'] = 'MY KEY';
        return $api;
    }
    add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');

    Any help would be appreciated.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Does this still occur if you try to add an empty snippet with just a title?

    Thread Starter atkulp

    (@atkulp)

    Yes. Is it writing to a table or a file? I can check permissions and also run repair on the table to be safe.

    Plugin Author Shea Bunge

    (@bungeshea)

    It’s writing to the {prefix}snippets database table.

    Plugin Author Shea Bunge

    (@bungeshea)

    The plugin will recreate the table if it doesn’t exist, so if you can export your existing snippets and delete the table that might resolve things.

    Thread Starter atkulp

    (@atkulp)

    Well I think this is the problem then. That tables doesn’t exist in my database and it must be having a problem trying to create it. Perhaps if you give me the script I could manually create the table and see if that fixes it. It would be nice to know why it’s not creating though. I’m using a redirection plugin and I can see that it created its own tables.

    Plugin Author Shea Bunge

    (@bungeshea)

    That would definitely explain the saving error. Not sure why the table is not being created.

    You can find the SQL code under php/class-db.php:

    CREATE TABLE wp_snippets (
         id          BIGINT(20)  NOT NULL AUTO_INCREMENT,
         name        TINYTEXT    NOT NULL DEFAULT '',
         description TEXT        NOT NULL DEFAULT '',
         code        LONGTEXT    NOT NULL DEFAULT '',
         tags        LONGTEXT    NOT NULL DEFAULT '',
         scope       VARCHAR(15) NOT NULL DEFAULT 'global',
         priority    SMALLINT    NOT NULL DEFAULT 10,
         active      TINYINT(1)  NOT NULL DEFAULT 0,
         modified    DATETIME    NOT NULL DEFAULT '0000-00-00 00:00:00',
         PRIMARY KEY  (id),
         KEY scope (scope),
         KEY active (active)
    )

    Just replace wp_ with the appropriate table prefix if you are not using the default.

    Thread Starter atkulp

    (@atkulp)

    This CREATE TABLE does not run on my instance. It looks like it’s a known limitation, depending on flags settings/version.

    https://bugs.mysql.com/bug.php?id=21532

    Perhaps use a varchar instead?

    Relevant discussion on StackOverflow:
    https://stackoverflow.com/questions/1203710/which-datatype-is-better-to-use-text-or-varchar

    • This reply was modified 2 years, 8 months ago by atkulp.
    Thread Starter atkulp

    (@atkulp)

    Have you had a chance to look into this more?

    Plugin Author Shea Bunge

    (@bungeshea)

    Which version of MySQL are you using? I can certainly look into using a more compatible SQL syntax in the future if necessary.

    For the meantime, you can just modify the query I sent to work for your version, and the plugin should work fine.

    Plugin Author Shea Bunge

    (@bungeshea)

    I’ll be removing the DEFAULT constraint on *TEXT columns in the next release.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘“An error occurred when saving the snippet”’ is closed to new replies.