Changeset 52161 for trunk/src/wp-includes/blocks/calendar.php
- Timestamp:
- 11/15/2021 12:47:22 PM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/calendar.php
r52042 r52161 108 108 } 109 109 110 // We only want to register these functions and actions when 111 // we are on single sites. On multi sites we use `post_count` option. 112 if ( ! is_multisite() ) { 113 /** 114 * Handler for updating the has published posts flag when a post is deleted. 115 * 116 * @param int $post_id Deleted post ID. 117 */ 118 function block_core_calendar_update_has_published_post_on_delete( $post_id ) { 119 $post = get_post( $post_id ); 120 121 if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) { 122 return; 123 } 124 125 block_core_calendar_update_has_published_posts(); 110 /** 111 * Handler for updating the has published posts flag when a post is deleted. 112 * 113 * @param int $post_id Deleted post ID. 114 */ 115 function block_core_calendar_update_has_published_post_on_delete( $post_id ) { 116 if ( is_multisite() ) { 117 return; 126 118 } 127 119 128 /** 129 * Handler for updating the has published posts flag when a post status changes. 130 * 131 * @param string $new_status The status the post is changing to. 132 * @param string $old_status The status the post is changing from. 133 * @param WP_Post $post Post object. 134 */ 135 function block_core_calendar_update_has_published_post_on_transition_post_status( $new_status, $old_status, $post ) { 136 if ( $new_status === $old_status ) { 137 return; 138 } 120 $post = get_post( $post_id ); 139 121 140 if ( 'post' !== get_post_type( $post ) ) { 141 return; 142 } 143 144 if ( 'publish' !== $new_status && 'publish' !== $old_status ) { 145 return; 146 } 147 148 block_core_calendar_update_has_published_posts(); 122 if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) { 123 return; 149 124 } 150 125 151 add_action( 'delete_post', 'block_core_calendar_update_has_published_post_on_delete' ); 152 add_action( 'transition_post_status', 'block_core_calendar_update_has_published_post_on_transition_post_status', 10, 3 ); 126 block_core_calendar_update_has_published_posts(); 153 127 } 128 129 /** 130 * Handler for updating the has published posts flag when a post status changes. 131 * 132 * @param string $new_status The status the post is changing to. 133 * @param string $old_status The status the post is changing from. 134 * @param WP_Post $post Post object. 135 */ 136 function block_core_calendar_update_has_published_post_on_transition_post_status( $new_status, $old_status, $post ) { 137 if ( is_multisite() ) { 138 return; 139 } 140 141 if ( $new_status === $old_status ) { 142 return; 143 } 144 145 if ( 'post' !== get_post_type( $post ) ) { 146 return; 147 } 148 149 if ( 'publish' !== $new_status && 'publish' !== $old_status ) { 150 return; 151 } 152 153 block_core_calendar_update_has_published_posts(); 154 } 155 156 add_action( 'delete_post', 'block_core_calendar_update_has_published_post_on_delete' ); 157 add_action( 'transition_post_status', 'block_core_calendar_update_has_published_post_on_transition_post_status', 10, 3 );
Note: See TracChangeset
for help on using the changeset viewer.