# blocks/trunk/src/Admin/TransferView.php

Blocks – Reusable Content, Shortcodes &amp; Site Variables, version trunk. 62 lines.

- Page: https://pluginprobe.com/plugins/blocks/trunk/code/src/Admin/TransferView.php
- Raw: https://pluginprobe.com/plugins/blocks/trunk/raw/src/Admin/TransferView.php
- Modified: 2026-07-13T20:34:48+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/blocks/trunk/code/src/Admin/TransferView.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace RenzoJohnson\Blocks\Admin;

\defined( 'ABSPATH' ) || exit;

final class TransferView {

	public function render(): void {
		// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only notice flags after a nonce-protected redirect.
		$imported     = isset( $_GET['imported'] );
		$import_error = isset( $_GET['import_error'] ) ? \sanitize_key( (string) \wp_unslash( $_GET['import_error'] ) ) : '';
		$created      = isset( $_GET['created'] ) ? \absint( $_GET['created'] ) : 0;
		$updated      = isset( $_GET['updated'] ) ? \absint( $_GET['updated'] ) : 0;
		$skipped      = isset( $_GET['skipped'] ) ? \absint( $_GET['skipped'] ) : 0;
		// phpcs:enable
		?>
		<div class="wrap">
			<h1><?php \esc_html_e( 'Import / Export', 'blocks' ); ?></h1>

			<?php if ( $imported ) : ?>
				<div class="notice notice-success is-dismissible"><p>
				<?php
				\printf(
					/* translators: 1: created count, 2: updated count, 3: skipped count. */
					\esc_html__( 'Import complete: %1$d created, %2$d updated, %3$d skipped.', 'blocks' ),
					\esc_html( (string) $created ),
					\esc_html( (string) $updated ),
					\esc_html( (string) $skipped ),
				);
				?>
				</p></div>
			<?php elseif ( '' !== $import_error ) : ?>
				<div class="notice notice-error is-dismissible"><p><?php echo 'nofile' === $import_error ? \esc_html__( 'No file was uploaded.', 'blocks' ) : \esc_html__( 'That file is not a valid Blocks export.', 'blocks' ); ?></p></div>
			<?php endif; ?>

			<h2><?php \esc_html_e( 'Export', 'blocks' ); ?></h2>
			<p class="description" style="max-width:640px;"><?php \esc_html_e( 'Download every block as a JSON file. Use it as a backup or to move blocks to another site.', 'blocks' ); ?></p>
			<form method="post" action="<?php echo \esc_url( \admin_url( 'admin-post.php' ) ); ?>">
				<?php \wp_nonce_field( 'blocks_export', 'blocks_export_nonce' ); ?>
				<input type="hidden" name="action" value="blocks_export">
				<?php \submit_button( \__( 'Download Export File', 'blocks' ), 'primary', 'submit', false ); ?>
			</form>

			<hr style="margin:2em 0;">

			<h2><?php \esc_html_e( 'Import', 'blocks' ); ?></h2>
			<p class="description" style="max-width:640px;"><?php \esc_html_e( 'Upload a Blocks export file. Blocks are matched by title and locale; existing matches are skipped unless you choose to overwrite them.', 'blocks' ); ?></p>
			<form method="post" action="<?php echo \esc_url( \admin_url( 'admin-post.php' ) ); ?>" enctype="multipart/form-data">
				<?php \wp_nonce_field( 'blocks_import', 'blocks_import_nonce' ); ?>
				<input type="hidden" name="action" value="blocks_import">
				<p><input type="file" name="blocks_import_file" accept=".json,application/json" required></p>
				<p><label><input type="checkbox" name="blocks_import_overwrite" value="1"> <?php \esc_html_e( 'Overwrite blocks that already exist (matched by title and locale)', 'blocks' ); ?></label></p>
				<?php \submit_button( \__( 'Import', 'blocks' ), 'primary', 'submit', false ); ?>
			</form>
		</div>
		<?php
	}
}

```
