feat: scaffold plugin foundation

This commit is contained in:
Keith Solomon
2026-04-26 12:44:16 -05:00
commit 557657344d
24 changed files with 5238 additions and 0 deletions
+93
View File
@@ -0,0 +1,93 @@
<?php
/**
* Admin dashboard controller.
*
* @package WPContentSync
*/
// phpcs:disable WordPress.Files.FileName.InvalidClassFileName
namespace WPContentSync\Admin;
use WPContentSync\Logging\LoggerInterface;
use WPContentSync\Settings\SettingsRepository;
/**
* Registers and renders the WP Content Sync admin page.
*/
final class AdminPage {
/**
* Settings storage.
*
* @var SettingsRepository
*/
private SettingsRepository $settings_repository;
/**
* Plugin logger.
*
* @var LoggerInterface
*/
private LoggerInterface $logger;
/**
* @param SettingsRepository $settings_repository Settings storage.
* @param LoggerInterface $logger Plugin logger.
*/
public function __construct( SettingsRepository $settings_repository, LoggerInterface $logger ) {
$this->settings_repository = $settings_repository;
$this->logger = $logger;
}
/**
* Registers admin hooks.
*/
public function register(): void {
add_action( 'admin_menu', array( $this, 'registerMenu' ) );
add_action( 'admin_init', array( $this, 'registerSettings' ) );
}
/**
* Registers the Tools menu page.
*/
// phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
public function registerMenu(): void {
add_management_page(
__( 'WP Content Sync', 'wp-content-sync' ),
__( 'Content Sync', 'wp-content-sync' ),
'manage_options',
'wp-content-sync',
array( $this, 'render' )
);
}
/**
* Registers the plugin settings option.
*/
// phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
public function registerSettings(): void {
register_setting(
'wpcs_settings',
SettingsRepository::OPTION_NAME,
array(
'type' => 'array',
'sanitize_callback' => array( $this->settings_repository, 'sanitizeOption' ),
'default' => $this->settings_repository->get()->toArray(),
)
);
}
/**
* Renders the admin dashboard.
*/
public function render(): void {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have permission to access WP Content Sync.', 'wp-content-sync' ) );
}
$settings = $this->settings_repository->get();
$this->logger->debug( 'Admin dashboard viewed.' );
include WPCS_PLUGIN_DIR . 'templates/admin/dashboard.php';
}
}