Disabling block.json supports programatically - markhowellsmead/helpers GitHub Wiki

Disable custom CSS field (WordPress 7.0)

Hook to register_block_type_args.

/**
 * Modify all block.json settings.
 * Ensure every block's attributes include `customCSS` set to false by default. Coming in WP 7.0.
 *
 * @param array $args Block registration args
 * @return array
 */
public function globalModifyBlockJson($args): array
{
	if (!isset($args['attributes']) || !is_array($args['attributes'])) {
		$args['attributes'] = [
			'customCSS' => [
				'type' => 'boolean',
				'default' => false,
			],
		];
		return $args;
	}

	// If attribute doesn't exist, add it. If it exists, force default to false.
	if (!isset($args['attributes']['customCSS'])) {
		$args['attributes']['customCSS'] = [
			'type' => 'boolean',
			'default' => false,
		];
	} else {
		if (is_array($args['attributes']['customCSS'])) {
			$args['attributes']['customCSS']['default'] = false;
		}
	}

	return $args;
}