From 6ff667190fdd4e247bcc9f1b2947f01fcd46885a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Tue, 9 Nov 2021 09:55:40 +0100 Subject: [PATCH 1/5] Use Gutenberg suffix to make it work with WordPress trunk --- lib/class-wp-theme-json-schema-v0.php | 6 +++--- lib/interface-wp-theme-json-schema.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/class-wp-theme-json-schema-v0.php b/lib/class-wp-theme-json-schema-v0.php index 30a0578178c7f5..19d0fb1359388e 100644 --- a/lib/class-wp-theme-json-schema-v0.php +++ b/lib/class-wp-theme-json-schema-v0.php @@ -1,16 +1,16 @@ Date: Tue, 9 Nov 2021 10:08:29 +0100 Subject: [PATCH 2/5] Use gutenberg suffix to make it work with WordPress trunk --- packages/block-library/src/calendar/index.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/calendar/index.php b/packages/block-library/src/calendar/index.php index 9f3f8c48d36679..b91b50a061b7ca 100644 --- a/packages/block-library/src/calendar/index.php +++ b/packages/block-library/src/calendar/index.php @@ -115,7 +115,7 @@ function block_core_calendar_update_has_published_posts() { * * @param int $post_id Deleted post ID. */ - function block_core_calendar_update_has_published_post_on_delete( $post_id ) { + function gutenberg_block_core_calendar_update_has_published_post_on_delete( $post_id ) { $post = get_post( $post_id ); if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) { @@ -132,7 +132,7 @@ function block_core_calendar_update_has_published_post_on_delete( $post_id ) { * @param string $old_status The status the post is changing from. * @param WP_Post $post Post object. */ - function block_core_calendar_update_has_published_post_on_transition_post_status( $new_status, $old_status, $post ) { + function gutenberg_block_core_calendar_update_has_published_post_on_transition_post_status( $new_status, $old_status, $post ) { if ( $new_status === $old_status ) { return; } @@ -148,6 +148,6 @@ function block_core_calendar_update_has_published_post_on_transition_post_status block_core_calendar_update_has_published_posts(); } - add_action( 'delete_post', 'block_core_calendar_update_has_published_post_on_delete' ); - add_action( 'transition_post_status', 'block_core_calendar_update_has_published_post_on_transition_post_status', 10, 3 ); + add_action( 'delete_post', 'gutenberg_block_core_calendar_update_has_published_post_on_delete' ); + add_action( 'transition_post_status', 'gutenberg_block_core_calendar_update_has_published_post_on_transition_post_status', 10, 3 ); } From 601a01250e0111527a88c68cfca0caec719f85ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Tue, 9 Nov 2021 12:24:56 +0100 Subject: [PATCH 3/5] Cover against function already present --- packages/block-library/src/calendar/index.php | 73 ++++++++++--------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/packages/block-library/src/calendar/index.php b/packages/block-library/src/calendar/index.php index b91b50a061b7ca..343996513ec195 100644 --- a/packages/block-library/src/calendar/index.php +++ b/packages/block-library/src/calendar/index.php @@ -110,44 +110,49 @@ function block_core_calendar_update_has_published_posts() { // We only want to register these functions and actions when // we are on single sites. On multi sites we use `post_count` option. if ( ! is_multisite() ) { - /** - * Handler for updating the has published posts flag when a post is deleted. - * - * @param int $post_id Deleted post ID. - */ - function gutenberg_block_core_calendar_update_has_published_post_on_delete( $post_id ) { - $post = get_post( $post_id ); - - if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) { - return; - } - - block_core_calendar_update_has_published_posts(); - } - /** - * Handler for updating the has published posts flag when a post status changes. - * - * @param string $new_status The status the post is changing to. - * @param string $old_status The status the post is changing from. - * @param WP_Post $post Post object. - */ - function gutenberg_block_core_calendar_update_has_published_post_on_transition_post_status( $new_status, $old_status, $post ) { - if ( $new_status === $old_status ) { - return; - } - - if ( 'post' !== get_post_type( $post ) ) { - return; + if ( ! function_exists( 'block_core_calendar_update_has_published_post_on_delete' ) ) { + /** + * Handler for updating the has published posts flag when a post is deleted. + * + * @param int $post_id Deleted post ID. + */ + function block_core_calendar_update_has_published_post_on_delete( $post_id ) { + $post = get_post( $post_id ); + + if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) { + return; + } + + block_core_calendar_update_has_published_posts(); } + } - if ( 'publish' !== $new_status && 'publish' !== $old_status ) { - return; + if ( ! function_exists( 'block_core_calendar_update_has_published_post_on_transition_post_status' ) ) { + /** + * Handler for updating the has published posts flag when a post status changes. + * + * @param string $new_status The status the post is changing to. + * @param string $old_status The status the post is changing from. + * @param WP_Post $post Post object. + */ + function block_core_calendar_update_has_published_post_on_transition_post_status( $new_status, $old_status, $post ) { + if ( $new_status === $old_status ) { + return; + } + + if ( 'post' !== get_post_type( $post ) ) { + return; + } + + if ( 'publish' !== $new_status && 'publish' !== $old_status ) { + return; + } + + block_core_calendar_update_has_published_posts(); } - - block_core_calendar_update_has_published_posts(); } - add_action( 'delete_post', 'gutenberg_block_core_calendar_update_has_published_post_on_delete' ); - add_action( 'transition_post_status', 'gutenberg_block_core_calendar_update_has_published_post_on_transition_post_status', 10, 3 ); + add_action( 'delete_post', 'block_core_calendar_update_has_published_post_on_delete' ); + add_action( 'transition_post_status', 'block_core_calendar_update_has_published_post_on_transition_post_status', 10, 3 ); } From 4c125afee0ba05e158850023c1e1b736e4bef004 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 9 Nov 2021 12:51:02 +0100 Subject: [PATCH 4/5] Fix calendar block code --- packages/block-library/src/calendar/index.php | 87 +++++++++---------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/packages/block-library/src/calendar/index.php b/packages/block-library/src/calendar/index.php index 343996513ec195..0fa03b413cf7e4 100644 --- a/packages/block-library/src/calendar/index.php +++ b/packages/block-library/src/calendar/index.php @@ -107,52 +107,51 @@ function block_core_calendar_update_has_published_posts() { return $has_published_posts; } -// We only want to register these functions and actions when -// we are on single sites. On multi sites we use `post_count` option. -if ( ! is_multisite() ) { - - if ( ! function_exists( 'block_core_calendar_update_has_published_post_on_delete' ) ) { - /** - * Handler for updating the has published posts flag when a post is deleted. - * - * @param int $post_id Deleted post ID. - */ - function block_core_calendar_update_has_published_post_on_delete( $post_id ) { - $post = get_post( $post_id ); - - if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) { - return; - } - - block_core_calendar_update_has_published_posts(); - } +/** + * Handler for updating the has published posts flag when a post is deleted. + * + * @param int $post_id Deleted post ID. + */ +function block_core_calendar_update_has_published_post_on_delete( $post_id ) { + if ( ! is_multisite() ) { + return; } - if ( ! function_exists( 'block_core_calendar_update_has_published_post_on_transition_post_status' ) ) { - /** - * Handler for updating the has published posts flag when a post status changes. - * - * @param string $new_status The status the post is changing to. - * @param string $old_status The status the post is changing from. - * @param WP_Post $post Post object. - */ - function block_core_calendar_update_has_published_post_on_transition_post_status( $new_status, $old_status, $post ) { - if ( $new_status === $old_status ) { - return; - } - - if ( 'post' !== get_post_type( $post ) ) { - return; - } - - if ( 'publish' !== $new_status && 'publish' !== $old_status ) { - return; - } - - block_core_calendar_update_has_published_posts(); - } + $post = get_post( $post_id ); + + if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) { + return; + } + + block_core_calendar_update_has_published_posts(); +} + +/** + * Handler for updating the has published posts flag when a post status changes. + * + * @param string $new_status The status the post is changing to. + * @param string $old_status The status the post is changing from. + * @param WP_Post $post Post object. + */ +function block_core_calendar_update_has_published_post_on_transition_post_status( $new_status, $old_status, $post ) { + if ( ! is_multisite() ) { + return; + } + + if ( $new_status === $old_status ) { + return; } - add_action( 'delete_post', 'block_core_calendar_update_has_published_post_on_delete' ); - add_action( 'transition_post_status', 'block_core_calendar_update_has_published_post_on_transition_post_status', 10, 3 ); + if ( 'post' !== get_post_type( $post ) ) { + return; + } + + if ( 'publish' !== $new_status && 'publish' !== $old_status ) { + return; + } + + block_core_calendar_update_has_published_posts(); } + +add_action( 'delete_post', 'block_core_calendar_update_has_published_post_on_delete' ); +add_action( 'transition_post_status', 'block_core_calendar_update_has_published_post_on_transition_post_status', 10, 3 ); From 102aea6de24cd14a431751df1f4e8e9e1f43e2f4 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 9 Nov 2021 12:55:10 +0100 Subject: [PATCH 5/5] Fix conditions --- packages/block-library/src/calendar/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/calendar/index.php b/packages/block-library/src/calendar/index.php index 0fa03b413cf7e4..28eba2afcd361b 100644 --- a/packages/block-library/src/calendar/index.php +++ b/packages/block-library/src/calendar/index.php @@ -113,7 +113,7 @@ function block_core_calendar_update_has_published_posts() { * @param int $post_id Deleted post ID. */ function block_core_calendar_update_has_published_post_on_delete( $post_id ) { - if ( ! is_multisite() ) { + if ( is_multisite() ) { return; } @@ -134,7 +134,7 @@ function block_core_calendar_update_has_published_post_on_delete( $post_id ) { * @param WP_Post $post Post object. */ function block_core_calendar_update_has_published_post_on_transition_post_status( $new_status, $old_status, $post ) { - if ( ! is_multisite() ) { + if ( is_multisite() ) { return; }