diff --git a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php index 8556a0be1663f..1a81652c29fe0 100644 --- a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php +++ b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php @@ -48,6 +48,35 @@ function wp_theme_has_theme_json() { } } +if ( ! function_exists( 'wp_theme_get_css_selector_for_block' ) ) { + /** + * Lookup a CSS selector for the block provided, and return it if it exists. + * + * @param string $block_name The name of the block to lookup the CSS selector for. + * + * @return string|null the CSS selector for the block. + */ + function wp_theme_get_css_selector_for_block( $block_name ) { + $registry = WP_Block_Type_Registry::get_instance(); + $blocks = $registry->get_all_registered(); + + if ( isset( $blocks[ $block_name ] ) ) { + $block = $blocks[ $block_name ]; + if ( + isset( $block->supports['__experimentalSelector'] ) && + is_string( $block->supports['__experimentalSelector'] ) + ) { + return $block->supports['__experimentalSelector']; + } else { + return '.wp-block-' . str_replace( '/', '-', str_replace( 'core/', '', $block_name ) ); + } + } + + // Selector for the block was not found. + return null; + } +} + if ( ! function_exists( 'wp_theme_has_theme_json_clean_cache' ) ) { /** * Function to clean the cache used by wp_theme_has_theme_json method.