Core Architecture
Main Plugin Class
The plugin uses a Singleton pattern to ensure only one instance exists throughout the WordPress lifecycle. File:class-visual-portfolio.php
Plugin Initialization
The plugin is initialized on theplugins_loaded hook:
Plugin Properties
The main class stores essential plugin information:Class Loading Order
Classes are loaded in a specific order viainclude_dependencies() to ensure proper initialization:
1. Deprecations (First)
2. Security & Utilities
3. Template & Asset Systems
4. Core Features
5. Gutenberg Integration
6. WordPress Integration
7. Third-Party Integrations
8. Migration (Last)
Core Classes
Visual_Portfolio_Assets
File:classes/class-assets.php
Manages all script and style enqueuing with conditional loading.
Key Features:
- Stores required assets per page load
- Conditionally enqueues assets only when needed
- Handles both static and dynamic CSS
- Manages head and footer asset loading
- Generates inline styles for customization
Visual_Portfolio_Custom_Post_Type
File:classes/class-custom-post-type.php
Registers the vp_lists custom post type for portfolios.
Post Type Configuration:
- Slug:
vp_lists - Supports: title, editor, thumbnail, author
- Capabilities: Custom capability system
- Taxonomies: Portfolio categories and tags
- Admin UI: Custom columns and filters
Visual_Portfolio_Templates
File:classes/class-templates.php
Handles template file loading with theme override support.
Template Hierarchy:
- Child theme:
wp-content/themes/child-theme/visual-portfolio/ - Parent theme:
wp-content/themes/theme/visual-portfolio/ - Plugin:
wp-content/plugins/visual-portfolio/templates/
Visual_Portfolio_Gutenberg
File:classes/class-gutenberg.php
Integrates the plugin with WordPress block editor.
Features:
- Registers block editor assets
- Provides editor-only styles
- Sets up block categories
- Registers block patterns
Visual_Portfolio_Rest
File:classes/class-rest.php
Provides REST API endpoints for AJAX operations.
Endpoints:
- Get portfolio items
- Lazy load items
- Filter and sort operations
- Custom content queries
Visual_Portfolio_Security
File:classes/class-security.php
Implements security measures throughout the plugin.
Features:
- Input sanitization
- Output escaping
- Nonce verification
- Capability checks
- SQL injection prevention
- XSS protection
Visual_Portfolio_Get_Portfolio
File:classes/class-get-portfolio.php
Core logic for retrieving and rendering portfolios.
Responsibilities:
- Query portfolio items
- Apply filters and sorting
- Render layouts
- Handle pagination
- Process custom queries
Hook System
Initialization Hooks
The plugin uses multipleinit hooks with different priorities:
Priority 10: Loads text domain
Priority 20: Runs deferred rewrite rules
Activation/Deactivation
- Sets welcome screen redirect transient
- Defers rewrite rules flush
- Clears capability cache
- Flushes rewrite rules
Rewrite Rules System
The plugin uses a deferred rewrite flush mechanism to avoid performance issues:- Post type must be registered before flushing
- Avoids multiple flushes on same page load
- Improves performance
Data Storage
Portfolio Settings
Portfolio configurations are stored in post meta:Transient Caching
The plugin uses transients for caching expensive operations:vp_flush_rewrite_rules- Deferred rewrite flush_visual_portfolio_welcome_screen_activation_redirect- Welcome screen redirectvp_oembed_data_*- oEmbed data cache
Template System
Template Files
Templates are organized by component:Theme Override
Themes can override templates by creating:Pro Plugin Integration
The plugin detects and integrates with the Pro version:Naming Conventions
PHP Classes
Pattern:Visual_Portfolio_ClassName
File Names
Pattern:class-{class-name}.php
class-assets.phpclass-templates.phpclass-custom-post-type.php
JavaScript
Modules: Modular ES6+ structureNaming: camelCase for functions, PascalCase for React components
SCSS
BEM Methodology:.vp-block__element--modifierPrefix: All classes prefixed with
vp-
Best Practices
Adding New Features
- Create a new class in
classes/directory - Follow naming convention:
class-feature-name.php - Use WordPress hooks for initialization
- Include in load order via
include_dependencies() - Add inline documentation using PHPDoc
- Run linters before committing
Extending Functionality
Use WordPress filters and actions:Performance Optimization
- Conditional loading: Only load assets when needed
- Transient caching: Cache expensive operations
- Lazy loading: Defer image loading
- Minification: Use minified assets in production
- Database queries: Use
WP_Querywith proper arguments
Next Steps
- Development Setup - Set up your local environment
- Developer Overview - High-level plugin overview
- Contributing - Contribution guidelines