Documentation

apply_filters("whereused_ignored_blocks", array $ignored_blocks)

Details

  • whereused_ignored_blocks
  • filter hook
  • Active
  • 1.1.0
  • Whereused/ignored_blocks

Description

WhereUsed will tell you where a block is used throughout the site. This is helpful as you may want to know where a particular block is used before you remove a plugin. Sometimes, these references are so abundant that you may not want to know where you a particular block is being used. This filter tells the scan to ignore these blocks from the references table when a scan is performed.

Blocks Excluded From References Table:

  • core/paragraph
  • core/heading

If you decide to modify the ignored blocks, you will need to conduct a full scan afterward to see the effects of this modifcation.

Parameters

$ignored_blocks array
Array of blocks

Adding An Ignored Block Example Code:

In the code below, we want to add a key of “core/audio” to the array to identify it as a block we do not want to scan.

/**
 * Do not detect the core/audio block on a full scan
 *
 * @link  https://whereused.com/docs/hooks/whereused_ignored_blocks/
 *
 * @return array
 */
function custom_add_whereused_ignored_block(array $ignored_blocks): array {

	// The name of the block is the key of the array
	$ignored_blocks['core/audio'] = true;

	return $ignored_blocks;
}

add_filter('whereused_ignored_blocks', 'custom_add_whereused_ignored_block', 10, 1);

Removing An Ignored Block Example Code:

The core/heading block is ignored or not scanned by default. If we wanted to include it in our scan, we would remove it from the array as shown below.

/**
 * Detect the core/heading block on a full scan
 *
 * @link  https://whereused.com/docs/hooks/whereused_ignored_blocks/
 *
 * @return array
 */
function custom_remove_whereused_ignored_blocks(array $ignored_blocks): array {

	// Remove heading block from the array
	unset($ignored_blocks['core/heading']);

	return $ignored_blocks;
}

add_filter('whereused_ignored_blocks', 'custom_remove_whereused_ignored_blocks', 10, 

Filter context within the plugin’s code:

/**
 * The blocks that are not scanned
 *
 * @package WhereUsed
 * @since   1.0.0
 * @link    https://whereused.com/docs/hooks/whereused_ignored_blocks/
 *
 * @return array
 */
public static function ignored_blocks(): array {

	$ignored_blocks = [
		'core/paragraph' => true,
		'core/heading' => true,
	];

	return apply_filters( 'whereused_ignored_blocks', $ignored_blocks );
}1);

If you notice any incorrect or missing information on this page, please let us know.