Documentation
Documentation
Graphic_Data_Scene
in package
Manages the Scene custom post type and its admin interface.
Handles registration of the Scene post type, custom meta fields, REST API integration, admin list table columns and filters, permalink rewriting, Quick Edit validation, and bulk/row action customization.
Tags
Table of Contents
Methods
- add_scene_rewrite_rules() : array<string|int, mixed>
- Add custom rewrite rules for scene permalinks.
- change_scene_columns() : array<string|int, mixed>
- Set custom columns for the Scene post type admin list table.
- cleanup_expired_scene_filters() : void
- Clean up expired scene filter values in user metadata.
- create_scene_fields() : mixed
- Create custom fields, using metaboxes, for Scene custom content type.
- custom_content_type_scene() : mixed
- Create Scene custom content type.
- custom_scene_column() : mixed
- Populate custom fields for Scene content type in the admin screen.
- display_overview_scene_notice() : mixed
- Display an admin notice if the current scene is the overview scene for its instance.
- enqueue_scene_admin_columns_css() : void
- Enqueues custom CSS for scene admin columns on the post type edit screen.
- filter_scene_by_scene_location() : array<string|int, mixed>
- Filter REST API queries for scenes by the "scene_location" meta field.
- get_scene_filter_value() : bool|string|int
- Check if stored filter values are still valid and retrieve them if they are.
- graphic_data_svg_cleanup_on_upload() : array<string|int, mixed>
- Clean up Inkscape-generated SVGs after WordPress handles the upload.
- graphic_data_transform_svg_inkscape() : string
- Transform Inkscape-specific attributes in an SVG string.
- modify_scene_quick_edit_link() : array<string|int, string>
- Renames the Quick Edit row action link for the Scene post type.
- orderby_status_column() : void
- Modifies the main WordPress query to enable sorting by the last modified date.
- register_scene_rest_fields() : mixed
- Register Scene custom fields for use by REST API.
- register_status_as_sortable_column() : array<string|int, mixed>
- Registers the "status" column as sortable in the Scene, Modal, and Figure custom post admin lists.
- remove_bulk_actions() : mixed
- Remove Bulk Actions dropdown from Scene, Modal, Figure, and Instance admin screens.
- remove_scene_slug() : string
- Rewrite the permalink for scene posts to use the instance slug.
- scene_enqueue_quick_edit_validation() : void
- Enqueues the Quick Edit slug validation script on the Scene list table screen.
- scene_filter_dropdowns() : void
- Add filter dropdowns for the Scene admin screen with persistent selection support.
- scene_location_filter_results() : void
- Filter the Scene admin screen results based on selected or stored filter values.
- scene_remove_quick_edit_link() : mixed
- Remove Quick Edit links from Scene admin screen.
- scene_validate_slug_ajax() : void
- AJAX handler that checks whether a scene post slug is already in use.
- store_scene_filter_values() : void
- Store filter values in user metadata with 20-minute expiration.
- string_truncate() : mixed
- Shorten string without cutting words midword.
Methods
add_scene_rewrite_rules()
Add custom rewrite rules for scene permalinks.
public
add_scene_rewrite_rules(array<string|int, mixed> $rules) : array<string|int, mixed>
Prepends a rewrite rule that maps a two-segment URL structure ({instance_slug}/{scene_slug}) to the scene post type. The new rule is added before the existing rules so it takes priority.
Intended as a callback for the 'rewrite_rules_array' filter.
Parameters
- $rules : array<string|int, mixed>
-
The existing WordPress rewrite rules.
Tags
Return values
array<string|int, mixed> —Modified rewrite rules with the scene rule prepended.
change_scene_columns()
Set custom columns for the Scene post type admin list table.
public
change_scene_columns(array<string|int, mixed> $columns) : array<string|int, mixed>
Replaces the default WordPress admin columns with custom columns specific to the Scene custom post type, including scene location, infographic, tagline, order, and overview information.
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 Scene-specific columns:
- 'title': Scene title
- 'scene_location': Associated instance/location
- 'scene_infographic': Linked infographic
- 'scene_tagline': Scene tagline text
- 'scene_order': Display order number
- 'scene_overview': Scene overview content
- 'status': Publication status
cleanup_expired_scene_filters()
Clean up expired scene filter values in user metadata.
public
cleanup_expired_scene_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_scene_fields()
Create custom fields, using metaboxes, for Scene custom content type.
public
create_scene_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_scene()
Create Scene custom content type.
public
custom_content_type_scene() : mixed
Tags
custom_scene_column()
Populate custom fields for Scene content type in the admin screen.
public
custom_scene_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
display_overview_scene_notice()
Display an admin notice if the current scene is the overview scene for its instance.
public
display_overview_scene_notice() : mixed
Tags
enqueue_scene_admin_columns_css()
Enqueues custom CSS for scene admin columns on the post type edit screen.
public
enqueue_scene_admin_columns_css(string $hook) : void
This function conditionally loads CSS styling for the admin columns display when viewing the list of 'scene' 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_scene_by_scene_location()
Filter REST API queries for scenes by the "scene_location" meta field.
public
filter_scene_by_scene_location(array<string|int, mixed> $args, WP_REST_Request $request) : array<string|int, mixed>
Appends a LIKE meta_query clause to the WP_Query arguments when the 'scene_location' parameter is present in the REST request, enabling partial-match filtering on the scene_location post meta value.
Intended as a callback for the 'rest_scene_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 with the meta_query clause appended when the scene_location parameter is set.
get_scene_filter_value()
Check if stored filter values are still valid and retrieve them if they are.
public
get_scene_filter_value(string $meta_key) : bool|string|int
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|int —False if expired or not found, the value if still valid.
graphic_data_svg_cleanup_on_upload()
Clean up Inkscape-generated SVGs after WordPress handles the upload.
public
graphic_data_svg_cleanup_on_upload(array<string|int, mixed> $upload, string $context) : array<string|int, mixed>
Hooked to wp_handle_upload, this function reads the uploaded file,
checks whether it is an SVG containing Inkscape-specific markup, and
if so, transforms it in-place using graphic_data_transform_svg_inkscape().
Non-SVG files and SVGs without Inkscape attributes are returned untouched.
Parameters
- $upload : array<string|int, mixed>
-
{ Array of upload data from WordPress.
@type string $file Full path to the uploaded file. @type string $url URL of the uploaded file. @type string $type MIME type of the uploaded file.}
- $context : string
-
The type of upload action. Accepts 'upload' or 'sideload'.
Return values
array<string|int, mixed> —The (possibly modified) upload data array.
graphic_data_transform_svg_inkscape()
Transform Inkscape-specific attributes in an SVG string.
public
graphic_data_transform_svg_inkscape(string $svg) : string
Replaces the id attribute value with the inkscape:label value on elements that have both attributes.
Parameters
- $svg : string
-
The raw SVG markup.
Return values
string —The transformed SVG markup.
modify_scene_quick_edit_link()
Renames the Quick Edit row action link for the Scene post type.
public
modify_scene_quick_edit_link(array<string|int, string> $actions, WP_Post $post) : array<string|int, string>
Replaces the default "Quick Edit" label with "Edit Scene Title or URL" in the row actions on the Scene admin list table. Intended for use with the 'post_row_actions' filter.
Parameters
- $actions : array<string|int, string>
-
Associative array of row action links.
- $post : WP_Post
-
The post object for the current row.
Tags
Return values
array<string|int, string> —The modified row actions array.
orderby_status_column()
Modifies the main WordPress query to enable sorting by the last modified date.
public
orderby_status_column(WP_Query $query) : void
This function ensures that when sorting is triggered by the "status" column,
WordPress orders the Scene, Modal, or Figure posts based on the post_modified field in ascending
or descending order, depending on user selection.
Parameters
- $query : WP_Query
-
The current query instance.
register_scene_rest_fields()
Register Scene custom fields for use by REST API.
public
register_scene_rest_fields() : mixed
Tags
register_status_as_sortable_column()
Registers the "status" column as sortable in the Scene, Modal, and Figure custom post admin lists.
public
register_status_as_sortable_column(array<string|int, mixed> $sortable_columns) : array<string|int, mixed>
Parameters
- $sortable_columns : array<string|int, mixed>
-
An array of sortable columns.
Return values
array<string|int, mixed> —Modified array with the "status" column set as sortable by "modified".
remove_bulk_actions()
Remove Bulk Actions dropdown from Scene, Modal, Figure, and Instance admin screens.
public
remove_bulk_actions(array<string|int, mixed> $actions) : mixed
Parameters
- $actions : array<string|int, mixed>
-
An array of the available bulk actions.
Tags
remove_scene_slug()
Rewrite the permalink for scene posts to use the instance slug.
public
remove_scene_slug(string $post_link, WP_Post $post, bool $leavename) : string
Replaces the default scene permalink with a custom structure: {home_url}/{instance_slug}/{scene_slug}/
The instance slug is derived from the 'instance_slug' meta field of the instance post assigned via the scene's 'scene_location' meta. Returns the original link unchanged if the post is not a published scene or the associated instance data is missing.
Intended as a callback for the 'post_type_link' filter.
Parameters
- $post_link : string
-
The default permalink for the post.
- $post : WP_Post
-
The current post object.
- $leavename : bool
-
Whether to keep the post name or use a placeholder.
Tags
Return values
string —The modified permalink, or the original if conditions are not met.
scene_enqueue_quick_edit_validation()
Enqueues the Quick Edit slug validation script on the Scene list table screen.
public
scene_enqueue_quick_edit_validation(string $hook) : void
Loads scene-quick-edit-validation.js (dependent on inline-edit-post) and
localizes it with the AJAX URL, a nonce for slug validation, and user-facing
messages. Only enqueued on the edit.php screen for the 'scene' post type.
Parameters
- $hook : string
-
The current admin page hook suffix.
Tags
scene_filter_dropdowns()
Add filter dropdowns for the Scene admin screen with persistent selection support.
public
scene_filter_dropdowns() : void
This function creates and outputs filter dropdowns for field length and instance on the Scene 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. This function handles proper user capability checks to show only assigned instances for content editors.
Tags
scene_location_filter_results()
Filter the Scene admin screen results based on selected or stored filter values.
public
scene_location_filter_results(WP_Query $query) : void
This function modifies the WordPress query to filter Scene posts based on the selected location (instance) 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
scene_remove_quick_edit_link()
Remove Quick Edit links from Scene admin screen.
public
scene_remove_quick_edit_link(array<string|int, string> $actions, int $post) : mixed
Parameters
- $actions : array<string|int, string>
-
An array of row action links.
- $post : int
-
The database id of the post.
Tags
scene_validate_slug_ajax()
AJAX handler that checks whether a scene post slug is already in use.
public
scene_validate_slug_ajax() : void
Validates the nonce from the Quick Edit validation script, then queries the
database for an existing scene post with the given slug (excluding the current
post and trashed posts). Returns a JSON success response with exists: true
and the conflicting post's ID and title if a duplicate is found, or
exists: false if the slug is available. Sends a JSON error if the slug is empty.
Expects $_POST['slug'] (the slug to check) and $_POST['post_id'] (the
current post ID to exclude from the check).
Tags
Return values
void —Outputs JSON response and terminates execution.
store_scene_filter_values()
Store filter values in user metadata with 20-minute expiration.
public
store_scene_filter_values() : void
This function captures the current Scene filter selections from the URL parameters and stores them in user metadata with a 20-minute expiration timestamp. It only runs on the Scene post type admin screen and requires a logged-in user.
Tags
string_truncate()
Shorten string without cutting words midword.
public
string_truncate(string $string, int $your_desired_width) : mixed
Parameters
- $string : string
-
The string to be shortened.
- $your_desired_width : int
-
The number of characters in the shortened string.