# Implementation Plan - Care Book Block Ultimate **Project**: WordPress Plugin for KiviCare Appointment Control **Branch**: feature/wordpress-plugin-kivicare-appointment-control **Created**: 2025-09-12 **Context7 MCP**: βœ… Active **Web Research**: βœ… Completed --- ## 🚨 CRITICAL COMPATIBILITY UPDATES **Based on Web Research ObrigatΓ³ria findings**: ### πŸ”΄ **SECURITY-CRITICAL UPDATES REQUIRED** - **PHP 7.4**: EOL since Nov 2022 - **UPGRADE to PHP 8.1+ MANDATORY** - **MySQL 5.7**: EOL since Oct 2023 - **UPGRADE to MySQL 8.0+ REQUIRED** - **Impact**: Current minimum requirements expose to critical vulnerabilities ### βœ… **Updated Tech Stack (Security-Validated)** ```yaml Production Stack: PHP: 8.1+ (LTS) or 8.4+ (Latest - supported until 2028) WordPress: 6.8+ (Latest annual release) MySQL: 8.0.35+ (Performance + Security) KiviCare: 3.6.8+ (Latest security fixes - Feb 2025) Composer: Latest (PSR-4 autoloading) ``` --- ## πŸ—οΈ ARCHITECTURAL DESIGN ### **Core Architecture Pattern: CSS-First + Hook-Based Integration** ```mermaid graph TB A[WordPress Frontend] --> B[CSS Injection Layer] B --> C[Visual Element Hiding] C --> D[PHP Hook Layer] D --> E[Data Filtering] E --> F[Cache Layer] F --> G[Database Layer] H[Admin Interface] --> I[AJAX Endpoints] I --> J[Restriction Management] J --> F K[KiviCare Plugin] --> D ``` ### **Database Architecture** ```sql -- Updated for MySQL 8.0+ compatibility CREATE TABLE wp_care_booking_restrictions ( id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, doctor_id BIGINT UNSIGNED NOT NULL, service_id BIGINT UNSIGNED NULL COMMENT 'NULL = applies to all services', restriction_type ENUM('hide_doctor', 'hide_service', 'hide_combination') NOT NULL, is_active BOOLEAN DEFAULT true, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, created_by BIGINT UNSIGNED, metadata JSON NULL COMMENT 'MySQL 8.0+ JSON support for flexible data', INDEX idx_doctor_service (doctor_id, service_id), INDEX idx_active_restrictions (is_active, restriction_type), INDEX idx_created_at (created_at), FOREIGN KEY (doctor_id) REFERENCES wp_kc_doctors(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ``` ### **PSR-4 Namespace Structure** (2024-2025 Best Practices) ```php =8.1" } } ``` --- ## πŸ“Š IMPLEMENTATION PHASES ### **Phase 0: Foundation & Security Updates** ⭐ NEW **Duration**: 2-3 days **Priority**: CRITICAL #### Tasks: - [ ] **Update development environment to PHP 8.1+/8.4** - [ ] **Update MySQL to 8.0.35+** - [ ] **Test WordPress 6.8 compatibility** - [ ] **Verify KiviCare 3.6.8+ integration points** - [ ] **Setup Composer with PSR-4 autoloading** - [ ] **Create modern PHP 8+ plugin structure** #### Deliverables: - βœ… Security-compliant development environment - βœ… Modern PSR-4 plugin structure - βœ… Updated compatibility documentation --- ### **Phase 1: Core Foundation** (Week 1) **Duration**: 5 days **Dependencies**: Phase 0 complete #### Tasks: - [ ] **Plugin main file with PHP 8.1+ features** ```php getActiveRestrictions(); $css = $this->generateHidingCss($restrictions); wp_add_inline_style('kivicare-frontend', $css); } private function generateHidingCss(array $restrictions): string { // Generate CSS to immediately hide restricted elements return $this->buildSelectorCss($restrictions); } } ``` - [ ] **KiviCare integration hooks** ```php validateNonce(); $this->checkCapabilities(); // Modern PHP 8+ request handling $request = $this->validateRequest($_POST); $result = $this->restrictionService->toggle($request); wp_send_json_success($result); } } ``` - [ ] **Caching layer with WordPress Transients** ```php loadFromDatabase(); set_transient(self::CACHE_KEY, $restrictions, self::CACHE_EXPIRATION); return $restrictions; } } ``` #### Deliverables: - βœ… CSS injection system - βœ… KiviCare integration hooks - βœ… AJAX admin interface - βœ… Intelligent caching system --- ### **Phase 3: Enhancement & Optimization** (Week 3-4) **Duration**: 10 days **Dependencies**: Phase 2 complete #### Tasks: - [ ] **Bulk operations interface** - [ ] **Export/import functionality with JSON** - [ ] **Audit logging system** - [ ] **Performance optimization** - Query optimization for MySQL 8.0 - Advanced caching strategies - CSS minification - AJAX request batching - [ ] **Modern testing suite** ```php assertEquals(123, $restriction->doctorId); $this->assertEquals(RestrictionType::HIDE_DOCTOR, $restriction->type); } } ``` #### Deliverables: - βœ… Advanced admin features - βœ… Import/export system - βœ… Performance-optimized code - βœ… Comprehensive test suite --- ## πŸ§ͺ TESTING STRATEGY (Updated for PHP 8+) ### **Unit Tests (PHPUnit 10+)** ```bash # Modern PHP 8+ testing composer require --dev phpunit/phpunit:^10.0 composer require --dev mockery/mockery # Run tests ./vendor/bin/phpunit tests/ ``` ### **Integration Tests** - WordPress 6.6, 6.7, 6.8 compatibility - KiviCare 3.6.8+ integration - MySQL 8.0+ query testing - PHP 8.1/8.4 compatibility testing ### **Performance Benchmarks** - Page load impact: <5% (target: <2% with modern stack) - AJAX response: <200ms (target: <100ms with PHP 8+) - Cache efficiency: >90% hit ratio - MySQL 8.0 query optimization --- ## πŸ“ˆ PERFORMANCE TARGETS (Updated) ### **With Modern Stack (PHP 8.4 + MySQL 8.0)** - **Page Load Overhead**: <2% (improved from <5%) - **AJAX Response Time**: <100ms (improved from <200ms) - **Database Query Time**: <50ms (MySQL 8.0 optimization) - **Cache Hit Ratio**: >95% (improved caching strategy) - **Memory Usage**: <10MB additional (PHP 8 efficiency) --- ## πŸ”’ SECURITY IMPLEMENTATION (PHP 8+ Features) ### **Input Validation & Sanitization** ```php validatePositiveInt($data['doctor_id'] ?? null), serviceId: $this->validateOptionalPositiveInt($data['service_id'] ?? null), restrictionType: RestrictionType::from($data['type'] ?? ''), isActive: $this->validateBoolean($data['is_active'] ?? true) ); } private function validatePositiveInt(?string $value): int { if ($value === null) { throw new InvalidArgumentException('Required integer value is missing'); } $int = filter_var($value, FILTER_VALIDATE_INT); if ($int === false || $int <= 0) { throw new InvalidArgumentException('Invalid positive integer'); } return $int; } } ``` ### **Capability-Based Access Control** ```php 95% - [ ] βœ… Database queries optimized for MySQL 8.0 --- ## 🚨 RISK MITIGATION UPDATED ### **Security Risks (RESOLVED)** - βœ… **PHP 7.4 vulnerabilities**: Upgraded to PHP 8.1+ - βœ… **MySQL 5.7 EOL**: Upgraded to MySQL 8.0+ - βœ… **Outdated dependencies**: Updated to latest secure versions ### **Technical Risks** - **KiviCare Updates**: Hook-based integration (no core modifications) - **Performance Impact**: Modern stack + optimized caching - **Plugin Conflicts**: Proper namespacing + defensive coding - **PHP 8 Breaking Changes**: Comprehensive testing on PHP 8.1/8.4 ### **Migration Risks** - **PHP 7.4 β†’ 8.1+ Migration**: Code audit + testing required - **MySQL 5.7 β†’ 8.0 Migration**: Query compatibility testing - **Compatibility Testing**: Multi-version testing matrix --- ## πŸ“… UPDATED TIMELINE | Phase | Duration | Focus | Deliverables | |-------|----------|-------|--------------| | **Phase 0** | 2-3 days | Security Updates | Modern dev environment | | **Phase 1** | 5 days | Foundation | Plugin structure, database | | **Phase 2** | 7 days | Core Features | CSS injection, hooks, AJAX | | **Phase 3** | 10 days | Enhancement | Optimization, testing, docs | | **Total** | **3-4 weeks** | **Complete Plugin** | **Production-ready system** | --- ## βœ… NEXT STEPS 1. **Execute Phase 0**: Update development environment to secure stack 2. **Context7 Consultation**: Query for architectural recommendations 3. **Dify Specialist Review**: Validate plan with expert consultation 4. **Begin Implementation**: Start Phase 1 with modern foundation 5. **Continuous Testing**: Multi-version compatibility validation --- **Plan Status**: βœ… Complete with Security Updates **Web Research**: βœ… Technology compatibility validated **Context7 MCP**: βœ… Active and ready for consultation **Next Command**: `/tasks` to generate detailed task breakdown