| name | seo-service |
| description | Generate a new SEO service class following the Saman SEO plugin architecture. Use when creating new features that need a dedicated service, adding functionality to the plugin, or extending plugin capabilities. |
Create New SEO Service
Generate a new service class for the Saman SEO plugin following established patterns.
Arguments
$ARGUMENTS should contain: service name (e.g., "schema-validator") and optional description
Steps
-
Analyze the request to determine:
- Service name (convert to proper class naming:
Schema_Validator from "schema-validator")
- Service purpose and main functionality
- Required hooks (admin, frontend, or both)
- Whether it needs a settings page or REST API
-
Create the service file at includes/class-saman-seo-service-{name}.php
-
Follow this template structure:
<?php
namespace Saman\SEO;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Service_{Service_Name} {
public function boot() {
if ( ! \Saman\SEO\Helpers\module_enabled( '{module-key}' ) ) {
return;
}
add_action( 'init', array( $this, 'init' ) );
if ( is_admin() ) {
add_action( 'admin_init', array( $this, 'admin_init' ) );
}
}
public function init() {
}
public function admin_init() {
}
}
-
Register the service in includes/class-saman-seo-plugin.php:
- Add to the
boot() method's service registration list
- Example:
$this->register( '{service-key}', new Service_{Service_Name}() );
-
If the service needs a toggle, add the option:
- Add to default options in
Plugin::activate()
- Document in the module system
Patterns to Follow
- No Page Registration: Services MUST NOT call
add_submenu_page() or add_menu_page(). All admin pages are handled by the Admin_V2 React SPA. Use /react-page to create UI.
- Namespace: Always use
namespace Saman\SEO;
- Hooks: Register in
boot(), implement in separate methods
- Feature Toggle: Use
\Saman\SEO\Helpers\module_enabled( 'key' ) for toggleable features
- Capability Checks: Use
current_user_can( 'manage_options' ) for admin functions
- Sanitization: Always sanitize inputs with
sanitize_text_field(), absint(), etc.
- Escaping: Always escape outputs with
esc_html(), esc_attr(), etc.
Example Usage
/seo-service content-analyzer Analyzes post content for SEO improvements
This will create a new Service_Content_Analyzer class with the standard boilerplate.