--- a/wp/wp-includes/blocks/site-logo.php Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-includes/blocks/site-logo.php Tue Sep 27 16:37:53 2022 +0200
@@ -14,7 +14,7 @@
*/
function render_block_core_site_logo( $attributes ) {
$adjust_width_height_filter = function ( $image ) use ( $attributes ) {
- if ( empty( $attributes['width'] ) || empty( $image ) ) {
+ if ( empty( $attributes['width'] ) || empty( $image ) || ! $image[1] || ! $image[2] ) {
return $image;
}
$height = (float) $attributes['width'] / ( (float) $image[1] / (float) $image[2] );
@@ -40,18 +40,10 @@
// Add the link target after the rel="home".
// Add an aria-label for informing that the page opens in a new tab.
$aria_label = 'aria-label="' . esc_attr__( '(Home link, opens in a new tab)' ) . '"';
- $custom_logo = str_replace( 'rel="home"', 'rel="home" target="' . $attributes['linkTarget'] . '"' . $aria_label, $custom_logo );
+ $custom_logo = str_replace( 'rel="home"', 'rel="home" target="' . esc_attr( $attributes['linkTarget'] ) . '"' . $aria_label, $custom_logo );
}
$classnames = array();
- if ( ! empty( $attributes['className'] ) ) {
- $classnames[] = $attributes['className'];
- }
-
- if ( ! empty( $attributes['align'] ) && in_array( $attributes['align'], array( 'center', 'left', 'right' ), true ) ) {
- $classnames[] = "align{$attributes['align']}";
- }
-
if ( empty( $attributes['width'] ) ) {
$classnames[] = 'is-default-size';
}
@@ -81,6 +73,23 @@
add_action( 'rest_api_init', 'register_block_core_site_logo_setting', 10 );
/**
+ * Register a core site setting for a site icon
+ */
+function register_block_core_site_icon_setting() {
+ register_setting(
+ 'general',
+ 'site_icon',
+ array(
+ 'show_in_rest' => true,
+ 'type' => 'integer',
+ 'description' => __( 'Site icon.' ),
+ )
+ );
+}
+
+add_action( 'rest_api_init', 'register_block_core_site_icon_setting', 10 );
+
+/**
* Registers the `core/site-logo` block on the server.
*/
function register_block_core_site_logo() {
@@ -133,6 +142,12 @@
* @param array $value Updated theme mod settings.
*/
function _delete_site_logo_on_remove_custom_logo( $old_value, $value ) {
+ global $_ignore_site_logo_changes;
+
+ if ( $_ignore_site_logo_changes ) {
+ return;
+ }
+
// If the custom_logo is being unset, it's being removed from theme mods.
if ( isset( $old_value['custom_logo'] ) && ! isset( $value['custom_logo'] ) ) {
delete_option( 'site_logo' );
@@ -143,6 +158,12 @@
* Deletes the site logo when all theme mods are being removed.
*/
function _delete_site_logo_on_remove_theme_mods() {
+ global $_ignore_site_logo_changes;
+
+ if ( $_ignore_site_logo_changes ) {
+ return;
+ }
+
if ( false !== get_theme_support( 'custom-logo' ) ) {
delete_option( 'site_logo' );
}
@@ -160,3 +181,21 @@
add_action( "delete_option_theme_mods_$theme", '_delete_site_logo_on_remove_theme_mods' );
}
add_action( 'setup_theme', '_delete_site_logo_on_remove_custom_logo_on_setup_theme', 11 );
+
+/**
+ * Removes the custom_logo theme-mod when the site_logo option gets deleted.
+ */
+function _delete_custom_logo_on_remove_site_logo() {
+ global $_ignore_site_logo_changes;
+
+ // Prevent _delete_site_logo_on_remove_custom_logo and
+ // _delete_site_logo_on_remove_theme_mods from firing and causing an
+ // infinite loop.
+ $_ignore_site_logo_changes = true;
+
+ // Remove the custom logo.
+ remove_theme_mod( 'custom_logo' );
+
+ $_ignore_site_logo_changes = false;
+}
+add_action( 'delete_option_site_logo', '_delete_custom_logo_on_remove_site_logo' );