Skip to content

Commit f7521ed

Browse files
authored
Update
1 parent 25669cf commit f7521ed

2 files changed

Lines changed: 133 additions & 64 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131
- Improved plugin structure with centralized settings management
3232
- Enhanced user experience with clear feature descriptions and dependency information
3333

34+
### Fixed
35+
- **Code Quality:**
36+
- Fixed array alignment issues to meet WordPress coding standards
37+
- Removed unused variable in sanitize_settings() method
38+
- Refactored long methods (init_settings, settings_page) into smaller, focused methods
39+
- Improved code maintainability and readability
40+
- Enhanced method separation for better testing and debugging
41+
3442
## [1.0.5] - 2025-08-11
3543

3644
### Security

class-optimizations-ace-mc.php

Lines changed: 125 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ class Optimizations_Ace_Mc {
3535
* @var array
3636
*/
3737
private $default_settings = array(
38-
'woocommerce_show_empty_categories' => true,
39-
'woocommerce_hide_category_count' => true,
40-
'woocommerce_user_order_count_column' => true,
41-
'wpsl_show_store_categories' => true,
42-
'wpsl_disable_rest_api' => true,
43-
'admin_user_registration_date_column' => true,
38+
'woocommerce_show_empty_categories' => true,
39+
'woocommerce_hide_category_count' => true,
40+
'woocommerce_user_order_count_column' => true,
41+
'wpsl_show_store_categories' => true,
42+
'wpsl_disable_rest_api' => true,
43+
'admin_user_registration_date_column' => true,
4444
);
4545

4646
/**
@@ -335,7 +335,16 @@ public function init_settings() {
335335
array( $this, 'sanitize_settings' )
336336
);
337337

338-
// WooCommerce settings section.
338+
// Initialize settings sections.
339+
$this->init_woocommerce_settings();
340+
$this->init_wpsl_settings();
341+
$this->init_admin_settings();
342+
}
343+
344+
/**
345+
* Initialize WooCommerce settings section.
346+
*/
347+
private function init_woocommerce_settings() {
339348
add_settings_section(
340349
'woocommerce_section',
341350
__( 'WooCommerce Optimizations', 'optimizations-ace-mc' ),
@@ -378,8 +387,12 @@ public function init_settings() {
378387
'description' => __( 'Add an order count column to the WordPress Users admin table.', 'optimizations-ace-mc' ),
379388
)
380389
);
390+
}
381391

382-
// WP Store Locator settings section.
392+
/**
393+
* Initialize WP Store Locator settings section.
394+
*/
395+
private function init_wpsl_settings() {
383396
add_settings_section(
384397
'wpsl_section',
385398
__( 'WP Store Locator Optimizations', 'optimizations-ace-mc' ),
@@ -410,8 +423,12 @@ public function init_settings() {
410423
'description' => __( 'Disable REST API endpoint for WP Store Locator post type for security.', 'optimizations-ace-mc' ),
411424
)
412425
);
426+
}
413427

414-
// WordPress Admin settings section.
428+
/**
429+
* Initialize WordPress admin settings section.
430+
*/
431+
private function init_admin_settings() {
415432
add_settings_section(
416433
'admin_section',
417434
__( 'WordPress Admin Optimizations', 'optimizations-ace-mc' ),
@@ -442,7 +459,7 @@ public function sanitize_settings( $input ) {
442459
$sanitized = array();
443460

444461
// Sanitize each setting based on its type.
445-
foreach ( $this->default_settings as $key => $default_value ) {
462+
foreach ( $this->default_settings as $key => $value ) {
446463
if ( isset( $input[ $key ] ) ) {
447464
$sanitized[ $key ] = (bool) $input[ $key ];
448465
} else {
@@ -504,27 +521,14 @@ public function settings_page() {
504521
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'optimizations-ace-mc' ) );
505522
}
506523

507-
// Note: Form submission is handled automatically by WordPress Settings API.
508-
// The settings_fields() function handles CSRF protection via nonces.
509-
if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] ) {
510-
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Settings saved successfully!', 'optimizations-ace-mc' ) . '</p></div>';
511-
}
524+
// Display success message if settings were updated.
525+
$this->display_admin_notices();
512526
?>
513527
<div class="wrap">
514528
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
515529

516-
<div class="notice notice-info">
517-
<p>
518-
<strong><?php esc_html_e( 'Plugin Information:', 'optimizations-ace-mc' ); ?></strong>
519-
<?php esc_html_e( 'This plugin provides pre-configured optimizations for WooCommerce, WP Store Locator, and WordPress admin interfaces.', 'optimizations-ace-mc' ); ?>
520-
</p>
521-
<p>
522-
<strong><?php esc_html_e( 'Version:', 'optimizations-ace-mc' ); ?></strong> <?php echo esc_html( OPTIMIZATIONS_ACE_MC_VERSION ); ?> |
523-
<strong><?php esc_html_e( 'WordPress:', 'optimizations-ace-mc' ); ?></strong> <?php esc_html_e( '6.5+ required', 'optimizations-ace-mc' ); ?> |
524-
<strong><?php esc_html_e( 'PHP:', 'optimizations-ace-mc' ); ?></strong> <?php esc_html_e( '7.4+ required', 'optimizations-ace-mc' ); ?>
525-
</p>
526-
</div>
527-
530+
<?php $this->display_plugin_info(); ?>
531+
528532
<form method="post" action="options.php">
529533
<?php
530534
settings_fields( 'optimizations_ace_mc_group' );
@@ -533,45 +537,102 @@ public function settings_page() {
533537
?>
534538
</form>
535539

536-
<div class="card">
537-
<h2><?php esc_html_e( 'Plugin Dependencies', 'optimizations-ace-mc' ); ?></h2>
538-
<p><?php esc_html_e( 'This plugin is designed to work with the following plugins:', 'optimizations-ace-mc' ); ?></p>
539-
<ul>
540-
<li>
541-
<strong>WooCommerce:</strong>
542-
<?php
543-
if ( class_exists( 'WooCommerce' ) ) {
544-
echo '<span style="color: green;">✓ ' . esc_html__( 'Active', 'optimizations-ace-mc' ) . '</span>';
545-
} else {
546-
echo '<span style="color: orange;">! ' . esc_html__( 'Not detected', 'optimizations-ace-mc' ) . '</span>';
547-
}
548-
?>
549-
</li>
550-
<li>
551-
<strong>WP Store Locator:</strong>
552-
<?php
553-
if ( class_exists( 'WP_Store_locator' ) || function_exists( 'wpsl_store_header_template' ) ) {
554-
echo '<span style="color: green;">✓ ' . esc_html__( 'Active', 'optimizations-ace-mc' ) . '</span>';
555-
} else {
556-
echo '<span style="color: orange;">! ' . esc_html__( 'Not detected', 'optimizations-ace-mc' ) . '</span>';
557-
}
558-
?>
559-
</li>
560-
</ul>
561-
<p><em><?php esc_html_e( 'Note: Plugin features will only be active when their corresponding dependencies are installed and activated.', 'optimizations-ace-mc' ); ?></em></p>
562-
</div>
563-
564-
<div class="card">
565-
<h2><?php esc_html_e( 'Support & Documentation', 'optimizations-ace-mc' ); ?></h2>
566-
<p>
567-
<?php esc_html_e( 'For support, bug reports, or feature requests:', 'optimizations-ace-mc' ); ?>
568-
<a href="https://github.com/PDowney/optimizations-ace-mc" target="_blank" rel="noopener noreferrer">
569-
<?php esc_html_e( 'Visit the GitHub repository', 'optimizations-ace-mc' ); ?>
570-
</a>
571-
</p>
572-
</div>
540+
<?php
541+
$this->display_dependencies_info();
542+
$this->display_support_info();
543+
$this->output_admin_styles();
544+
?>
545+
</div>
546+
<?php
547+
}
548+
549+
/**
550+
* Display admin notices.
551+
*/
552+
private function display_admin_notices() {
553+
// Note: Form submission is handled automatically by WordPress Settings API.
554+
// The settings_fields() function handles CSRF protection via nonces.
555+
if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] ) {
556+
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Settings saved successfully!', 'optimizations-ace-mc' ) . '</p></div>';
557+
}
558+
}
559+
560+
/**
561+
* Display plugin information.
562+
*/
563+
private function display_plugin_info() {
564+
?>
565+
<div class="notice notice-info">
566+
<p>
567+
<strong><?php esc_html_e( 'Plugin Information:', 'optimizations-ace-mc' ); ?></strong>
568+
<?php esc_html_e( 'This plugin provides pre-configured optimizations for WooCommerce, WP Store Locator, and WordPress admin interfaces.', 'optimizations-ace-mc' ); ?>
569+
</p>
570+
<p>
571+
<strong><?php esc_html_e( 'Version:', 'optimizations-ace-mc' ); ?></strong> <?php echo esc_html( OPTIMIZATIONS_ACE_MC_VERSION ); ?> |
572+
<strong><?php esc_html_e( 'WordPress:', 'optimizations-ace-mc' ); ?></strong> <?php esc_html_e( '6.5+ required', 'optimizations-ace-mc' ); ?> |
573+
<strong><?php esc_html_e( 'PHP:', 'optimizations-ace-mc' ); ?></strong> <?php esc_html_e( '7.4+ required', 'optimizations-ace-mc' ); ?>
574+
</p>
573575
</div>
576+
<?php
577+
}
574578

579+
/**
580+
* Display plugin dependencies information.
581+
*/
582+
private function display_dependencies_info() {
583+
?>
584+
<div class="card">
585+
<h2><?php esc_html_e( 'Plugin Dependencies', 'optimizations-ace-mc' ); ?></h2>
586+
<p><?php esc_html_e( 'This plugin is designed to work with the following plugins:', 'optimizations-ace-mc' ); ?></p>
587+
<ul>
588+
<li>
589+
<strong>WooCommerce:</strong>
590+
<?php
591+
if ( class_exists( 'WooCommerce' ) ) {
592+
echo '<span style="color: green;">✓ ' . esc_html__( 'Active', 'optimizations-ace-mc' ) . '</span>';
593+
} else {
594+
echo '<span style="color: orange;">! ' . esc_html__( 'Not detected', 'optimizations-ace-mc' ) . '</span>';
595+
}
596+
?>
597+
</li>
598+
<li>
599+
<strong>WP Store Locator:</strong>
600+
<?php
601+
if ( class_exists( 'WP_Store_locator' ) || function_exists( 'wpsl_store_header_template' ) ) {
602+
echo '<span style="color: green;">✓ ' . esc_html__( 'Active', 'optimizations-ace-mc' ) . '</span>';
603+
} else {
604+
echo '<span style="color: orange;">! ' . esc_html__( 'Not detected', 'optimizations-ace-mc' ) . '</span>';
605+
}
606+
?>
607+
</li>
608+
</ul>
609+
<p><em><?php esc_html_e( 'Note: Plugin features will only be active when their corresponding dependencies are installed and activated.', 'optimizations-ace-mc' ); ?></em></p>
610+
</div>
611+
<?php
612+
}
613+
614+
/**
615+
* Display support information.
616+
*/
617+
private function display_support_info() {
618+
?>
619+
<div class="card">
620+
<h2><?php esc_html_e( 'Support & Documentation', 'optimizations-ace-mc' ); ?></h2>
621+
<p>
622+
<?php esc_html_e( 'For support, bug reports, or feature requests:', 'optimizations-ace-mc' ); ?>
623+
<a href="https://github.com/PDowney/optimizations-ace-mc" target="_blank" rel="noopener noreferrer">
624+
<?php esc_html_e( 'Visit the GitHub repository', 'optimizations-ace-mc' ); ?>
625+
</a>
626+
</p>
627+
</div>
628+
<?php
629+
}
630+
631+
/**
632+
* Output admin page styles.
633+
*/
634+
private function output_admin_styles() {
635+
?>
575636
<style>
576637
.card {
577638
background: #fff;

0 commit comments

Comments
 (0)