Documentation

Graphic_Data_Search
in package

Class Graphic_Data_Search

Registers and renders the "Search All Content" top-level admin page.

Tags
since
1.0.0

Table of Contents

Properties

$instance_meta_keys  : array<string, string>
Maps post type to the postmeta key that stores the related Instance post ID.
$instance_title_cache  : array<int, string>
In-request cache of resolved Instance titles, keyed by Instance post ID.
$post_types  : array<string|int, string>
Custom post types included in the search.

Methods

init()  : void
Hook the admin menu registration.
register_menu()  : void
Register "Search All Content" as a top-level admin menu page.
render_page()  : void
Render the search form and results table.
filter_by_assigned_instances()  : array<string|int, array<string|int, mixed>>
Filter results down to only those whose Instance is in the current user's assigned list.
get_instance_id()  : int
Resolve the Instance post ID for a single result row.
get_instance_title()  : string
Resolve the Instance display title for a single result row.
is_restricted_author()  : bool
Determine whether the current user should be restricted to their assigned Instances.
search_content()  : array<string|int, array<string|int, mixed>>
Search post titles and postmeta values for the given term.
sort_results()  : void
Sort the results array in place by the requested column and direction.
sortable_column_header()  : void
Output a single <th> with a sort toggle link, preserving the current search term.

Properties

$instance_meta_keys

Maps post type to the postmeta key that stores the related Instance post ID.

private static array<string, string> $instance_meta_keys = array('scene' => 'scene_location', 'modal' => 'modal_location', 'figure' => 'location')

The 'about' type has no Instance relationship, and 'instance' posts are their own Instance, so neither appears here.

Tags
since
1.0.0

$instance_title_cache

In-request cache of resolved Instance titles, keyed by Instance post ID.

private static array<int, string> $instance_title_cache = array()

Avoids repeated get_the_title() calls when multiple results share an Instance.

Tags
since
1.0.0

$post_types

Custom post types included in the search.

private static array<string|int, string> $post_types = array('about', 'instance', 'scene', 'modal', 'figure')
Tags
since
1.0.0

Methods

init()

Hook the admin menu registration.

public static init() : void
Tags
since
1.0.0

register_menu()

Register "Search All Content" as a top-level admin menu page.

public static register_menu() : void
Tags
since
1.0.0

render_page()

Render the search form and results table.

public static render_page() : void

Reads the search term and sort parameters from $_GET, runs the query, resolves each row's Instance value, applies the Author instance-assignment restriction, sorts in PHP, and outputs the admin markup with sortable column headers.

Tags
since
1.0.0

filter_by_assigned_instances()

Filter results down to only those whose Instance is in the current user's assigned list.

private static filter_by_assigned_instances(array<string|int, array<string|int, mixed>> $results) : array<string|int, array<string|int, mixed>>

Reads 'assigned_instances' from wp_usermeta for the current user, which is expected to be an array of Instance post IDs. Rows with no Instance (e.g. 'about' posts, or an unresolved location meta) are excluded, since they cannot be matched to an assignment.

Parameters
$results : array<string|int, array<string|int, mixed>>

Results array, each row containing an 'instance_id' key.

Tags
since
1.0.0
Return values
array<string|int, array<string|int, mixed>>

Filtered results.

get_instance_id()

Resolve the Instance post ID for a single result row.

private static get_instance_id(int $post_id, string $post_type) : int

Behavior varies by post type:

  • about: no Instance relationship, always returns 0.
  • instance: the post IS an Instance, so its own ID is returned.
  • scene: resolved via the 'scene_location' postmeta.
  • modal: resolved via the 'modal_location' postmeta.
  • figure: resolved via the 'location' postmeta.
Parameters
$post_id : int

The result row's post ID.

$post_type : string

The result row's post type.

Tags
since
1.0.0
Return values
int

Instance post ID, or 0 if not applicable/not found.

get_instance_title()

Resolve the Instance display title for a single result row.

private static get_instance_title(int $instance_id, string $post_type, string $current_title) : string
Parameters
$instance_id : int

Instance post ID as resolved by get_instance_id().

$post_type : string

The result row's post type.

$current_title : string

The result row's own title (used when post type is 'instance').

Tags
since
1.0.0
Return values
string

Instance title, or empty string if not applicable/not found.

is_restricted_author()

Determine whether the current user should be restricted to their assigned Instances.

private static is_restricted_author() : bool

Restriction applies to users holding the 'author' role who do not also hold a higher-privilege role (administrator or editor), so an Author who has additionally been granted Editor is not restricted.

Tags
since
1.0.0
Return values
bool

True if the current user should be limited to assigned Instances.

search_content()

Search post titles and postmeta values for the given term.

private static search_content(string $search_term) : array<string|int, array<string|int, mixed>>

Runs a single query joining wp_posts to wp_postmeta so both the title and any custom field value can match. DISTINCT is required because a post typically has many postmeta rows, and without it a single matching post would be returned once per matching row.

Parameters
$search_term : string

Sanitized search term (raw text, not yet LIKE-escaped).

Tags
since
1.0.0
Return values
array<string|int, array<string|int, mixed>>

{ Indexed array of matching post rows.

@type int    $ID        Post ID.
@type string $title     Post title (may be empty).
@type string $post_type Post type slug.

}

sort_results()

Sort the results array in place by the requested column and direction.

private static sort_results(array<string|int, array<string|int, mixed>> &$results, string $orderby, string $order) : void

Sorting is done in PHP rather than SQL because the Instance value is resolved after the initial query (it requires a per-row postmeta lookup and, for scene/modal/figure, a second post title lookup).

Parameters
$results : array<string|int, array<string|int, mixed>>

Results array, passed by reference. Each row has 'ID', 'title', 'post_type', 'instance_id', 'instance' keys.

$orderby : string

One of 'title', 'post_type', 'instance'.

$order : string

'asc' or 'desc'.

Tags
since
1.0.0

sortable_column_header()

Output a single <th> with a sort toggle link, preserving the current search term.

private static sortable_column_header(string $label, string $column_key, string $search_term, string $orderby, string $order) : void
Parameters
$label : string

Visible column label.

$column_key : string

Key used in the orderby query arg (must be in $allowed_orderby).

$search_term : string

Current search term, preserved across the sort link.

$orderby : string

Currently active orderby column.

$order : string

Currently active order ('asc'|'desc').

Tags
since
1.0.0
On this page

Search results