From 84d19848666a81584e0007a6ab7f7ad3c990d71a Mon Sep 17 00:00:00 2001 From: audrasjb Date: Tue, 20 Sep 2022 15:44:38 +0000 Subject: [PATCH] Cron API: Add error logging and hooks to `wp-cron.php`. This changeset adds error logging on `wp_reschedule_event()` and `wp_unschedule_event` in `wp-cron.php`. This allows proper error logging when random errors appear. It also introduces `cron_reschedule_event_error` and `cron_unschedule_event_error` hooks which can be used to trigger additional behaviors when an error occurs. Props Enchiridion, johnbillion, costdev. Fixes #56048. Built from https://develop.svn.wordpress.org/trunk@54258 git-svn-id: http://core.svn.wordpress.org/trunk@53817 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-cron.php | 52 ++++++++++++++++++++++++++++++++++-- wp-includes/blocks/cover.php | 18 ++++++++++--- wp-includes/version.php | 2 +- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/wp-cron.php b/wp-cron.php index ceaf5d1e65..164e4ef191 100644 --- a/wp-cron.php +++ b/wp-cron.php @@ -123,10 +123,58 @@ foreach ( $crons as $timestamp => $cronhooks ) { $schedule = $v['schedule']; if ( $schedule ) { - wp_reschedule_event( $timestamp, $schedule, $hook, $v['args'] ); + $result = wp_reschedule_event( $timestamp, $schedule, $hook, $v['args'], true ); + + if ( is_wp_error( $result ) ) { + error_log( + sprintf( + /* translators: 1: Hook name, 2: Error code, 3: Error message, 4: Event data. */ + __( 'Cron reschedule event error for hook: %1$s, Error code: %2$s, Error message: %3$s, Data: %4$s' ), + $hook, + $result->get_error_code(), + $result->get_error_message(), + wp_json_encode( $v ) + ) + ); + + /** + * Fires when an error happens rescheduling a cron event. + * + * @since 6.1.0 + * + * @param WP_Error $result The WP_Error object. + * @param string $hook Action hook to execute when the event is run. + * @param array $v Event data. + */ + do_action( 'cron_reschedule_event_error', $result, $hook, $v ); + } } - wp_unschedule_event( $timestamp, $hook, $v['args'] ); + $result = wp_unschedule_event( $timestamp, $hook, $v['args'], true ); + + if ( is_wp_error( $result ) ) { + error_log( + sprintf( + /* translators: 1: Hook name, 2: Error code, 3: Error message, 4: Event data. */ + __( 'Cron unschedule event error for hook: %1$s, Error code: %2$s, Error message: %3$s, Data: %4$s' ), + $hook, + $result->get_error_code(), + $result->get_error_message(), + wp_json_encode( $v ) + ) + ); + + /** + * Fires when an error happens unscheduling a cron event. + * + * @since 6.1.0 + * + * @param WP_Error $result The WP_Error object. + * @param string $hook Action hook to execute when the event is run. + * @param array $v Event data. + */ + do_action( 'cron_unschedule_event_error', $result, $hook, $v ); + } /** * Fires scheduled events. diff --git a/wp-includes/blocks/cover.php b/wp-includes/blocks/cover.php index 9e14791ba8..4168d26767 100644 --- a/wp-includes/blocks/cover.php +++ b/wp-includes/blocks/cover.php @@ -8,8 +8,8 @@ /** * Renders the `core/cover` block on server. * - * @param array $attributes The block attributes. - * @param array $content The block rendered content. + * @param array $attributes The block attributes. + * @param string $content The block rendered content. * * @return string Returns the cover block markup, if useFeaturedImage is true. */ @@ -46,9 +46,19 @@ function render_block_core_cover( $attributes, $content ) { update_post_thumbnail_cache(); } $current_featured_image = get_the_post_thumbnail_url(); - $content = preg_replace( + + $styles = 'background-image:url(' . esc_url( $current_featured_image ) . '); '; + + if ( isset( $attributes['minHeight'] ) ) { + $height_unit = empty( $attributes['minHeightUnit'] ) ? 'px' : $attributes['minHeightUnit']; + $height = " min-height:{$attributes['minHeight']}{$height_unit}"; + + $styles .= $height; + } + + $content = preg_replace( '/class=\".*?\"/', - '${0} style="background-image:url(' . esc_url( $current_featured_image ) . ')"', + '${0} style="' . $styles . '"', $content, 1 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index bf8aab806d..b46be7c718 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-54257'; +$wp_version = '6.1-alpha-54258'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.