From 6e8bb9df358c3300fcb7f02cf6e4d88854cd2728 Mon Sep 17 00:00:00 2001 From: David Szabo Date: Mon, 16 Nov 2020 18:14:50 +0100 Subject: [PATCH] Clear last checks option after trashing or deleting templates and template parts --- lib/templates-sync.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/templates-sync.php b/lib/templates-sync.php index 7c46c651453c2..a780f2fc63d36 100644 --- a/lib/templates-sync.php +++ b/lib/templates-sync.php @@ -147,3 +147,28 @@ function gutenberg_synchronize_theme_templates_on_load() { _gutenberg_synchronize_theme_templates( 'template' ); } add_action( 'wp_loaded', 'gutenberg_synchronize_theme_templates_on_load' ); + +/** + * Clears synchronization last check timestamps. + */ +function gutenberg_clear_synchronize_last_checks() { + update_option( 'gutenberg_last_synchronize_theme_template_checks', array() ); + update_option( 'gutenberg_last_synchronize_theme_template-part_checks', array() ); +} + +// Clear synchronization last check timestamps after trashing a template or template part. +add_action( 'trash_wp_template', 'gutenberg_clear_synchronize_last_checks' ); +add_action( 'trash_wp_template_part', 'gutenberg_clear_synchronize_last_checks' ); + +/** + * Clear synchronization last check timestamps after deleting a template or template part. + * + * @param int $post_id ID of the deleted post. + * @param WP_Post $post WP_Post instance of the deleted post. + */ +function gutenberg_clear_synchronize_last_checks_after_delete( $postid, $post ) { + if ( 'wp_template' !== $post->post_type || 'wp_template_part' !== $post->post_type ) { + gutenberg_clear_synchronize_last_checks(); + } +} +add_action( 'after_delete_post', 'gutenberg_clear_synchronize_last_checks_after_delete' );