Skip to main content
This page documents the REST API endpoints provided by Visual Portfolio for dynamic content loading and portfolio management.

Base URL

All endpoints are prefixed with:
Namespace: visual-portfolio/v1

Endpoints

Get Layouts List

Retrieve a list of all saved portfolio layouts. Endpoint: GET /get_layouts/ Permission: edit_posts Response:
Error Response:
Example:

Update Layout Data

Update portfolio layout configuration. Endpoint: POST /update_layout/ Permission: edit_post (for the specific post) Parameters:
  • post_id (integer, required) - Portfolio post ID
  • data (object, required) - Layout configuration data
Request Body:
Response:
Error Response:
Example:

Get Filter Items

Retrieve filter items for a portfolio based on content source. Endpoint: POST /get_filter_items/ Permission: edit_posts Parameters:
  • content_source (string, required) - Content source type (‘post-based’, ‘images’)
  • post_id (integer, required) - Current post ID for URL generation
  • Additional parameters based on content source
For post-based content:
  • posts_source (string) - Posts source
  • post_types_set (array) - Post types to include
  • posts_taxonomies (object) - Taxonomy filters
  • posts_order_by (string) - Order by field
  • posts_order_direction (string) - Order direction
For images content:
  • images (array) - Array of image IDs
  • images_order_by (string) - Order by field
Request Body:
Response:
Error Response:
Example:

Get Max Pages

Calculate the maximum number of pages for pagination. Endpoint: GET|POST /get-max-pages/ Permission: edit_posts Parameters:
  • content_source (string, required) - Content source type
  • items_count (integer, required) - Number of items per page
  • Additional content-specific parameters
Query String (GET):
Request Body (POST):
Response:
Example (GET):
Example (POST):

Update the visibility state of the gallery items count notice. Endpoint: POST /update_gallery_items_count_notice_state/ Permission: manage_options and edit_post Parameters:
  • post_id (integer, required) - Portfolio post ID
  • notice_state (string, required) - Notice state value
Request Body:
Response:

PHP Implementation

Accessing REST Endpoints in PHP

You can make internal REST API requests using WordPress functions. Example:

Making External API Calls

Using wp_remote_post:

JavaScript Helper Functions

Making Authenticated Requests

With nonce authentication:
Using jQuery with WordPress AJAX:

Error Handling

Common Error Codes

  • not_allowed - User lacks required permissions
  • missing_params - Required parameters not provided
  • no_layouts_found - No portfolio layouts exist
  • invalid_content_source - Invalid content source specified
  • post_id_required - Post ID parameter missing
  • user_dont_have_permission - User lacks specific permission

Error Response Format

All error responses follow this structure:

Handling Errors

JavaScript:
PHP:

Security

Permission Checks

All endpoints implement WordPress capability checks:
  • edit_posts - Required for reading layouts and filters
  • edit_post - Required for updating specific layouts
  • manage_options - Required for plugin settings

Nonce Verification

When making requests from the frontend, include the nonce:

Data Sanitization

All input data is sanitized using:
  • sanitize_text_field() - For text inputs
  • intval() - For integer values
  • Visual_Portfolio_Security::sanitize_attributes() - For attribute arrays
  • Visual_Portfolio_Security::validate_calculate_max_pages_params() - For pagination params