breznflow/includes/Admin/views/themes.php
Michael c891e68b16 Fix Plugin Check warnings: remove load_plugin_textdomain, prefix global variables
- Remove deprecated load_plugin_textdomain() call (auto-loaded since WP 4.6)
- Prefix all global variables in themes.php with breznflow_ for WPCS compliance

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-30 15:12:59 +00:00

148 lines
5.4 KiB
PHP

<?php
/**
* Template: Theme management page.
*
* @package BreznFlow
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use BreznFlow\Features\ThemeImporter;
use BreznFlow\Features\ThemeRegistry;
$breznflow_custom_themes = ThemeImporter::get_all();
?>
<div class="wrap breznflow-admin-wrap">
<h1><?php esc_html_e( 'BreznFlow — Themes', 'breznflow' ); ?></h1>
<?php if ( isset( $_GET['imported'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
<div class="notice notice-success is-dismissible">
<p><?php esc_html_e( 'Theme imported successfully.', 'breznflow' ); ?></p>
</div>
<?php endif; ?>
<?php if ( isset( $_GET['deleted'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
<div class="notice notice-success is-dismissible">
<p><?php esc_html_e( 'Theme deleted.', 'breznflow' ); ?></p>
</div>
<?php endif; ?>
<?php if ( isset( $_GET['error'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
<?php
$breznflow_error_code = sanitize_key( $_GET['error'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$breznflow_messages = array(
'invalid_file' => __( 'Invalid file type. Please upload a .breznflow.json file.', 'breznflow' ),
'upload_failed' => __( 'File upload failed. Please try again.', 'breznflow' ),
'read_failed' => __( 'Could not read the uploaded file.', 'breznflow' ),
'invalid_json' => __( 'File is not valid JSON.', 'breznflow' ),
'validation' => isset( $_GET['message'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
? urldecode( sanitize_text_field( wp_unslash( $_GET['message'] ) ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
: __( 'Theme validation failed.', 'breznflow' ),
);
$breznflow_msg = $breznflow_messages[ $breznflow_error_code ] ?? __( 'An error occurred.', 'breznflow' );
?>
<div class="notice notice-error is-dismissible">
<p><?php echo esc_html( $breznflow_msg ); ?></p>
</div>
<?php endif; ?>
<!-- Import Section -->
<div class="breznflow-card">
<h2><?php esc_html_e( 'Import Custom Theme', 'breznflow' ); ?></h2>
<p class="description">
<?php esc_html_e( 'Upload a .breznflow.json file containing a valid theme definition. The file must include all 41 color tokens.', 'breznflow' ); ?>
</p>
<form method="post" enctype="multipart/form-data" action="<?php echo esc_url( admin_url( 'admin.php?page=breznflow-themes' ) ); ?>">
<?php wp_nonce_field( 'breznflow_theme_import' ); ?>
<table class="form-table">
<tr>
<th><label for="breznflow_theme_file"><?php esc_html_e( 'Theme File', 'breznflow' ); ?></label></th>
<td>
<input type="file" name="breznflow_theme_file" id="breznflow_theme_file" accept=".json,.breznflow.json">
</td>
</tr>
</table>
<?php submit_button( __( 'Import Theme', 'breznflow' ) ); ?>
</form>
</div>
<!-- Built-in Themes -->
<div class="breznflow-card">
<h2><?php esc_html_e( 'Built-in Themes', 'breznflow' ); ?></h2>
<table class="wp-list-table widefat striped">
<thead>
<tr>
<th><?php esc_html_e( 'Name', 'breznflow' ); ?></th>
<th><?php esc_html_e( 'ID', 'breznflow' ); ?></th>
<th><?php esc_html_e( 'Type', 'breznflow' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( ThemeRegistry::BUILTIN as $breznflow_theme_id => $breznflow_theme_name ) : ?>
<tr>
<td><?php echo esc_html( $breznflow_theme_name ); ?></td>
<td><code><?php echo esc_html( $breznflow_theme_id ); ?></code></td>
<td><?php esc_html_e( 'Built-in', 'breznflow' ); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<p class="description">
<?php esc_html_e( 'Built-in themes are read-only and updated with the plugin.', 'breznflow' ); ?>
</p>
</div>
<!-- Custom Themes -->
<div class="breznflow-card">
<h2><?php esc_html_e( 'Custom Themes', 'breznflow' ); ?></h2>
<?php if ( empty( $breznflow_custom_themes ) ) : ?>
<p class="description"><?php esc_html_e( 'No custom themes imported yet.', 'breznflow' ); ?></p>
<?php else : ?>
<table class="wp-list-table widefat striped">
<thead>
<tr>
<th><?php esc_html_e( 'Name', 'breznflow' ); ?></th>
<th><?php esc_html_e( 'ID', 'breznflow' ); ?></th>
<th><?php esc_html_e( 'Version', 'breznflow' ); ?></th>
<th><?php esc_html_e( 'Actions', 'breznflow' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( $breznflow_custom_themes as $breznflow_theme ) : ?>
<tr>
<td><?php echo esc_html( $breznflow_theme['name'] ); ?></td>
<td><code><?php echo esc_html( $breznflow_theme['id'] ); ?></code></td>
<td><?php echo esc_html( (string) $breznflow_theme['version'] ); ?></td>
<td>
<a href="
<?php
echo esc_url(
wp_nonce_url(
add_query_arg(
array(
'page' => 'breznflow-themes',
'action' => 'delete_theme',
'theme_id' => $breznflow_theme['id'],
),
admin_url( 'admin.php' )
),
'breznflow_theme_delete_' . $breznflow_theme['id']
)
);
?>
"
onclick="return confirm('<?php echo esc_js( __( 'Delete this theme?', 'breznflow' ) ); ?>');"
class="submitdelete">
<?php esc_html_e( 'Delete', 'breznflow' ); ?>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</div>