WP_Compat::using_block_function()
This function have to be called from a polyfill to map themes and plugins calling those functions.
Description
Make sure that class WP_Compat exists before calling the function because it’s not defined if Blocks Compatibility option is set to "off".
Return
(void)
Source
File: wp-includes/classicpress/class-wp-compat.php
public static function using_block_function() {
if ( 2 !== self::$blocks_compatibility_level ) {
return;
}
$trace = debug_backtrace();
/*
* Fires after WP_Compat::using_block_function() is called.
*
* @since: CP-2.0.0
*
* @param array $trace debug_backtrace() output
*/
do_action( 'using_block_function', $trace );
if ( str_starts_with( $trace[1]['file'], realpath( get_stylesheet_directory() ) ) ) {
// Current theme is calling the function
update_option( 'theme_using_blocks', '1' );
} elseif ( str_starts_with( $trace[1]['file'], realpath( get_template_directory() ) ) ) {
// Parent theme is calling the function
update_option( 'theme_using_blocks', '2' );
} else {
// A plugin is calling the function
$traces = array_column( $trace, 'file' );
$traces = array_map(
function ( $path ) {
return self::plugin_folder( $path );
},
$traces
);
$active = wp_get_active_and_valid_plugins();
$active = array_map(
function ( $path ) {
return self::plugin_folder( $path );
},
$active
);
$plugins = array_intersect( $traces, $active );
$plugin = array_pop( $plugins );
if ( null === $plugin ) {
// Nothing found? Bail.
return;
}
$plugins_using_blocks = get_option( 'plugins_using_blocks', array() );
if ( ! array_key_exists( plugin_basename( $plugin ), $plugins_using_blocks ) ) {
$plugins_using_blocks[ plugin_basename( $plugin ) ] = true;
update_option( 'plugins_using_blocks', $plugins_using_blocks );
}
}
}