Skip to main content

Overview

The Visual Portfolio plugin includes a powerful visual editor that allows you to create and configure portfolio layouts through a dedicated post type interface. This editor provides a live preview and comprehensive settings panel.

Saved Layouts (vp_lists)

Visual Portfolio uses a custom post type called vp_lists to store saved layouts. Each saved layout is a reusable portfolio configuration that can be inserted anywhere on your site.

Accessing the Visual Editor

  1. Navigate to WordPress Admin → Visual Portfolio → Add New
  2. The editor will open with a single block: visual-portfolio/saved-editor
  3. Configure your settings in the sidebar
  4. Preview changes in real-time in the editor

Editor Architecture

The visual editor is built on top of WordPress Gutenberg and located in /home/daytona/workspace/source/gutenberg/layouts-editor/.

Editor Block

The editor uses a special block (visual-portfolio/saved-editor) that is automatically inserted and always selected:

Editor Enforcement

The editor enforces several rules:
  1. Visual Mode Only - Forces the editor to stay in visual mode
  2. Single Block - Only allows one editor block per layout
  3. Always Selected - Keeps the editor block selected for immediate configuration

Settings Storage

Layout settings are stored as WordPress post meta with the vp_ prefix:

Meta Data Caching

The plugin caches layout meta for performance in /home/daytona/workspace/source/classes/class-controls.php:348-366:

Control System

The visual editor uses a robust control system defined in class-controls.php.

Default Control Arguments

Every control supports these base arguments:

Control Types

The editor supports various control types:
  • text - Single line text input
  • textarea - Multi-line text
  • number - Numeric input
  • range - Slider control
  • checkbox - Boolean toggle
  • select - Dropdown selection
  • color - Color picker with alpha/gradient support
  • gallery - Image gallery manager
  • code_editor - Code editor with syntax highlighting
  • elements_selector - Element location selector
  • align - Alignment control

Conditional Controls

Controls can be conditionally shown based on other control values:
Supported operators: ==, !==, >, <, >=, <=

Style System

Controls can automatically generate CSS:

Control Categories

Controls are organized into categories for better UX:

Registering Custom Controls

You can register custom controls for the visual editor:

Boolean String Fields

Some controls use string boolean values for dropdown options. The plugin automatically handles conversion for saved layouts:
Conversion happens in /home/daytona/workspace/source/classes/class-controls.php:421-442.

Dynamic Controls

Controls can have dynamic values loaded via AJAX:
The AJAX handler is at /home/daytona/workspace/source/classes/class-controls.php:145-187.

Live Preview System

The visual editor includes an iframe-based live preview system:

Reload on Change

Controls with reload_iframe set to true will refresh the preview when changed:

Preview Rendering

The preview is rendered using the same output system as the frontend, ensuring WYSIWYG accuracy. The gallery control is a special control type for managing images:

Custom CSS Control

The editor includes a code editor control for custom CSS:
Custom CSS is automatically encoded/decoded in /home/daytona/workspace/source/classes/class-controls.php:398-404.

Best Practices

  1. Control Names - Use descriptive, unique names with underscores (e.g., items_gap, filter_show_count)
  2. Default Values - Always provide sensible defaults for better UX
  3. Conditions - Use conditional controls to simplify the interface
  4. Categories - Organize related controls into logical categories
  5. Validation - Use sanitize_callback to validate user input
  6. Performance - Set reload_iframe to false for non-visual controls
  7. WPML Support - Enable wpml for translatable string controls

Sanitization Callbacks

Always sanitize user input:
Common sanitization functions:
  • sanitize_text_field() - For text inputs
  • sanitize_textarea_field() - For textareas
  • absint() - For positive integers
  • floatval() - For decimal numbers
  • wp_kses_post() - For HTML content