From 2e25c4813540ffa5b33a091f5f517253e2dfc5ce Mon Sep 17 00:00:00 2001 From: marcusquinn <6428977+marcusquinn@users.noreply.github.com> Date: Mon, 21 Apr 2025 22:03:09 +0100 Subject: [PATCH] Fix code quality issues and WordPress naming conventions --- .github/workflows/wordpress-tests.yml | 8 ++--- includes/Multisite/class-multisite.php | 4 +-- includes/class-plugin.php | 4 +-- wp-plugin-starter-template.php | 50 +++++++++++++------------- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/.github/workflows/wordpress-tests.yml b/.github/workflows/wordpress-tests.yml index af2786a..23db66a 100644 --- a/.github/workflows/wordpress-tests.yml +++ b/.github/workflows/wordpress-tests.yml @@ -73,10 +73,10 @@ jobs: MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress options: > - --health-cmd="mysqladmin ping" - --health-interval=10s - --health-timeout=5s - --health-retries=3 + --health-cmd "mysqladmin ping" + --health-interval 10s + --health-timeout 5s + --health-retries 3 steps: - uses: actions/checkout@v4 diff --git a/includes/Multisite/class-multisite.php b/includes/Multisite/class-multisite.php index 1620526..f5a5fcb 100644 --- a/includes/Multisite/class-multisite.php +++ b/includes/Multisite/class-multisite.php @@ -36,7 +36,7 @@ class Multisite { * * @return bool Always returns true. */ - public function isMultisiteCompatible() { + public function is_multisite_compatible() { return true; } @@ -45,7 +45,7 @@ class Multisite { * * @return array An empty array as this is just a placeholder. */ - public function getNetworkSites() { + public function get_network_sites() { // This is just a placeholder method. // In a real implementation, you might use get_sites() or a custom query. return function_exists( 'get_sites' ) ? get_sites( array( 'public' => 1 ) ) : array(); diff --git a/includes/class-plugin.php b/includes/class-plugin.php index 4f01883..5892269 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -83,7 +83,7 @@ class Plugin { * * @return string The plugin version. */ - public function getVersion(): string { + public function get_version(): string { return $this->version; } @@ -92,7 +92,7 @@ class Plugin { * * @return Admin The admin instance. */ - public function getAdmin(): Admin { + public function get_admin(): Admin { return $this->admin; } } diff --git a/wp-plugin-starter-template.php b/wp-plugin-starter-template.php index 1794f86..dd9f772 100644 --- a/wp-plugin-starter-template.php +++ b/wp-plugin-starter-template.php @@ -41,32 +41,34 @@ define( 'WP_PLUGIN_STARTER_TEMPLATE_VERSION', '0.1.13' ); use WPALLSTARS\PluginStarterTemplate\Plugin; // Register autoloader for plugin classes. -spl_autoload_register( function ( $class ) { - // Plugin namespace prefix - $prefix = 'WPALLSTARS\\PluginStarterTemplate\\'; +spl_autoload_register( + function ( $className ) { + // Plugin namespace prefix. + $prefix = 'WPALLSTARS\\PluginStarterTemplate\\'; - // Check if the class uses our namespace - $len = strlen( $prefix ); - if ( strncmp( $prefix, $class, $len ) !== 0 ) { - return; + // Check if the class uses our namespace. + $len = strlen( $prefix ); + if ( strncmp( $prefix, $className, $len ) !== 0 ) { + return; + } + + // Get the relative class name. + $relative_class = substr( $className, $len ); + + // Convert namespace to path. + $file = WP_PLUGIN_STARTER_TEMPLATE_PATH . 'includes/' . str_replace( '\\', '/', $relative_class ) . '.php'; + + // Convert class name format to file name format. + $file = str_replace( 'class-', '', $file ); + $file = preg_replace( '/([a-z])([A-Z])/', '$1-$2', $file ); + $file = strtolower( $file ); + + // If the file exists, require it. + if ( file_exists( $file ) ) { + require_once $file; + } } - - // Get the relative class name - $relative_class = substr( $class, $len ); - - // Convert namespace to path - $file = WP_PLUGIN_STARTER_TEMPLATE_PATH . 'includes/' . str_replace( '\\', '/', $relative_class ) . '.php'; - - // Convert class name format to file name format - $file = str_replace( 'class-', '', $file ); - $file = preg_replace( '/([a-z])([A-Z])/', '$1-$2', $file ); - $file = strtolower( $file ); - - // If the file exists, require it - if ( file_exists( $file ) ) { - require_once $file; - } -} ); +); // Plugin is multisite compatible - see .wiki/Testing-Framework.md for testing instructions. // For multisite-specific functionality, see the includes/Multisite directory.