Documentation
Documentation
Graphic_Data_Validation
in package
Handles validation of custom post type fields before saving.
This class provides comprehensive validation for all custom content types in the Graphic Data plugin, including About, Scene, Modal, Figure, and Instance posts. Each validation method checks required fields, validates URLs for syntax and accessibility, and stores errors/warnings in transients for display after page reload.
Tags
Table of Contents
Methods
- check_url_is_accessible() : int
- Return HTTP status code for a given URL to check if it's accessible.
- get_fields_config() : array<string|int, mixed>
- Get fields configuration from a content type's field creation method.
- master_validate() : bool
- Routes validation to the appropriate content type validator.
- url_check() : bool
- Validates URL syntax with path requirement.
- validate_about() : bool
- Validates a post of About custom post type before saving.
- validate_figure() : bool
- Validates a post of Figure custom post type before saving.
- validate_instance() : bool
- Validates a post of Instance custom post type before saving.
- validate_modal() : bool
- Validates a post of Modal custom post type before saving.
- validate_scene() : bool
- Validates a post of Scene custom post type before saving.
Methods
check_url_is_accessible()
Return HTTP status code for a given URL to check if it's accessible.
public
check_url_is_accessible(string $url_to_be_checked) : int
Uses cURL to perform a HEAD request to the specified URL and retrieves the HTTP status code. The URL should already be validated for correct syntax before calling this method.
Parameters
- $url_to_be_checked : string
-
The URL to be checked for accessibility.
Tags
Return values
int —The HTTP status code for the URL (e.g., 200 for accessible, 404 for not found).
get_fields_config()
Get fields configuration from a content type's field creation method.
public
get_fields_config(string $content_type, object $class_instance) : array<string|int, mixed>
Retrieves the field configuration array from a content type class by calling its field creation method with a flag to return the configuration instead of creating the options panel.
Parameters
- $content_type : string
-
The custom content type (e.g., 'modal', 'scene', 'about', 'figure', 'instance').
- $class_instance : object
-
Instance of the class containing the field creation method.
Tags
Return values
array<string|int, mixed> —The fields configuration array, or empty array if method doesn't exist.
master_validate()
Routes validation to the appropriate content type validator.
public
master_validate(string $validate_content_type) : bool
Acts as a dispatcher that calls the specific validation method based on the content type being saved. Each content type has its own validation logic with specific field requirements and rules.
Parameters
- $validate_content_type : string
-
The content type to validate. Accepts 'about', 'scene', 'modal', 'figure', or 'instance'.
Tags
Return values
bool —True if validation passes, false if validation fails or content type is invalid.
url_check()
Validates URL syntax with path requirement.
public
url_check(string $input_url) : bool
Checks whether the provided URL has valid syntax according to PHP's URL validation filter. The URL must include a path component to pass validation.
Parameters
- $input_url : string
-
The URL to validate.
Tags
Return values
bool —True if the URL is valid and contains a path, false otherwise.
validate_about()
Validates a post of About custom post type before saving.
public
validate_about() : bool
Performs validation on a given About post, checking that required fields such as the central content main field and about box titles/content are filled. If validation fails, stores error messages and field values in transients for display after page reload.
Tags
Return values
bool —True if all validation passes and post can be saved, false otherwise.
Transients set on validation failure:
- 'about_errors': Array of error messages (30 second expiration)
- 'about_post_status': Set to "post_error" (30 second expiration)
- 'about_error_all_fields': Field configuration and submitted values (30 second expiration)
Transient set on validation success:
- 'about_post_status': Set to "post_good" (30 second expiration)
validate_figure()
Validates a post of Figure custom post type before saving.
public
validate_figure() : bool
Performs comprehensive validation on a given Figure post. If the validation succeeds, the function returns true, allowing the post to be saved. If any validation checks fail, it returns false and sets several transients to store error messages, warnings, and field values for display after a page reload.
Tags
Return values
bool —True if all validation passes and post can be saved, false otherwise.
Transients set on validation failure:
- 'figure_errors': Array of error messages (30 second expiration)
- 'figure_post_status': Set to "post_error" (30 second expiration)
- 'figure_error_all_fields': Field configuration and submitted values (30 second expiration)
Transient set on validation success:
- 'figure_post_status': Set to "post_good" (30 second expiration)
Transient potentially set on either validation failure or success:
- 'figure_warnings': Array of error messages (30 second expiration)
validate_instance()
Validates a post of Instance custom post type before saving.
public
validate_instance() : bool
Performs comprehensive validation on a given Instance post. If the validation succeeds, the function returns true, allowing the post to be saved. If any validation checks fail, it returns false and sets several transients to store error messages, warnings, and field values for display after a page reload.
Tags
Return values
bool —True if all validation passes and post can be saved, false otherwise.
Transients set on validation failure:
- 'instance_errors': Array of error messages (30 second expiration)
- 'instance_post_status': Set to "post_error" (30 second expiration)
- 'instance_error_all_fields': Field configuration and submitted values (30 second expiration)
Transient set on validation success:
- 'modal_post_status': Set to "post_good" (30 second expiration)
Transient potentially set on either validation failure or success:
- 'instance_warnings': Array of error messages (30 second expiration)
validate_modal()
Validates a post of Modal custom post type before saving.
public
validate_modal() : bool
Performs comprehensive validation on a given Modal post. If the validation succeeds, the function returns true, allowing the post to be saved. If any validation checks fail, it returns false and sets several transients to store error messages, warnings, and field values for display after a page reload.
Tags
Return values
bool —True if all validation passes and post can be saved, false otherwise.
Transients set on new modal post:
- 'modal_new_post': Set to "true" (30 second expiration)
Transients set on validation failure:
- 'modal_errors': Array of error messages (30 second expiration)
- 'modal_post_status': Set to "post_error" (30 second expiration)
- 'modal_error_all_fields': Field configuration and submitted values (30 second expiration)
Transient set on validation success:
- 'modal_post_status': Set to "post_good" (30 second expiration)
Transient potentially set on either validation failure or success:
- 'modal_warnings': Array of error messages (30 second expiration)
validate_scene()
Validates a post of Scene custom post type before saving.
public
validate_scene() : bool
Performs comprehensive validation on a given Scene post. If the validation succeeds, the function returns true, allowing the post to be saved. If any validation checks fail, it returns false and sets several transients to store error messages, warnings, and field values for display after a page reload.
Tags
Return values
bool —True if all validation passes and post can be saved, false otherwise.
Transients set on validation failure:
- 'scene_errors': Array of error messages (30 second expiration)
- 'scene_warnings': Array of warning messages (30 second expiration)
- 'scene_post_status': Set to "post_error" (30 second expiration)
- 'scene_error_all_fields': Field configuration and submitted values (30 second expiration)
Transient set on validation success:
- 'scene_post_status': Set to "post_good" (30 second expiration)
Transient potentially set on either validation failure or success:
- 'scene_warnings': Array of error messages (30 second expiration)