Skip to main content

Overview

Visual Portfolio provides native Gutenberg blocks that integrate seamlessly with the WordPress block editor. There are two main blocks available:
  • Visual Portfolio Block - The main block for creating galleries and portfolio layouts
  • Saved Layout Block - A block for displaying pre-configured saved layouts

Visual Portfolio Block

The main Visual Portfolio block (visual-portfolio/block) allows you to create custom galleries and portfolio layouts directly in the block editor.

Block Registration

The block is registered in /home/daytona/workspace/source/gutenberg/block/index.php:27-34:

Block Configuration

The block supports the following features as defined in block.json:

Dynamic Attributes

Block attributes are dynamically generated from registered controls in /home/daytona/workspace/source/classes/class-gutenberg.php:35-141. The system automatically converts control types to appropriate block attribute types:
  • checkbox/toggleboolean
  • number/rangenumber
  • select (multiple)array
  • galleryarray of objects
  • elements_selectorobject

Block Context

The block can receive context from parent blocks using the usesContext property:
Context is automatically transformed to attributes in /home/daytona/workspace/source/classes/class-gutenberg.php:145-178.

Loop Block

The Loop block (visual-portfolio/loop) is a container block that provides a complete portfolio structure with filters, gallery, and pagination.

Block Structure

The Loop block uses a predefined template with nested blocks:

Content Source Controls

The Loop block displays specific control categories in the sidebar:
  • content-source
  • content-source-general
  • content-source-images
  • content-source-post-based
  • content-source-social-stream
  • custom_css

Max Pages Calculation

The Loop block automatically calculates the maximum number of pages via REST API when attributes change:

Saved Layout Block

The Saved Layout block (visual-portfolio/saved-layout) displays pre-configured portfolio layouts saved as custom post types.

Block Attributes

WPML Support

The block includes WPML integration for translated layouts:

Block Editor Integration

JavaScript Assets

Block editor assets are enqueued in /home/daytona/workspace/source/classes/class-gutenberg.php:183-234:

Global Variables

The following variables are available to JavaScript via VPGutenbergVariables:
  • nonce - AJAX nonce for security
  • plugin_version - Current plugin version
  • plugin_url - Plugin URL path
  • attributes - All registered block attributes
  • controls - All registered controls
  • controls_categories - Control categories for organization

Block Render Callback

The block render callback in /home/daytona/workspace/source/gutenberg/block/index.php:45-71 processes attributes and outputs the portfolio:

Using Blocks Programmatically

Creating a Block in Code

Registering Custom Block Attributes

You can filter block attributes before registration:

Best Practices

  1. Use Context - When building nested block structures, use block context to pass data from parent to child blocks
  2. Validate Attributes - Always validate and sanitize attributes in render callbacks
  3. Cache Control Data - The plugin caches control data for performance - clear cache when modifying controls
  4. Preview Mode - Use the preview_image_example attribute to show layout previews in the block inserter
  5. Anchor Support - Enable anchor support for deep linking to specific portfolios on a page