WordPress.org

Make WordPress Core

Ticket #53771: 53771.patch

File 53771.patch, 1.6 KB (added by imath, 3 months ago)
  • src/wp-includes/widgets.php

    diff --git src/wp-includes/widgets.php src/wp-includes/widgets.php
    index 61caf6af56..d722d03d0d 100644
    function wp_check_widget_editor_deps() { 
    20602060                }
    20612061        }
    20622062}
     2063
     2064/**
     2065 * Determines whether a Block Type has been added to one or more Sidebar Widgets.
     2066 *
     2067 * @since 5.8.?
     2068 *
     2069 * @param string $block_name    Optional. Block Type name (eg: `core/paragraph`).
     2070 *                              Optional, but needed for checking.
     2071 * @param bool   $skip_inactive Optional. Whether to check in 'wp_inactive_widgets'.
     2072 *                              Default true.
     2073 * @return bool True if the Block Type name to check has been added to one or more Sidebar Widgets.
     2074 *              False otherwise.
     2075 */
     2076function wp_widget_block_has( $block_name = '', $skip_inactive = true ) {
     2077        $widget_blocks = get_option( 'widget_block', array() );
     2078        $sidebars      = wp_get_sidebars_widgets();
     2079
     2080        if ( ! $widget_blocks || ! $sidebars ) {
     2081                return false;
     2082        }
     2083
     2084        // Neutralize inactive sidebar.
     2085        if ( $skip_inactive ) {
     2086                unset( $sidebars['wp_inactive_widgets'] );
     2087        }
     2088
     2089        $widgets_content = '';
     2090        foreach ( $widget_blocks as $key => $widget_block ) {
     2091                $widget_block_reference = 'block-' . $key;
     2092
     2093                if ( ! isset( $widget_block['content'] ) || ! $widget_block['content'] ) {
     2094                        continue;
     2095                }
     2096
     2097                foreach ( $sidebars as $sidebar ) {
     2098                        if ( is_array( $sidebar ) && in_array( $widget_block_reference, $sidebar, true ) ) {
     2099                                $widgets_content .= $widget_block['content'] . "\n";
     2100                        }
     2101                }
     2102        }
     2103
     2104        return has_block( $block_name, $widgets_content );
     2105}