# gutenberg/10.5.3/build/block-library/blocks/file.php

Gutenberg, version 10.5.3. 39 lines.

- Page: https://pluginprobe.com/plugins/gutenberg/10.5.3/code/build/block-library/blocks/file.php
- Raw: https://pluginprobe.com/plugins/gutenberg/10.5.3/raw/build/block-library/blocks/file.php
- Modified: 2021-04-28T21:13:32+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/gutenberg/10.5.3/code/build/block-library/blocks/file.php#L10-L20`.

```php
<?php
/**
 * Server-side rendering of the `core/file` block.
 *
 * @package WordPress
 */

/**
 * When the `core/file` block is rendering, check if we need to enqueue the `'wp-block-library-file` script.
 *
 * @param array $attributes The block attributes.
 * @param array $content    The block content.
 *
 * @return string Returns the block content.
 */
function gutenberg_render_block_core_file( $attributes, $content ) {
	if ( ! empty( $attributes['displayPreview'] ) ) {
		// Check if it's already enqueued, so we don't add the inline script multiple times.
		if ( ! wp_script_is( 'wp-block-library-file' ) ) {
			wp_enqueue_script( 'wp-block-library-file', plugins_url( 'file/frontend.js', __FILE__ ) );
		}
	}

	return $content;
}

/**
 * Registers the `core/file` block on server.
 */
function gutenberg_register_block_core_file() {
	register_block_type_from_metadata(
		__DIR__ . '/file',
		array(
			'render_callback' => 'gutenberg_render_block_core_file',
		)
	);
}
add_action( 'init', 'gutenberg_register_block_core_file', 20 );

```
