admin-page.php
Settings page
Settings → Harden & Trim: one form for every setting, grouped by section (performance, head, privacy, security, roles), a presets form, and the save and preset handlers behind admin-post.php. All user-facing copy for the settings (labels, descriptions, choice names) lives in this file; import/export and the README reuse the labels.
Tags
Table of Contents
Functions
- jpkcom_harden_trim_page_slug() : string
- Slug of the settings page.
- jpkcom_harden_trim_field_label() : string
- Short label of a setting.
- jpkcom_harden_trim_field_description() : string
- Description of a setting, with a warning wherever switching it on can break something.
- jpkcom_harden_trim_standalone_hint() : string
- Note for a field whose standalone JPKCom plugin is active.
- jpkcom_harden_trim_choice_label() : string
- Display name of one choice of an enum or int setting.
- jpkcom_harden_trim_notice_messages() : array<string, string>
- The messages the settings page shows after a redirect, by code.
- jpkcom_harden_trim_notice_transient() : string
- Name of the current user's notice transient.
- jpkcom_harden_trim_notice_list_cap() : int
- How many entries a notice list keeps.
- jpkcom_harden_trim_redirect_with_notice() : never
- Redirect back to the settings page with a message code, then stop.
- jpkcom_harden_trim_changed_keys() : array<int, string>
- Keys whose value differs between two settings arrays.
- jpkcom_harden_trim_handle_save() : void
- Store a settings form submission (admin_post_jpkcom_harden_trim_save).
- jpkcom_harden_trim_handle_preset() : void
- Apply a preset (admin_post_jpkcom_harden_trim_preset).
- jpkcom_harden_trim_admin_menu() : void
- Add Settings → Harden & Trim and hook its assets to that screen only.
- jpkcom_harden_trim_enqueue_styles() : void
- Enqueue the settings page stylesheet.
- jpkcom_harden_trim_enqueue_scripts() : void
- Enqueue the settings page script (preset confirmation).
- jpkcom_harden_trim_plugin_action_links() : array<string|int, string>
- Put a "Settings" link first in the plugin's row on the Plugins screen.
- jpkcom_harden_trim_format_value() : string
- A constant's value as shown next to a locked field.
- jpkcom_harden_trim_display_value() : string
- A setting's value as the settings page names it.
- jpkcom_harden_trim_core_control_value() : array{value: mixed, other: string|null}
- What a field locked by a core constant shows: the core value, read the way core reads it.
- jpkcom_harden_trim_role_options() : array<string, string>
- Roles offered as checkboxes: every role whose slug the store accepts.
- jpkcom_harden_trim_render_notices() : void
- Kill-switch, invalid-constant and redirect notices.
- jpkcom_harden_trim_render_field() : void
- One form-table row for one setting.
- jpkcom_harden_trim_render_role_scope() : void
- Which features honour the role exemption and which are global.
- jpkcom_harden_trim_render_presets() : void
- The presets section: what each preset sets, and one button per preset.
- jpkcom_harden_trim_render_page() : void
- Render Settings → Harden & Trim.
Functions
jpkcom_harden_trim_page_slug()
Slug of the settings page.
jpkcom_harden_trim_page_slug() : string
Tags
Return values
string —Menu slug.
jpkcom_harden_trim_field_label()
Short label of a setting.
jpkcom_harden_trim_field_label(string $key) : string
Parameters
- $key : string
-
Setting key.
Tags
Return values
string —Translated label, '' for an unknown key.
jpkcom_harden_trim_field_description()
Description of a setting, with a warning wherever switching it on can break something.
jpkcom_harden_trim_field_description(string $key) : string
Parameters
- $key : string
-
Setting key.
Tags
Return values
string —Translated description, '' for an unknown key.
jpkcom_harden_trim_standalone_hint()
Note for a field whose standalone JPKCom plugin is active.
jpkcom_harden_trim_standalone_hint(string $key) : string
JPKCom Disable XML-RPC and JPKCom Disable Comments define their version constant at load; while one of them is active, the matching switch here is redundant (both together are harmless). Information only: no notice, no link, nothing is changed.
Parameters
- $key : string
-
Setting key.
Tags
Return values
string —Translated hint, '' when not applicable.
jpkcom_harden_trim_choice_label()
Display name of one choice of an enum or int setting.
jpkcom_harden_trim_choice_label(string $key, string|int|bool|null $value) : string
Parameters
- $key : string
-
Setting key.
- $value : string|int|bool|null
-
Choice; null is the "WordPress default" option.
Tags
Return values
string —Translated name.
jpkcom_harden_trim_notice_messages()
The messages the settings page shows after a redirect, by code.
jpkcom_harden_trim_notice_messages() : array<string, string>
Only the code travels in the URL; a code that is not listed here shows nothing, so a crafted link cannot put words in front of an administrator.
Tags
Return values
array<string, string> —Code => translated message.
jpkcom_harden_trim_notice_transient()
Name of the current user's notice transient.
jpkcom_harden_trim_notice_transient() : string
Holds the key lists of the last save, preset or import for 60 seconds, so they never travel through the URL and no other user can read them.
Tags
Return values
string —Transient name.
jpkcom_harden_trim_notice_list_cap()
How many entries a notice list keeps.
jpkcom_harden_trim_notice_list_cap() : int
Tags
Return values
int —Maximum entries per list.
jpkcom_harden_trim_redirect_with_notice()
Redirect back to the settings page with a message code, then stop.
jpkcom_harden_trim_redirect_with_notice(string $code[, array<string, array<int, string>> $lists = array() ]) : never
Key lists (changed, rejected, locked) go to the user-scoped
transient; the URL only carries the code and the number of changed keys.
Each list keeps at most jpkcom_harden_trim_notice_list_cap() entries;
how many were cut is kept under more, so a hostile import with
thousands of unknown keys cannot bloat the transient or the notice.
Parameters
- $code : string
-
A key of jpkcom_harden_trim_notice_messages().
- $lists : array<string, array<int, string>> = array()
-
Key lists for the notice.
Tags
Return values
neverjpkcom_harden_trim_changed_keys()
Keys whose value differs between two settings arrays.
jpkcom_harden_trim_changed_keys(array<string, mixed> $before, array<string, mixed> $after) : array<int, string>
Parameters
- $before : array<string, mixed>
-
Settings before.
- $after : array<string, mixed>
-
Settings after.
Tags
Return values
array<int, string> —Keys in the order of $after.
jpkcom_harden_trim_handle_save()
Store a settings form submission (admin_post_jpkcom_harden_trim_save).
jpkcom_harden_trim_handle_save() : void
Fields that were disabled because the active theme is a block theme are not submitted; they keep their stored value instead of falling back to the default. Locked keys keep theirs inside the store.
Tags
jpkcom_harden_trim_handle_preset()
Apply a preset (admin_post_jpkcom_harden_trim_preset).
jpkcom_harden_trim_handle_preset() : void
Only an exact preset name is accepted; anything else, or a preset that would change nothing, writes nothing.
Tags
jpkcom_harden_trim_admin_menu()
Add Settings → Harden & Trim and hook its assets to that screen only.
jpkcom_harden_trim_admin_menu() : void
Tags
jpkcom_harden_trim_enqueue_styles()
Enqueue the settings page stylesheet.
jpkcom_harden_trim_enqueue_styles() : void
Tags
jpkcom_harden_trim_enqueue_scripts()
Enqueue the settings page script (preset confirmation).
jpkcom_harden_trim_enqueue_scripts() : void
Tags
jpkcom_harden_trim_plugin_action_links()
Put a "Settings" link first in the plugin's row on the Plugins screen.
jpkcom_harden_trim_plugin_action_links(array<string|int, string> $links) : array<string|int, string>
Parameters
- $links : array<string|int, string>
-
Action links.
Tags
Return values
array<string|int, string> —Links with the settings link first.
jpkcom_harden_trim_format_value()
A constant's value as shown next to a locked field.
jpkcom_harden_trim_format_value(mixed $value) : string
Parameters
- $value : mixed
-
Value.
Tags
Return values
string —Plain text, not escaped.
jpkcom_harden_trim_display_value()
A setting's value as the settings page names it.
jpkcom_harden_trim_display_value(string $key, mixed $value) : string
Parameters
- $key : string
-
Setting key.
- $value : mixed
-
Value.
Tags
Return values
string —Plain text, not escaped.
jpkcom_harden_trim_core_control_value()
What a field locked by a core constant shows: the core value, read the way core reads it.
jpkcom_harden_trim_core_control_value(string $key, mixed $value) : array{value: mixed, other: string|null}
The control of a core-locked field must show what is in effect, which is the core constant (core honours it and the feature code then does nothing), never the stored value or an ignored plugin constant. Core reads (7.1.3):
DISALLOW_FILE_EDIT: truthy disables the editors (capabilities.php:609).WP_AI_SUPPORT: falsy disables AI (ai-client.php:23); the field is "Disable core AI features", so it is checked for a falsy value.WP_POST_REVISIONS:trueis unlimited, anything else is cast to int (revision.php:813-818); a negative number is unlimited as well, which is what "WordPress default" means for this field. 0 and the listed limits select their option.AUTOSAVE_INTERVAL: seconds handed to the editor (script-loader.php:1962); 60 is core's own default (default-constants.php:381). A value no option names is returned asother, the text of an extra option the disabled select shows selected.
Parameters
- $key : string
-
Setting key with a core constant.
- $value : mixed
-
The core constant's value.
Tags
Return values
array{value: mixed, other: string|null} —Control value; other is set when no option fits.
jpkcom_harden_trim_role_options()
Roles offered as checkboxes: every role whose slug the store accepts.
jpkcom_harden_trim_role_options() : array<string, string>
Tags
Return values
array<string, string> —Slug => translated name.
jpkcom_harden_trim_render_notices()
Kill-switch, invalid-constant and redirect notices.
jpkcom_harden_trim_render_notices() : void
Tags
jpkcom_harden_trim_render_field()
One form-table row for one setting.
jpkcom_harden_trim_render_field(string $key, array<string, mixed> $settings, array<string, string> $locked[, array<string, mixed> $effective = array() ]) : void
Parameters
- $key : string
-
Setting key. A field locked by a core constant shows the core value instead (see jpkcom_harden_trim_core_control_value()).
- $settings : array<string, mixed>
-
Values the inputs show: stored for unlocked keys, effective for locked ones.
- $locked : array<string, string>
-
Key => locking constant name.
- $effective : array<string, mixed> = array()
-
Effective settings (filter applied); empty to skip the comparison.
Tags
jpkcom_harden_trim_render_role_scope()
Which features honour the role exemption and which are global.
jpkcom_harden_trim_render_role_scope() : void
Tags
jpkcom_harden_trim_render_presets()
The presets section: what each preset sets, and one button per preset.
jpkcom_harden_trim_render_presets() : void
Tags
jpkcom_harden_trim_render_page()
Render Settings → Harden & Trim.
jpkcom_harden_trim_render_page() : void