import-export.php
Import and export
Export downloads the stored settings as JSON; import takes an uploaded file or pasted JSON, validates every value through the settings store and writes through it. The export carries no site address and no user data, so a file can move between sites as it is.
Tags
Table of Contents
Constants
- JPKCOM_HARDEN_TRIM_IMPORT_MAX_BYTES : mixed = 65536
- Largest import accepted, in bytes (64 KB).
Functions
- jpkcom_harden_trim_import_max_size() : string
- The import limit as the settings page names it ("64 KB").
-
jpkcom_harden_trim_export_payload()
: array{plugin: string, schema: int, version: string, settings: array
} - The export document.
- jpkcom_harden_trim_export_headers() : array<string, string>
- HTTP headers of the export download (besides nocache_headers()).
- jpkcom_harden_trim_handle_export() : void
- Send the export download (admin_post_jpkcom_harden_trim_export).
- jpkcom_harden_trim_import_error_message() : string
- The message for an import error code.
-
jpkcom_harden_trim_parse_import()
: array{settings: array
, applied: list , rejected: list }|WP_Error - Validate an import and merge it over the stored settings (writes nothing).
- jpkcom_harden_trim_import_source() : string|WP_Error
- The raw import from the request: an uploaded file, else pasted JSON.
- jpkcom_harden_trim_handle_import() : void
- Import settings (admin_post_jpkcom_harden_trim_import).
- jpkcom_harden_trim_render_import_export() : void
- The import / export section of the settings page.
Constants
JPKCOM_HARDEN_TRIM_IMPORT_MAX_BYTES
Largest import accepted, in bytes (64 KB).
public
mixed
JPKCOM_HARDEN_TRIM_IMPORT_MAX_BYTES
= 65536
An export of every setting is about 1.5 KB.
Tags
Functions
jpkcom_harden_trim_import_max_size()
The import limit as the settings page names it ("64 KB").
jpkcom_harden_trim_import_max_size() : string
Follows JPKCOM_HARDEN_TRIM_IMPORT_MAX_BYTES, which wp-config.php may set.
Tags
Return values
string —Formatted size.
jpkcom_harden_trim_export_payload()
The export document.
jpkcom_harden_trim_export_payload() : array{plugin: string, schema: int, version: string, settings: array}
Stored values only: no constant, no filter, no site URL, no user data.
Tags
Return values
array{plugin: string, schema: int, version: string, settings: arrayjpkcom_harden_trim_export_headers()
HTTP headers of the export download (besides nocache_headers()).
jpkcom_harden_trim_export_headers() : array<string, string>
The date in the filename is UTC, as in the other family plugins.
Tags
Return values
array<string, string> —Header name => value.
jpkcom_harden_trim_handle_export()
Send the export download (admin_post_jpkcom_harden_trim_export).
jpkcom_harden_trim_handle_export() : void
Tags
jpkcom_harden_trim_import_error_message()
The message for an import error code.
jpkcom_harden_trim_import_error_message(string $code) : string
Only codes listed here produce text, so a code that reaches the notice from anywhere else shows nothing.
Parameters
- $code : string
-
Error code.
Tags
Return values
string —Translated message, '' for an unknown code.
jpkcom_harden_trim_parse_import()
Validate an import and merge it over the stored settings (writes nothing).
jpkcom_harden_trim_parse_import(string $raw) : array{settings: array, applied: list, rejected: list}|WP_Error
Every key in the file goes through the settings sanitiser on its own:
a valid value is applied, an unknown key or an invalid value is rejected
and the stored value stays, role slugs that do not exist on this site are
dropped and reported as <key>:<slug>. Keys missing from the file keep
their stored value.
Parameters
- $raw : string
-
File or pasted content.
Tags
Return values
array{settings: arrayComplete settings to store, or an error with code too_large, invalid_json, wrong_plugin, unsupported_schema or no_settings.
jpkcom_harden_trim_import_source()
The raw import from the request: an uploaded file, else pasted JSON.
jpkcom_harden_trim_import_source() : string|WP_Error
A file wins over pasted text. The upload is only read when PHP itself
received it (is_uploaded_file()); the client's file name and MIME type
are never trusted.
Tags
Return values
string|WP_Error —Raw content, or an error with code no_input, upload_failed or too_large.
jpkcom_harden_trim_handle_import()
Import settings (admin_post_jpkcom_harden_trim_import).
jpkcom_harden_trim_handle_import() : void
A failed import writes nothing and names the reason. A successful one stores every applied value, locked keys included; the notice counts the applied and rejected entries, lists the keys that changed, the rejected ones and the locked ones whose constant still wins.
Tags
jpkcom_harden_trim_render_import_export()
The import / export section of the settings page.
jpkcom_harden_trim_render_import_export() : void