Documentation

Graphic_Data_Transfer_Exporter
in package

Class Graphic_Data_Transfer_Exporter.

Tags
since
1.10.0

Table of Contents

Properties

$built  : bool
Whether build() has run.
$data_files  : array<string|int, array<string|int, mixed>>
Figure data files to add to the zip.
$media  : array<string, array<string|int, mixed>>
Media entries keyed by media key ('a<attachment id>' or 'f<hash>').
$media_files  : array<string, string>
Absolute paths of media files to add to the zip, keyed by zip path.
$posts  : array<int, array<string|int, mixed>>
Exported posts keyed by source post ID.
$references  : array<string|int, array<string|int, mixed>>
References from exported content to other posts.
$selection  : array<string|int, mixed>
Normalised selection (see Graphic_Data_Content_Transfer::get_selection_from_request()).
$terms  : array<int, array<string|int, mixed>>
Exported Instance Type terms keyed by source term ID.
$warnings  : array<string|int, string>
Non-fatal problems found while building the package.

Methods

__construct()  : mixed
Constructor.
build()  : true|WP_Error
Collect all content, references, media and data files for the selection.
get_collected()  : array{posts: array, terms: array, media: array, media_files: array, data_files: array[]}
Everything build() collected, for writing it in another format (see Graphic_Data_Transfer_Tsv_Exporter).
get_file_name()  : string
Suggested download file name, for example graphic-data-instances-2026-11-18.zip, graphic-data-selection-2026-11-18.zip or graphic-data-figure-sea-temps-2026-11-18.zip.
get_package_type()  : string
Package type recorded in the manifest.
get_summary()  : array<string|int, mixed>
Human-readable summary of what the package will contain, for the preview shown before downloading.
write_zip()  : true|WP_Error
Write the package to a zip file.
add_attachment()  : bool
Queue an attachment's original file and its library details.
add_media_url()  : void
Queue the file behind an uploads URL, preferring the original file of the attachment it belongs to so that all image sizes can be regenerated on the target site.
add_post()  : void
Add a post's core fields and allowlisted meta to the package.
add_reference()  : void
Record one reference if its value is a post ID.
add_term()  : void
Add an Instance Type term to the package.
collect_block_references()  : void
Record references held in Graphic Data block attributes, including blocks nested inside groups or columns.
collect_data_files()  : void
Queue a figure's source data files.
collect_instance()  : void
Add an Instance, its Instance Type, and everything assigned to it.
collect_media()  : void
Find every Media Library or uploads URL in a post's fields (including URLs embedded in rich-text HTML) and queue the files for the package.
collect_references()  : void
Record every reference from a post to another post, noting whether the target is in the package. Targets outside the package are described by title so the importer can ask the user what to link them to.
find_attachment_id()  : int
Look up the attachment for an uploads URL, including URLs of resized (-300x200) and big-image (-scaled) variants.
get_content()  : array<string|int, mixed>
Build content.json.
get_manifest()  : array<string|int, mixed>
Build manifest.json.
get_missing_parents()  : array<int, array{type: string, linkable: bool}>
Required parents (Instance, Scene, Modal) that a post will not have from this package alone. Such a post is imported as published with a Graphic Data status of Draft unless the parent is linked on import.
get_size_name()  : string
Name of the image size a URL refers to ('full' for the main file), so the importer can point it at the same size of the new attachment.
get_unique_data_files()  : array<string|int, string>
Data file paths with duplicates removed (a GeoJSON upload is stored under two meta keys).
get_uploads_url_pattern()  : string
Regular expression matching URLs inside this site's uploads folder, whether written as http, https or protocol-relative.
query_posts()  : array<string|int, int>
Find posts of a type, optionally filtered by a meta value.
resolve_inside()  : string|false
Resolve a relative path inside a base directory, refusing anything that escapes it (for example via ../).

Properties

$data_files

Figure data files to add to the zip.

private array<string|int, array<string|int, mixed>> $data_files = array()

$media

Media entries keyed by media key ('a<attachment id>' or 'f<hash>').

private array<string, array<string|int, mixed>> $media = array()

$media_files

Absolute paths of media files to add to the zip, keyed by zip path.

private array<string, string> $media_files = array()

$posts

Exported posts keyed by source post ID.

private array<int, array<string|int, mixed>> $posts = array()

$references

References from exported content to other posts.

private array<string|int, array<string|int, mixed>> $references = array()

$selection

Normalised selection (see Graphic_Data_Content_Transfer::get_selection_from_request()).

private array<string|int, mixed> $selection

$terms

Exported Instance Type terms keyed by source term ID.

private array<int, array<string|int, mixed>> $terms = array()

$warnings

Non-fatal problems found while building the package.

private array<string|int, string> $warnings = array()

Methods

__construct()

Constructor.

public __construct(array<string|int, mixed> $selection) : mixed
Parameters
$selection : array<string|int, mixed>

Normalised selection: scope ('instances' | 'selected'), plus instance_ids, include_pages and include_about for 'instances', or post_ids for 'selected'.

build()

Collect all content, references, media and data files for the selection.

public build() : true|WP_Error
Return values
true|WP_Error

get_collected()

Everything build() collected, for writing it in another format (see Graphic_Data_Transfer_Tsv_Exporter).

public get_collected() : array{posts: array, terms: array, media: array, media_files: array, data_files: array[]}
Return values
array{posts: array, terms: array, media: array, media_files: array, data_files: array[]} —

Posts and terms keyed by source ID, media keyed by media key, media file paths keyed by zip path, and data files with their figure ('post'), meta key ('field'), zip path ('file') and path ('path').

get_file_name()

Suggested download file name, for example graphic-data-instances-2026-11-18.zip, graphic-data-selection-2026-11-18.zip or graphic-data-figure-sea-temps-2026-11-18.zip.

public get_file_name() : string

A selection of one item is named after that item.

Return values
string

get_package_type()

Package type recorded in the manifest.

public get_package_type() : string

'figure' marks a single-figure package, the only kind Editors may import.

Return values
string —

'instances', 'selection' or 'figure'.

get_summary()

Human-readable summary of what the package will contain, for the preview shown before downloading.

public get_summary() : array<string|int, mixed>
Return values
array<string|int, mixed>

write_zip()

Write the package to a zip file.

public write_zip(string $zip_path) : true|WP_Error
Parameters
$zip_path : string

Absolute path of the zip file to create (overwritten).

Return values
true|WP_Error

add_attachment()

Queue an attachment's original file and its library details.

private add_attachment(int $attachment_id) : bool
Parameters
$attachment_id : int

Attachment ID.

Return values
bool —

False if the file is missing.

add_media_url()

Queue the file behind an uploads URL, preferring the original file of the attachment it belongs to so that all image sizes can be regenerated on the target site.

private add_media_url(string $url) : void
Parameters
$url : string

URL found in content.

add_post()

Add a post's core fields and allowlisted meta to the package.

private add_post(int $post_id) : void
Parameters
$post_id : int

Post ID.

add_reference()

Record one reference if its value is a post ID.

private add_reference(int $source_id, string $location, string $key, string $block, mixed $value, string $target_type) : void
Parameters
$source_id : int

Post holding the reference.

$location : string

'meta' or 'block'.

$key : string

Meta key or block attribute.

$block : string

Block name, for block references.

$value : mixed

Stored value.

$target_type : string

Post type the value points at.

add_term()

Add an Instance Type term to the package.

private add_term(int $term_id) : void
Parameters
$term_id : int

Term ID.

collect_block_references()

Record references held in Graphic Data block attributes, including blocks nested inside groups or columns.

private collect_block_references(int $source_id, array<string|int, mixed> $blocks) : void
Parameters
$source_id : int

Source page ID.

$blocks : array<string|int, mixed>

Parsed blocks.

collect_data_files()

Queue a figure's source data files.

private collect_data_files(int $source_id, array<string|int, mixed> $entry) : void

The stored paths are absolute and may come from another server (for example after a site migration), so if a path does not exist the file of the same name in this figure's data folder is used instead.

Parameters
$source_id : int

Figure post ID.

$entry : array<string|int, mixed>

Post entry.

collect_instance()

Add an Instance, its Instance Type, and everything assigned to it.

private collect_instance(int $instance_id) : void
Parameters
$instance_id : int

Instance post ID.

collect_media()

Find every Media Library or uploads URL in a post's fields (including URLs embedded in rich-text HTML) and queue the files for the package.

private collect_media(array<string|int, mixed> $entry) : void
Parameters
$entry : array<string|int, mixed>

Post entry.

collect_references()

Record every reference from a post to another post, noting whether the target is in the package. Targets outside the package are described by title so the importer can ask the user what to link them to.

private collect_references(int $source_id, array<string|int, mixed> $entry) : void
Parameters
$source_id : int

Source post ID.

$entry : array<string|int, mixed>

Post entry.

find_attachment_id()

Look up the attachment for an uploads URL, including URLs of resized (-300x200) and big-image (-scaled) variants.

private find_attachment_id(string $url) : int
Parameters
$url : string

Absolute uploads URL.

Return values
int —

Attachment ID, or 0.

get_content()

Build content.json.

private get_content() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_manifest()

Build manifest.json.

private get_manifest(array<string, string> $checksums) : array<string|int, mixed>
Parameters
$checksums : array<string, string>

SHA-256 of every file in the package, keyed by zip path.

Return values
array<string|int, mixed>

get_missing_parents()

Required parents (Instance, Scene, Modal) that a post will not have from this package alone. Such a post is imported as published with a Graphic Data status of Draft unless the parent is linked on import.

private get_missing_parents(array<string|int, mixed> $entry) : array<int, array{type: string, linkable: bool}>
Parameters
$entry : array<string|int, mixed>

Post entry.

Return values
array<int, array{type: string, linkable: bool}> —

Missing parent types. linkable is true when the parent exists on this site but is outside the package, so it can be linked on import; false when the post has no parent at all.

get_size_name()

Name of the image size a URL refers to ('full' for the main file), so the importer can point it at the same size of the new attachment.

private get_size_name(int $attachment_id, string $relative) : string
Parameters
$attachment_id : int

Attachment ID.

$relative : string

Path of the URL relative to the uploads folder.

Return values
string

get_unique_data_files()

Data file paths with duplicates removed (a GeoJSON upload is stored under two meta keys).

private get_unique_data_files() : array<string|int, string>
Return values
array<string|int, string>

get_uploads_url_pattern()

Regular expression matching URLs inside this site's uploads folder, whether written as http, https or protocol-relative.

private get_uploads_url_pattern() : string
Return values
string

query_posts()

Find posts of a type, optionally filtered by a meta value.

private query_posts(string $post_type[, string $meta_key = '' ][, int|string $meta_value = '' ]) : array<string|int, int>
Parameters
$post_type : string

Post type.

$meta_key : string = ''

Optional meta key to match.

$meta_value : int|string = ''

Value the meta key must equal.

Return values
array<string|int, int> —

Post IDs.

resolve_inside()

Resolve a relative path inside a base directory, refusing anything that escapes it (for example via ../).

private resolve_inside(string $base, string $relative) : string|false
Parameters
$base : string

Base directory.

$relative : string

Relative path.

Return values
string|false —

Real path of an existing file, or false.

On this page

Search results