Fix code quality issues and Markdown formatting

This commit is contained in:
2025-04-21 21:15:29 +01:00
parent e8d81ef45b
commit ed160ed51b
5 changed files with 64 additions and 62 deletions

View File

@@ -10,7 +10,7 @@ WordPress Multisite allows you to run multiple WordPress sites from a single Wor
The plugin includes a dedicated directory for multisite-specific functionality: The plugin includes a dedicated directory for multisite-specific functionality:
``` ```text
includes/ includes/
└── Multisite/ └── Multisite/
├── class-multisite.php # Base class for multisite functionality ├── class-multisite.php # Base class for multisite functionality
@@ -23,8 +23,8 @@ includes/
The `Multisite` class in `includes/Multisite/class-multisite.php` provides a foundation for multisite-specific functionality. It includes: The `Multisite` class in `includes/Multisite/class-multisite.php` provides a foundation for multisite-specific functionality. It includes:
- A constructor for initialization * A constructor for initialization
- Example methods for multisite functionality * Example methods for multisite functionality
### 2. Load Multisite Classes ### 2. Load Multisite Classes
@@ -34,7 +34,7 @@ To use multisite-specific functionality, you need to load and initialize the cla
// Load multisite support classes if in multisite environment // Load multisite support classes if in multisite environment
if ( is_multisite() ) { if ( is_multisite() ) {
require_once WP_PLUGIN_STARTER_TEMPLATE_PATH . 'includes/Multisite/class-multisite.php'; require_once WP_PLUGIN_STARTER_TEMPLATE_PATH . 'includes/Multisite/class-multisite.php';
// Initialize multisite support // Initialize multisite support
$multisite = new WPALLSTARS\PluginStarterTemplate\Multisite\Multisite(); $multisite = new WPALLSTARS\PluginStarterTemplate\Multisite\Multisite();
} }
@@ -49,14 +49,14 @@ You can extend the base `Multisite` class or create additional classes in the `M
namespace WPALLSTARS\PluginStarterTemplate\Multisite; namespace WPALLSTARS\PluginStarterTemplate\Multisite;
class Domain_Mapping extends Multisite { class Domain_Mapping extends Multisite {
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
// Add hooks for domain mapping functionality // Add hooks for domain mapping functionality
add_action( 'init', array( $this, 'register_domain_mapping' ) ); add_action( 'init', array( $this, 'register_domain_mapping' ) );
} }
public function register_domain_mapping() { public function register_domain_mapping() {
// Implement domain mapping functionality // Implement domain mapping functionality
} }
@@ -96,13 +96,13 @@ add_action( 'wp_initialize_site', array( $this, 'on_site_creation' ), 10, 2 );
public function on_site_creation( $new_site, $args ) { public function on_site_creation( $new_site, $args ) {
// Get the blog ID // Get the blog ID
$blog_id = $new_site->blog_id; $blog_id = $new_site->blog_id;
// Switch to the new blog // Switch to the new blog
switch_to_blog( $blog_id ); switch_to_blog( $blog_id );
// Perform site-specific setup // Perform site-specific setup
update_option( 'your_plugin_option', 'default_value' ); update_option( 'your_plugin_option', 'default_value' );
// Restore the current blog // Restore the current blog
restore_current_blog(); restore_current_blog();
} }
@@ -119,10 +119,10 @@ add_action( 'network_admin_edit_your_plugin_action', array( $this, 'save_network
public function save_network_settings() { public function save_network_settings() {
// Check nonce // Check nonce
check_admin_referer( 'your_plugin_nonce' ); check_admin_referer( 'your_plugin_nonce' );
// Save settings // Save settings
update_site_option( 'your_plugin_network_option', sanitize_text_field( $_POST['your_option'] ) ); update_site_option( 'your_plugin_network_option', sanitize_text_field( $_POST['your_option'] ) );
// Redirect back to settings page // Redirect back to settings page
wp_redirect( add_query_arg( array( wp_redirect( add_query_arg( array(
'page' => 'your-plugin-slug', 'page' => 'your-plugin-slug',

View File

@@ -19,6 +19,7 @@ We use `@wordpress/env` and Cypress for testing our plugin.
### Installation ### Installation
1. Clone the repository: 1. Clone the repository:
```bash ```bash
git clone https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding.git git clone https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding.git
cd wp-plugin-starter-template-for-ai-coding cd wp-plugin-starter-template-for-ai-coding
@@ -37,8 +38,8 @@ We use `@wordpress/env` and Cypress for testing our plugin.
``` ```
This will: This will:
- Start a WordPress environment using wp-env * Start a WordPress environment using wp-env
- Activate our plugin * Activate our plugin
2. Run Cypress tests for single site: 2. Run Cypress tests for single site:
```bash ```bash
@@ -51,8 +52,8 @@ We use `@wordpress/env` and Cypress for testing our plugin.
``` ```
3. Access the site manually: 3. Access the site manually:
- Site: http://localhost:8888 * Site: <http://localhost:8888>
- Admin login: admin / password * Admin login: admin / password
## Testing in WordPress Multisite ## Testing in WordPress Multisite
@@ -62,10 +63,10 @@ We use `@wordpress/env` and Cypress for testing our plugin.
``` ```
This will: This will:
- Start a WordPress environment using wp-env * Start a WordPress environment using wp-env
- Configure it as a multisite installation * Configure it as a multisite installation
- Create a test subsite * Create a test subsite
- Network activate our plugin * Network activate our plugin
2. Run Cypress tests for multisite: 2. Run Cypress tests for multisite:
```bash ```bash
@@ -78,9 +79,9 @@ We use `@wordpress/env` and Cypress for testing our plugin.
``` ```
3. Access the sites manually: 3. Access the sites manually:
- Main site: http://localhost:8888 * Main site: <http://localhost:8888>
- Test subsite: http://localhost:8888/testsite * Test subsite: <http://localhost:8888/testsite>
- Admin login: admin / password * Admin login: admin / password
## Continuous Integration ## Continuous Integration
@@ -111,7 +112,7 @@ Add new multisite tests to `cypress/e2e/multisite.cy.js`.
```bash ```bash
# For single site # For single site
wp-env run cli wp plugin activate wp-plugin-starter-template-for-ai-coding wp-env run cli wp plugin activate wp-plugin-starter-template-for-ai-coding
# For multisite # For multisite
wp-env run cli wp plugin activate wp-plugin-starter-template-for-ai-coding --network wp-env run cli wp plugin activate wp-plugin-starter-template-for-ai-coding --network
``` ```
@@ -119,7 +120,8 @@ Add new multisite tests to `cypress/e2e/multisite.cy.js`.
### Getting Help ### Getting Help
If you encounter any issues, please open an issue on our GitHub repository with: If you encounter any issues, please open an issue on our GitHub repository with:
- A description of the problem
- Steps to reproduce * A description of the problem
- Any error messages * Steps to reproduce
- Your environment details (OS, Node.js version, etc.) * Any error messages
* Your environment details (OS, Node.js version, etc.)

View File

@@ -4,13 +4,13 @@ This PR adds a comprehensive testing framework for our WordPress plugin template
## Changes ## Changes
- Added wp-env configuration for both single site and multisite environments * Added wp-env configuration for both single site and multisite environments
- Created Cypress e2e tests for both environments * Created Cypress e2e tests for both environments
- Added GitHub Actions workflow to run tests automatically on PRs * Added GitHub Actions workflow to run tests automatically on PRs
- Created a unified setup script for test environments * Created a unified setup script for test environments
- Added detailed documentation in the wiki * Added detailed documentation in the wiki
- Updated README.md to reference the new testing approach * Updated README.md to reference the new testing approach
- Added placeholder files for multisite functionality * Added placeholder files for multisite functionality
## Testing ## Testing

View File

@@ -3,7 +3,7 @@ const { defineConfig } = require('cypress');
module.exports = defineConfig({ module.exports = defineConfig({
e2e: { e2e: {
baseUrl: 'http://localhost:8888', baseUrl: 'http://localhost:8888',
setupNodeEvents(on, config) { setupNodeEvents() {
// implement node event listeners here // implement node event listeners here
}, },
}, },

View File

@@ -13,7 +13,7 @@ namespace WPALLSTARS\PluginStarterTemplate\Multisite;
// Exit if accessed directly. // Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
/** /**
@@ -23,31 +23,31 @@ if ( ! defined( 'ABSPATH' ) ) {
*/ */
class Multisite { class Multisite {
/** /**
* Constructor. * Constructor.
*/ */
public function __construct() { public function __construct() {
// This is just a placeholder class. // This is just a placeholder class.
// Add your multisite-specific initialization here. // Add your multisite-specific initialization here.
} }
/** /**
* Example method for multisite functionality. * Example method for multisite functionality.
* *
* @return bool Always returns true. * @return bool Always returns true.
*/ */
public function is_multisite_compatible() { public function is_multisite_compatible() {
return true; return true;
} }
/** /**
* Example method to get all sites in the network. * Example method to get all sites in the network.
* *
* @return array An empty array as this is just a placeholder. * @return array An empty array as this is just a placeholder.
*/ */
public function get_network_sites() { public function get_network_sites() {
// This is just a placeholder method. // This is just a placeholder method.
// In a real implementation, you might use get_sites() or a custom query. // In a real implementation, you might use get_sites() or a custom query.
return array(); return array();
} }
} }