JPKCom Harden & Trim

JPKCom_Harden_Trim_CLI
in package

FinalYes

Inspect and change the JPKCom Harden & Trim settings of a site.

EXAMPLES

What every switch does on this site, and why

$ wp harden-trim status

Switch one setting

$ wp harden-trim set heartbeat optimized

Apply a preset, first as a dry run

$ wp harden-trim preset recommended --dry-run

Copy the settings from one site to another

$ wp harden-trim export --file=harden-trim.json $ wp --url=https://example.org harden-trim import harden-trim.json

Tags
since
1.2.0

Table of Contents

Methods

export()  : void
Export the stored settings as JSON.
get()  : void
Print the effective value of one setting.
import()  : void
Import settings from an export.
preset()  : void
Apply a preset.
presets()  : void
List the presets and what each one would change on this site.
reset()  : void
Set settings back to their default.
set()  : void
Change one setting.
status()  : void
Show what every setting does on this site, and why.
accepted_values()  : string
Describe the values a key accepts.
block_theme_unavailable()  : bool
Whether a key is unavailable because the active theme is a block theme.
flag()  : bool
A boolean flag the WP-CLI way: --flag is true, --no-flag is false.
format_value()  : string
Format a setting value the way `set` accepts it.
parse_value()  : mixed
Turn a command-line value into a validated setting value, or stop.
printable_row()  : array<string, mixed>
A status row with every value printable in a table.
refuse_block_theme()  : void
Stop with an error for a key the settings page does not offer with a block theme.
refuse_locked()  : void
Stop with an error when a key is locked by a constant.
require_key()  : string
Validate a key or stop with an error.
write()  : void
Store values over the current stored settings and report the changes.

Methods

export()

Export the stored settings as JSON.

public export(array<int, string> $args, array<string, string> $assoc_args) : void

The same document the settings page downloads: stored values only, no constant, no filter, no site URL, no user data.

OPTIONS

[--file=] : Write to this file instead of standard output.

[--force] : Overwrite the file if it exists.

EXAMPLES

$ wp harden-trim export > harden-trim.json
$ wp harden-trim export --file=harden-trim.json
Parameters
$args : array<int, string>

Positional arguments (none).

$assoc_args : array<string, string>

Associative arguments.

Tags
since
1.2.0

get()

Print the effective value of one setting.

public get(array<int, string> $args, array<string, string> $assoc_args) : void

OPTIONS

: Setting key, as listed by `wp harden-trim status`.

[--format=] : plain prints the value as set accepts it; json prints it as JSON.

default: plain options:

  • plain
  • json

EXAMPLES

$ wp harden-trim get heartbeat
optimized
Parameters
$args : array<int, string>

Key.

$assoc_args : array<string, string>

Associative arguments.

Tags
since
1.2.0

import()

Import settings from an export.

public import(array<int, string> $args, array<string, string> $assoc_args) : void

Same rules as the settings page: every key is validated on its own, keys missing from the file keep their stored value, and settings locked by a constant are stored as the file says while the constant still wins.

OPTIONS

: Export file, or `-` to read standard input.

[--dry-run] : Report what would change, but write nothing.

EXAMPLES

$ wp harden-trim import harden-trim.json --dry-run
$ cat harden-trim.json | wp harden-trim import -
Parameters
$args : array<int, string>

File.

$assoc_args : array<string, string>

Associative arguments.

Tags
since
1.2.0

preset()

Apply a preset.

public preset(array<int, string> $args, array<string, string> $assoc_args) : void

Assigns every setting a preset manages (the preset's value, or the default where the preset lists none). Settings locked by a constant, role lists, application passwords, HSTS, feed discovery, comments, block library CSS and global styles are never touched.

OPTIONS

: Preset name. --- options: - harmless - recommended - strict ---

[--dry-run] : Report the changes, but write nothing.

EXAMPLES

$ wp harden-trim preset recommended --dry-run
$ wp harden-trim preset recommended
Parameters
$args : array<int, string>

Preset name.

$assoc_args : array<string, string>

Associative arguments.

Tags
since
1.2.0

presets()

List the presets and what each one would change on this site.

public presets(array<int, string> $args, array<string, string> $assoc_args) : void

OPTIONS

[--format=] : Render output in a particular format.

default: table options:

  • table
  • csv
  • json
  • yaml

Parameters
$args : array<int, string>

Positional arguments (none).

$assoc_args : array<string, string>

Associative arguments.

Tags
since
1.2.0

reset()

Set settings back to their default.

public reset(array<int, string> $args, array<string, string> $assoc_args) : void

Settings locked by a constant are skipped with a warning (the constant wins either way), and so are the settings the settings page does not offer with a block theme.

OPTIONS

[...] : One or more setting keys.

[--all] : Reset every setting that is not locked.

[--yes] : Do not ask for confirmation with --all.

[--dry-run] : Report, but write nothing.

EXAMPLES

$ wp harden-trim reset heartbeat post_revisions
$ wp harden-trim reset --all --yes
Parameters
$args : array<int, string>

Keys.

$assoc_args : array<string, string>

Associative arguments.

Tags
since
1.2.0

set()

Change one setting.

public set(array<int, string> $args, array<string, string> $assoc_args) : void

The value goes through the same validation as the settings page. A value that is not accepted, a setting locked by a constant, a role that does not exist on this site, and a setting the settings page does not offer with the active block theme are errors; nothing is written.

Values: switches take true/false (also 1/0, yes/no, on/off); choices take one of the listed words; post_revisions and autosave_interval take one of the listed numbers or default (the WordPress default); role lists take comma-separated role slugs, or an empty string for none.

OPTIONS

: Setting key, as listed by `wp harden-trim status`. : New value.

[--dry-run] : Validate and report, but write nothing.

EXAMPLES

$ wp harden-trim set emoji false
$ wp harden-trim set post_revisions 20
$ wp harden-trim set post_revisions default
$ wp harden-trim set exempt_roles administrator,editor
Parameters
$args : array<int, string>

Key and value.

$assoc_args : array<string, string>

Associative arguments.

Tags
since
1.2.0

status()

Show what every setting does on this site, and why.

public status(array<int, string> $args, array<string, string> $assoc_args) : void

Lists the effective value, where it comes from (default, stored, constant, filter or a core constant), the constant that locks it, and whether the feature acts. A switch can be on and still do nothing: the reason column says why (kill_switch, core_constant, block_theme, plain_permalinks, unused, off). Role-scoped features additionally skip users holding an exempt role.

OPTIONS

[--fields=] : Limit the output to specific fields.

default: key,value,source,locked_by,acts,reason

[--format=] : Render output in a particular format.

default: table options:

  • table
  • csv
  • json
  • yaml

AVAILABLE FIELDS

key, group, type, value, stored, default, source, locked_by, core_value, acts, reason, role_scoped

EXAMPLES

$ wp harden-trim status
$ wp harden-trim status --format=json
$ wp harden-trim status --fields=key,value,stored,default
Parameters
$args : array<int, string>

Positional arguments (none).

$assoc_args : array<string, string>

Associative arguments.

Tags
since
1.2.0

accepted_values()

Describe the values a key accepts.

private accepted_values(string $key) : string
Parameters
$key : string

Setting key.

Return values
string —

Sentence.

block_theme_unavailable()

Whether a key is unavailable because the active theme is a block theme.

private block_theme_unavailable(string $key) : bool

The settings page disables these fields and keeps their stored value.

Parameters
$key : string

Setting key.

Return values
bool

flag()

A boolean flag the WP-CLI way: --flag is true, --no-flag is false.

private flag(array<string, mixed> $assoc_args, string $flag) : bool
Parameters
$assoc_args : array<string, mixed>

Associative arguments.

$flag : string

Flag name.

Return values
bool

format_value()

Format a setting value the way `set` accepts it.

private format_value(mixed $value) : string
Parameters
$value : mixed

Value.

Return values
string —

Printable value.

parse_value()

Turn a command-line value into a validated setting value, or stop.

private parse_value(string $key, string $raw) : mixed
Parameters
$key : string

Setting key.

$raw : string

Value as typed.

Return values
mixed —

Validated value.

printable_row()

A status row with every value printable in a table.

private printable_row(array<string, mixed> $row) : array<string, mixed>
Parameters
$row : array<string, mixed>

Status row.

Return values
array<string, mixed> —

Row with formatted values.

refuse_block_theme()

Stop with an error for a key the settings page does not offer with a block theme.

private refuse_block_theme(string $key) : void
Parameters
$key : string

Setting key.

refuse_locked()

Stop with an error when a key is locked by a constant.

private refuse_locked(string $key) : void
Parameters
$key : string

Setting key.

require_key()

Validate a key or stop with an error.

private require_key(string $key) : string
Parameters
$key : string

Candidate key.

Return values
string —

The key.

write()

Store values over the current stored settings and report the changes.

private write(array<string, mixed> $values, bool $dry_run[, bool $keep_locked = true ]) : void
Parameters
$values : array<string, mixed>

Validated key => value.

$dry_run : bool

Whether to write nothing.

$keep_locked : bool = true

Passed to the store: whether locked keys keep their stored value.

On this page

Search results