Documentation
Documentation
Graphic_Data_Modal
in package
Manages the Modal custom post type and its admin interface.
Handles registration of the Modal post type, custom meta fields, REST API integration, admin list table columns and filters, tab/figure validation warnings, and filter persistence via user metadata.
Tags
Table of Contents
Methods
- change_modal_columns() : array<string|int, mixed>
- Set custom columns for the Modal post type admin list table.
- cleanup_expired_modal_filters() : void
- Clean up expired modal filter values in user metadata.
- create_modal_fields() : mixed
- Create custom fields, using metaboxes, for Modal custom content type.
- custom_content_type_modal() : mixed
- Create Modal custom content type.
- custom_modal_column() : mixed
- Populate custom fields for Modal content type in the admin screen.
- enqueue_modal_admin_columns_css() : void
- Enqueues custom CSS for modal admin columns on the post type edit screen.
- filter_modal_by_modal_scene() : array<string|int, mixed>
- Filter REST API queries for modals by scene and icon function.
- get_modal_filter_value() : bool|string
- Check if stored filter values are still valid and retrieve them if they are.
- modal_filter_dropdowns() : void
- Add filter dropdowns for the Modal admin screen with persistent selection support.
- modal_location_filter_results() : void
- Filter the Modal admin screen results based on selected or stored filter values.
- modal_warning_notice_tabs() : void
- Display warning notices on the Modal edit screen if tabs lack content.
- register_modal_rest_fields() : mixed
- Register Modal custom fields for use by REST API.
- store_modal_filter_values() : void
- Store filter values in user metadata with 20-minute expiration.
Methods
change_modal_columns()
Set custom columns for the Modal post type admin list table.
public
change_modal_columns(array<string|int, mixed> $columns) : array<string|int, mixed>
Replaces the default WordPress admin columns with custom columns specific to the Modal custom post type, including instance, scene, icon, function, tagline, tabs, and status information.
Intended as a callback for the 'manage_modal_posts_columns' filter.
Parameters
- $columns : array<string|int, mixed>
-
Default WordPress admin columns array where keys are column IDs and values are column labels.
Tags
Return values
array<string|int, mixed> —Modified columns array with custom Modal-specific columns.
cleanup_expired_modal_filters()
Clean up expired modal filter values in user metadata.
public
cleanup_expired_modal_filters() : void
This function runs on admin page load and checks if any stored filter values have exceeded their 20-minute expiration time. Any expired values are removed from the database to maintain clean user metadata and prevent stale filters from being applied.
Tags
create_modal_fields()
Create custom fields, using metaboxes, for Modal custom content type.
public
create_modal_fields([bool $return_fields_only = false ]) : mixed
Parameters
- $return_fields_only : bool = false
-
If true, only return the custom fields array without registering the metabox (used as part of field validation).
Tags
custom_content_type_modal()
Create Modal custom content type.
public
custom_content_type_modal() : mixed
Tags
custom_modal_column()
Populate custom fields for Modal content type in the admin screen.
public
custom_modal_column(string $column, int $post_id) : mixed
Parameters
- $column : string
-
The name of the column.
- $post_id : int
-
The database id of the post.
Tags
enqueue_modal_admin_columns_css()
Enqueues custom CSS for modal admin columns on the post type edit screen.
public
enqueue_modal_admin_columns_css(string $hook) : void
This function conditionally loads CSS styling for the admin columns display when viewing the list of 'modal' custom post type entries in the WordPress admin. The CSS is only enqueued when on the edit.php screen for the modal post type.
Parameters
- $hook : string
-
The current admin page hook suffix.
Tags
filter_modal_by_modal_scene()
Filter REST API queries for modals by scene and icon function.
public
filter_modal_by_modal_scene(array<string|int, mixed> $args, WP_REST_Request $request) : array<string|int, mixed>
Appends meta_query clauses to the WP_Query arguments when the 'modal_scene' and/or 'icon_function' parameters are present in the REST request. Results are always ordered alphabetically by title.
Intended as a callback for the 'rest_modal_query' filter.
Parameters
- $args : array<string|int, mixed>
-
The WP_Query arguments for the REST request.
- $request : WP_REST_Request
-
The current REST API request object.
Tags
Return values
array<string|int, mixed> —Modified query arguments, ordered by title ascending.
get_modal_filter_value()
Check if stored filter values are still valid and retrieve them if they are.
public
get_modal_filter_value(string $meta_key) : bool|string
This function retrieves a stored filter value from user metadata and verifies if it has exceeded its expiration time. If the value has expired, it cleans up the metadata entries and returns false. Otherwise, it returns the stored value.
Parameters
- $meta_key : string
-
The meta key to check expiration for.
Tags
Return values
bool|string —False if expired or not found, the value if still valid.
modal_filter_dropdowns()
Add filter dropdowns for the Modal admin screen with persistent selection support.
public
modal_filter_dropdowns() : void
This function creates and outputs filter dropdowns for field length, instance, and scene on the Modal post type admin screen. It first checks for filter values in the URL parameters, then falls back to stored user metadata values if they haven't expired. After displaying the dropdowns, it stores the current selections for future use.
Tags
modal_location_filter_results()
Filter the Modal admin screen results based on selected or stored filter values.
public
modal_location_filter_results(WP_Query $query) : void
This function modifies the WordPress query to filter Modal posts based on the selected location (instance) and scene values. It first checks for values in the URL parameters, then falls back to stored user metadata values that haven't expired. This ensures filter persistence for 20 minutes across page loads.
Parameters
- $query : WP_Query
-
The WordPress Query instance being filtered.
Tags
modal_warning_notice_tabs()
Display warning notices on the Modal edit screen if tabs lack content.
public
modal_warning_notice_tabs() : void
Checks each configured tab in a modal post to verify it has associated published figures. Displays admin warnings for tabs that either have no figures assigned or only have draft figures.
Skips warning display when:
- Not on a post edit screen
- Post type is not 'modal'
- Creating a new post (not editing existing)
- Post was just created (detected via transient)
Tags
Return values
void —Early returns if conditions for displaying warnings are not met.
register_modal_rest_fields()
Register Modal custom fields for use by REST API.
public
register_modal_rest_fields() : mixed
Tags
store_modal_filter_values()
Store filter values in user metadata with 20-minute expiration.
public
store_modal_filter_values() : void
This function captures the current filter selections from the URL parameters and stores them in user metadata with a 20-minute expiration timestamp. It only runs on the Modal post type admin screen and requires a logged-in user.