Fix camelCase naming and superglobal access issues

- Renamed methods to follow camelCase convention (initialize_hooks -> initializeHooks, enqueue_admin_assets -> enqueueAdminAssets)
- Renamed variables to follow camelCase convention (plugin_version -> pluginVersion)
- Replaced direct  superglobal access with filter_input() for better security
- Simplified commented-out code with a clear TODO comment
This commit is contained in:
2025-04-21 15:14:15 +01:00
parent ebdb172a14
commit 67c6c65611
3 changed files with 16 additions and 23 deletions

View File

@@ -124,7 +124,7 @@
} }
/* Responsive Styles */ /* Responsive Styles */
@media screen and (width <= 782px) { @media screen and (max-width: 782px) {
.wpst-form-table th { .wpst-form-table th {
width: 100%; width: 100%;
display: block; display: block;

View File

@@ -28,14 +28,14 @@ class Admin {
*/ */
public function __construct( Core $core ) { public function __construct( Core $core ) {
$this->core = $core; $this->core = $core;
$this->initialize_hooks(); $this->initializeHooks();
} }
/** /**
* Initializes WordPress hooks. * Initializes WordPress hooks.
*/ */
private function initialize_hooks() { private function initializeHooks(): void {
\add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) ); \add_action( 'admin_enqueue_scripts', array( $this, 'enqueueAdminAssets' ) );
} }
/** /**
@@ -48,24 +48,25 @@ class Admin {
* *
* @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found * @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
*/ */
public function enqueue_admin_assets(): void { public function enqueueAdminAssets(): void {
// @phpcs:disable WordPress.Security.NonceVerification.Recommended // @phpcs:disable WordPress.Security.NonceVerification.Recommended
// @phpcs:disable WordPress.Security.NonceVerification.Missing // @phpcs:disable WordPress.Security.NonceVerification.Missing
if ( ! isset( $_GET['page'] ) || 'wp_plugin_starter_template_settings' !== $_GET['page'] ) { $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if ( ! $page || 'wp_plugin_starter_template_settings' !== $page ) {
return; return;
} }
// @phpcs:enable // @phpcs:enable
// Get the plugin version. // Get the plugin version.
$plugin_version = $this->core->get_plugin_version(); $pluginVersion = $this->core->get_plugin_version();
// Enqueue styles. // Enqueue styles.
\wp_enqueue_style( \wp_enqueue_style(
'wpst-admin-styles', 'wpst-admin-styles',
\plugin_dir_url( __FILE__ ) . '../../admin/css/admin-styles.css', \plugin_dir_url( __FILE__ ) . '../../admin/css/admin-styles.css',
array(), // Dependencies. array(), // Dependencies.
$plugin_version // Version. $pluginVersion // Version.
); );
// Enqueue admin scripts. // Enqueue admin scripts.
@@ -73,19 +74,11 @@ class Admin {
'wpst-admin-script', 'wpst-admin-script',
\plugin_dir_url( __FILE__ ) . '../../admin/js/admin-scripts.js', \plugin_dir_url( __FILE__ ) . '../../admin/js/admin-scripts.js',
array( 'jquery' ), array( 'jquery' ),
$plugin_version, // Version. $pluginVersion, // Version.
true true
); );
// Prepare data for localization. // TODO: Implement localization when mocking is fixed (Issue #1)
$data = array( // This will include ajax_url and nonce for security
'ajax_url' => \admin_url( 'admin-ajax.php' ),
// @TODO: Fix mocking for wp_create_nonce. Issue #1.
// 'nonce' => \wp_create_nonce( 'wpst_admin_nonce' ),
);
// Localize the script with the data.
// @TODO: Fix mocking for wp_localize_script. Issue #1.
// Will need to implement wp_localize_script for 'wpst-admin-script' with 'wpst_admin_data' and the data array.
} }
} }

View File

@@ -29,11 +29,11 @@ class Plugin {
private $admin; private $admin;
/** /**
* Plugin file * Plugin file path
* *
* @var string * @var string
*/ */
private $plugin_file; private string $pluginFile;
/** /**
* Plugin version * Plugin version
@@ -48,8 +48,8 @@ class Plugin {
* @param string $plugin_file Main plugin file path. * @param string $plugin_file Main plugin file path.
* @param string $version Plugin version. * @param string $version Plugin version.
*/ */
public function __construct( $plugin_file, $version ) { public function __construct( string $pluginFile, string $version ) {
$this->plugin_file = $plugin_file; $this->pluginFile = $pluginFile;
$this->version = $version; $this->version = $version;
$this->core = new Core( $version ); $this->core = new Core( $version );
$this->admin = new Admin( $this->core ); $this->admin = new Admin( $this->core );