Addresses excessive line count in Peptide_News_Admin (1089 lines) by extracting responsibilities into single-purpose classes: - class-pn-admin-assets.php (88 lines): CSS/JS enqueuing - class-pn-admin-menu.php (98 lines): Menu & submenu registration - class-pn-admin-field-renderers.php (325 lines): 25+ field renderers (static) - class-pn-admin-settings.php (289 lines): Settings registration & sanitization - class-pn-admin-log-viewer.php (155 lines): Plugin log viewer UI & AJAX - class-pn-admin-settings-page.php (214 lines): Settings page + manual buttons - class-pn-admin-dashboard-pages.php (109 lines): Dashboard/articles/cost pages - class-peptide-news-admin.php (143 lines): Thin orchestrator (delegator) All files under 300 lines. Original public interface preserved exactly so no consumer code or tests break. Updated ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
89 lines
2.1 KiB
PHP
89 lines
2.1 KiB
PHP
<?php
|
|
declare( strict_types=1 );
|
|
/**
|
|
* Admin asset enqueuing.
|
|
*
|
|
* Handles CSS and JavaScript enqueuing for admin pages,
|
|
* including Chart.js library for analytics and cost dashboards.
|
|
*
|
|
* @since 2.5.0
|
|
* @see Peptide_News_Admin — Main admin orchestrator
|
|
*/
|
|
class Peptide_News_Admin_Assets {
|
|
|
|
/** @var string Plugin name/slug */
|
|
private $plugin_name;
|
|
|
|
/** @var string Plugin version for cache busting */
|
|
private $version;
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param string $plugin_name Plugin name/slug.
|
|
* @param string $version Plugin version.
|
|
*/
|
|
public function __construct( string $plugin_name, string $version ) {
|
|
$this->plugin_name = $plugin_name;
|
|
$this->version = $version;
|
|
}
|
|
|
|
/**
|
|
* Enqueue admin CSS.
|
|
*
|
|
* @param string $hook Current admin page hook.
|
|
* @return void
|
|
*/
|
|
public function enqueue_styles( string $hook ): void {
|
|
if ( strpos( $hook, 'peptide-news' ) === false ) {
|
|
return;
|
|
}
|
|
wp_enqueue_style(
|
|
$this->plugin_name . '-admin',
|
|
PEPTIDE_NEWS_PLUGIN_URL . 'admin/css/admin-style.css',
|
|
array(),
|
|
$this->version,
|
|
'all'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Enqueue admin JavaScript.
|
|
*
|
|
* Includes Chart.js for analytics and cost dashboards,
|
|
* plus the main admin script with AJAX handlers and localized data.
|
|
*
|
|
* @param string $hook Current admin page hook.
|
|
* @return void
|
|
*/
|
|
public function enqueue_scripts( string $hook ): void {
|
|
if ( strpos( $hook, 'peptide-news' ) === false ) {
|
|
return;
|
|
}
|
|
|
|
// Chart.js for analytics dashboard.
|
|
wp_enqueue_script(
|
|
'chartjs',
|
|
plugins_url( 'vendor/chartjs/chart.umd.min.js', __FILE__ ),
|
|
array(),
|
|
'4.4.0',
|
|
true
|
|
);
|
|
|
|
wp_enqueue_script(
|
|
$this->plugin_name . '-admin',
|
|
PEPTIDE_NEWS_PLUGIN_URL . 'admin/js/admin-script.js',
|
|
array( 'jquery', 'chartjs' ),
|
|
$this->version,
|
|
true
|
|
);
|
|
|
|
wp_localize_script( $this->plugin_name . '-admin', 'peptideNewsAdmin', array(
|
|
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
|
'rest_url' => rest_url( 'peptide-news/v1/' ),
|
|
'nonce' => wp_create_nonce( 'wp_rest' ),
|
|
'admin_nonce' => wp_create_nonce( 'peptide_news_admin' ),
|
|
) );
|
|
}
|
|
}
|