Skip to content

Commit

Permalink
Fix Gutenberg 11.8.2 in WordPress trunk (#36347)
Browse files Browse the repository at this point in the history
Co-authored-by: Riad Benguella <[email protected]>
  • Loading branch information
oandregal and youknowriad authored Nov 9, 2021
1 parent aa0ef03 commit e9c3607
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 39 deletions.
6 changes: 3 additions & 3 deletions lib/class-wp-theme-json-schema-v0.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
/**
* Class that implements a WP_Theme_JSON_Schema to convert
* Class that implements a WP_Theme_JSON_Schema_Gutenberg to convert
* a given structure in v0 schema to the latest one.
*
* @package gutenberg
*/

/**
* Class that implements a WP_Theme_JSON_Schema to convert
* Class that implements a WP_Theme_JSON_Schema_Gutenberg to convert
* a given structure in v0 schema to the latest one.
*/
class WP_Theme_JSON_Schema_V0 implements WP_Theme_JSON_Schema {
class WP_Theme_JSON_Schema_V0 implements WP_Theme_JSON_Schema_Gutenberg {

/**
* How to address all the blocks
Expand Down
2 changes: 1 addition & 1 deletion lib/interface-wp-theme-json-schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @package gutenberg
*/
interface WP_Theme_JSON_Schema {
interface WP_Theme_JSON_Schema_Gutenberg {
/**
* Parses an array that follows an old theme.json schema
* into the latest theme.json schema.
Expand Down
74 changes: 39 additions & 35 deletions packages/block-library/src/calendar/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,47 +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() ) {
/**
* 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;
}
/**
* 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;
}

$post = get_post( $post_id );

block_core_calendar_update_has_published_posts();
if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) {
return;
}

/**
* 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;
}
block_core_calendar_update_has_published_posts();
}

if ( 'post' !== get_post_type( $post ) ) {
return;
}
/**
* 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 ( 'publish' !== $new_status && 'publish' !== $old_status ) {
return;
}
if ( $new_status === $old_status ) {
return;
}

block_core_calendar_update_has_published_posts();
if ( 'post' !== get_post_type( $post ) ) {
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 ( '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 );

0 comments on commit e9c3607

Please sign in to comment.