224 lines
7.6 KiB
PHP
224 lines
7.6 KiB
PHP
<?php
|
|
/**
|
|
* Admin Page class - Handles the settings page.
|
|
*
|
|
* @package MapleIcons
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Class MI_Admin_Page
|
|
*
|
|
* Handles the plugin settings page in WordPress admin.
|
|
*/
|
|
class MI_Admin_Page {
|
|
|
|
/**
|
|
* Constructor - Register admin hooks.
|
|
*/
|
|
public function __construct() {
|
|
add_action( 'admin_menu', array( $this, 'register_menu' ) );
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
|
|
}
|
|
|
|
/**
|
|
* Register the admin menu item.
|
|
*/
|
|
public function register_menu() {
|
|
add_options_page(
|
|
__( 'Maple Icons', 'maple-icons' ),
|
|
__( 'Maple Icons', 'maple-icons' ),
|
|
'manage_options',
|
|
'maple-icons',
|
|
array( $this, 'render_page' )
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Enqueue admin assets.
|
|
*
|
|
* @param string $hook_suffix The current admin page.
|
|
*/
|
|
public function enqueue_assets( $hook_suffix ) {
|
|
if ( 'settings_page_maple-icons' !== $hook_suffix ) {
|
|
return;
|
|
}
|
|
|
|
wp_enqueue_style(
|
|
'mi-admin',
|
|
MI_PLUGIN_URL . 'assets/admin.css',
|
|
array(),
|
|
MI_VERSION
|
|
);
|
|
|
|
wp_enqueue_script(
|
|
'mi-admin',
|
|
MI_PLUGIN_URL . 'assets/admin.js',
|
|
array( 'jquery' ),
|
|
MI_VERSION,
|
|
true
|
|
);
|
|
|
|
wp_localize_script(
|
|
'mi-admin',
|
|
'miAdmin',
|
|
array(
|
|
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
|
'nonce' => wp_create_nonce( 'mi_admin_nonce' ),
|
|
'strings' => array(
|
|
'downloading' => __( 'Downloading...', 'maple-icons' ),
|
|
'deleting' => __( 'Deleting...', 'maple-icons' ),
|
|
'activating' => __( 'Activating...', 'maple-icons' ),
|
|
'confirmDelete' => __( 'Are you sure you want to delete this icon set?', 'maple-icons' ),
|
|
'downloadError' => __( 'Download failed. Please try again.', 'maple-icons' ),
|
|
'deleteError' => __( 'Delete failed. Please try again.', 'maple-icons' ),
|
|
'activateError' => __( 'Activation failed. Please try again.', 'maple-icons' ),
|
|
'downloadSuccess'=> __( 'Icon set downloaded successfully!', 'maple-icons' ),
|
|
'deleteSuccess' => __( 'Icon set deleted successfully!', 'maple-icons' ),
|
|
'activateSuccess'=> __( 'Icon set activated!', 'maple-icons' ),
|
|
),
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Render the settings page.
|
|
*/
|
|
public function render_page() {
|
|
if ( ! current_user_can( 'manage_options' ) ) {
|
|
return;
|
|
}
|
|
|
|
$registry = MI_Icon_Registry::get_instance();
|
|
$all_sets = MI_Icon_Sets::get_all();
|
|
$downloaded = $registry->get_downloaded_sets();
|
|
$active_set = $registry->get_active_set();
|
|
|
|
?>
|
|
<div class="wrap mi-admin-wrap">
|
|
<h1><?php esc_html_e( 'Maple Icons', 'maple-icons' ); ?></h1>
|
|
|
|
<div class="mi-admin-intro">
|
|
<p><?php esc_html_e( 'Download icon sets from CDN and use them in the Gutenberg block editor. Only one icon set can be active at a time.', 'maple-icons' ); ?></p>
|
|
</div>
|
|
|
|
<div class="mi-icon-sets">
|
|
<h2><?php esc_html_e( 'Available Icon Sets', 'maple-icons' ); ?></h2>
|
|
|
|
<div class="mi-sets-grid">
|
|
<?php foreach ( $all_sets as $slug => $set ) : ?>
|
|
<?php
|
|
$is_downloaded = isset( $downloaded[ $slug ] );
|
|
$is_active = $active_set === $slug;
|
|
$icon_count = $is_downloaded ? $downloaded[ $slug ]['icon_count'] : 0;
|
|
$download_date = $is_downloaded ? $downloaded[ $slug ]['downloaded_at'] : '';
|
|
?>
|
|
<div class="mi-set-card <?php echo $is_active ? 'mi-set-active' : ''; ?> <?php echo $is_downloaded ? 'mi-set-downloaded' : ''; ?>" data-slug="<?php echo esc_attr( $slug ); ?>">
|
|
<div class="mi-set-header">
|
|
<h3 class="mi-set-name"><?php echo esc_html( $set['name'] ); ?></h3>
|
|
<?php if ( $is_active ) : ?>
|
|
<span class="mi-badge mi-badge-active"><?php esc_html_e( 'Active', 'maple-icons' ); ?></span>
|
|
<?php elseif ( $is_downloaded ) : ?>
|
|
<span class="mi-badge mi-badge-downloaded"><?php esc_html_e( 'Downloaded', 'maple-icons' ); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="mi-set-meta">
|
|
<span class="mi-set-license">
|
|
<?php
|
|
/* translators: %s: License name */
|
|
printf( esc_html__( 'License: %s', 'maple-icons' ), esc_html( $set['license'] ) );
|
|
?>
|
|
</span>
|
|
<span class="mi-set-styles">
|
|
<?php
|
|
/* translators: %s: Style names */
|
|
printf( esc_html__( 'Styles: %s', 'maple-icons' ), esc_html( implode( ', ', $set['styles'] ) ) );
|
|
?>
|
|
</span>
|
|
<?php if ( $is_downloaded && $icon_count > 0 ) : ?>
|
|
<span class="mi-set-count">
|
|
<?php
|
|
/* translators: %d: Number of icons */
|
|
printf( esc_html( _n( '%d icon', '%d icons', $icon_count, 'maple-icons' ) ), intval( $icon_count ) );
|
|
?>
|
|
</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if ( ! empty( $set['url'] ) ) : ?>
|
|
<a href="<?php echo esc_url( $set['url'] ); ?>" class="mi-set-link" target="_blank" rel="noopener noreferrer">
|
|
<?php esc_html_e( 'View on website', 'maple-icons' ); ?> →
|
|
</a>
|
|
<?php endif; ?>
|
|
|
|
<div class="mi-set-actions">
|
|
<?php if ( ! $is_downloaded ) : ?>
|
|
<button type="button" class="button button-primary mi-download-btn" data-slug="<?php echo esc_attr( $slug ); ?>">
|
|
<?php esc_html_e( 'Download', 'maple-icons' ); ?>
|
|
</button>
|
|
<?php else : ?>
|
|
<?php if ( ! $is_active ) : ?>
|
|
<button type="button" class="button button-primary mi-activate-btn" data-slug="<?php echo esc_attr( $slug ); ?>">
|
|
<?php esc_html_e( 'Set Active', 'maple-icons' ); ?>
|
|
</button>
|
|
<?php else : ?>
|
|
<button type="button" class="button mi-deactivate-btn" data-slug="">
|
|
<?php esc_html_e( 'Deactivate', 'maple-icons' ); ?>
|
|
</button>
|
|
<?php endif; ?>
|
|
<button type="button" class="button mi-delete-btn" data-slug="<?php echo esc_attr( $slug ); ?>">
|
|
<?php esc_html_e( 'Delete', 'maple-icons' ); ?>
|
|
</button>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="mi-set-progress" style="display: none;">
|
|
<div class="mi-progress-bar">
|
|
<div class="mi-progress-fill"></div>
|
|
</div>
|
|
<span class="mi-progress-text"></span>
|
|
</div>
|
|
|
|
<div class="mi-set-message" style="display: none;"></div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mi-admin-usage">
|
|
<h2><?php esc_html_e( 'How to Use', 'maple-icons' ); ?></h2>
|
|
<ol>
|
|
<li><?php esc_html_e( 'Download one or more icon sets above.', 'maple-icons' ); ?></li>
|
|
<li><?php esc_html_e( 'Set one icon set as active.', 'maple-icons' ); ?></li>
|
|
<li><?php esc_html_e( 'In the Gutenberg editor, add a "Maple Icon" block.', 'maple-icons' ); ?></li>
|
|
<li><?php esc_html_e( 'Search and select an icon from your active set.', 'maple-icons' ); ?></li>
|
|
<li><?php esc_html_e( 'Customize size, color, and other settings in the block sidebar.', 'maple-icons' ); ?></li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div class="mi-admin-info">
|
|
<h2><?php esc_html_e( 'About', 'maple-icons' ); ?></h2>
|
|
<p>
|
|
<?php esc_html_e( 'Maple Icons downloads SVG icons from CDN and stores them locally in your WordPress installation. Icons are sanitized for security and normalized for consistent rendering.', 'maple-icons' ); ?>
|
|
</p>
|
|
<p>
|
|
<?php esc_html_e( 'All icons use currentColor for styling, which means they automatically inherit text color from your theme or block settings.', 'maple-icons' ); ?>
|
|
</p>
|
|
<p>
|
|
<?php
|
|
printf(
|
|
/* translators: %s: Directory path */
|
|
esc_html__( 'Icons are stored in: %s', 'maple-icons' ),
|
|
'<code>' . esc_html( MI_ICONS_DIR ) . '</code>'
|
|
);
|
|
?>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|