• Resolved truxton

    (@truxton)


    Hi,

    I want to ask if there’s a hook in which I can get code snippet’s information(id, title, content, etc) every time I do a “save” action. I want to save a duplicate(e.g. in log file or in a mysql table) for every saving code snippet, so that I don’t need a version control system.

    Or if there’s not such a hook, could you please tell me where I can write my code in this plugin’s directory?

    Thanks,
    Truxton

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

    (@bungeshea)

    Absolutely! There are two hooks for this purpose: the first is the code_snippets/create_snippet action. It runs just after a new snippet has been created and saved to the database, and provides the snippet ID (integer) as the first parameter, and the table name (string) as the second. You can find it in php/snippet-ops.php:

    do_action( 'code_snippets/create_snippet', $snippet->id, $table );

    The second hook is code_snippets/update_snippet. It runs just after an existing snippet data is updated in the database, and provides the same parameters as the other action. It can also be found in the same file.

    do_action( 'code_snippets/update_snippet', $snippet->id, $table );

    Hopefully these hooks fulfill your needs! If not, let us know; we’d be happy to add extra API where it would be useful if it is lacking in some areas.

    Also, I’d be very interested in seeing what you come up with if you’re comfortable with sharing. Please keep me in the loop!

    Thread Starter truxton

    (@truxton)

    Thank you so much for your help and hook API. I create a hook function to capture every saving snippet’s data and insert it into another MySQL table so that I can easily backtrack code snippets’ revisions whenever I encounter troubles. Actually, I hope this can be a future feature of this plugin because sometimes it’s common to wrongly modify snippets (or unsuccessfully add new functions), and we need to restore the older snippets. Of course, this will lead to extra disk space (like WordPress’s post revisions), but I think it’s worth it.

    • This reply was modified 2 years, 12 months ago by truxton.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Is there a wp hook for each saving action?’ is closed to new replies.