| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace RenzoJohnson\Blocks\Admin; |
| 6 |
|
| 7 |
\defined( 'ABSPATH' ) || exit; |
| 8 |
|
| 9 |
final class TransferView { |
| 10 |
|
| 11 |
public function render(): void { |
| 12 |
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only notice flags after a nonce-protected redirect. |
| 13 |
$imported = isset( $_GET['imported'] ); |
| 14 |
$import_error = isset( $_GET['import_error'] ) ? \sanitize_key( (string) \wp_unslash( $_GET['import_error'] ) ) : ''; |
| 15 |
$created = isset( $_GET['created'] ) ? \absint( $_GET['created'] ) : 0; |
| 16 |
$updated = isset( $_GET['updated'] ) ? \absint( $_GET['updated'] ) : 0; |
| 17 |
$skipped = isset( $_GET['skipped'] ) ? \absint( $_GET['skipped'] ) : 0; |
| 18 |
// phpcs:enable |
| 19 |
?> |
| 20 |
<div class="wrap"> |
| 21 |
<h1><?php \esc_html_e( 'Import / Export', 'blocks' ); ?></h1> |
| 22 |
|
| 23 |
<?php if ( $imported ) : ?> |
| 24 |
<div class="notice notice-success is-dismissible"><p> |
| 25 |
<?php |
| 26 |
\printf( |
| 27 |
/* translators: 1: created count, 2: updated count, 3: skipped count. */ |
| 28 |
\esc_html__( 'Import complete: %1$d created, %2$d updated, %3$d skipped.', 'blocks' ), |
| 29 |
\esc_html( (string) $created ), |
| 30 |
\esc_html( (string) $updated ), |
| 31 |
\esc_html( (string) $skipped ), |
| 32 |
); |
| 33 |
?> |
| 34 |
</p></div> |
| 35 |
<?php elseif ( '' !== $import_error ) : ?> |
| 36 |
<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> |
| 37 |
<?php endif; ?> |
| 38 |
|
| 39 |
<h2><?php \esc_html_e( 'Export', 'blocks' ); ?></h2> |
| 40 |
<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> |
| 41 |
<form method="post" action="<?php echo \esc_url( \admin_url( 'admin-post.php' ) ); ?>"> |
| 42 |
<?php \wp_nonce_field( 'blocks_export', 'blocks_export_nonce' ); ?> |
| 43 |
<input type="hidden" name="action" value="blocks_export"> |
| 44 |
<?php \submit_button( \__( 'Download Export File', 'blocks' ), 'primary', 'submit', false ); ?> |
| 45 |
</form> |
| 46 |
|
| 47 |
<hr style="margin:2em 0;"> |
| 48 |
|
| 49 |
<h2><?php \esc_html_e( 'Import', 'blocks' ); ?></h2> |
| 50 |
<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> |
| 51 |
<form method="post" action="<?php echo \esc_url( \admin_url( 'admin-post.php' ) ); ?>" enctype="multipart/form-data"> |
| 52 |
<?php \wp_nonce_field( 'blocks_import', 'blocks_import_nonce' ); ?> |
| 53 |
<input type="hidden" name="action" value="blocks_import"> |
| 54 |
<p><input type="file" name="blocks_import_file" accept=".json,application/json" required></p> |
| 55 |
<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> |
| 56 |
<?php \submit_button( \__( 'Import', 'blocks' ), 'primary', 'submit', false ); ?> |
| 57 |
</form> |
| 58 |
</div> |
| 59 |
<?php |
| 60 |
} |
| 61 |
} |
| 62 |
|