Settings
in package
Manage the pfeifferNet site(s) settings.
- Create a settings admin page.
- Settings are kept in an array in single table entry.
- Maintain settings that are unique to each site.
- Provide hooks to allow other plugins to modify or extend settings sections and fields.
- Provide hook to allow other plugins to validate extended settings fields.
- Provide settings import/export.
Tags
Table of Contents
Constants
- CAPABILITY = 'manage_options'
- The user capability required to access the settings page.
- DEFAULT_INPUT_CONTAINER = 'input-default.php'
- Default setting field input partial.
- DESCRIPTION_FIELD_CONTAINER = 'setting-description.php'
- The settings field or section description paragraph element template.
- FILE_NAME = 'pfeifferNet-settings.json'
- The settings export file name.
- PAGE_SLUG = 'pnet-site-settings'
- The settings menu slug.
- SETTINGS_CONTAINER = 'form-settings.php'
- Settings page partial.
Properties
- $current_settings : array<string|int, mixed>
- The array of settings values currently stored.
- $default_input : string
- The fully qualified path to the default setting field input partial.
- $description_field : string
- The fully qualified path to the setting section or field description partial.
- $fields : array<string|int, mixed>
- The array of settings input fields and their definition.
- $instances : array<string|int, object>
- The array of instances of this class and sub-classes.
- $media_selector : Media_Selector
- The instance of the Media_Selector class.
- $page_hook : string
- The page hook.
- $page_icon_url : string
- The page icon url.
- $page_title : string
- The page title.
- $sections : array<string|int, mixed>
- The array of settings sections and their definition.
- $settings_container : string
- The fully qualified path to the settings page partial.
- $settings_key : string
- The plugin settings options key.
Methods
- add_options_menu() : void
- Add entry to options menu.
- get_export() : array<string|int, mixed>
- Get the settings export file contents.
- get_instance() : object
- Creates and/or returns the instance of this class.
- import() : bool
- Import settings.
- initialise_settings() : void
- Register the setting and add sections and fields.
- render() : void
- Render settings page.
- render_field() : void
- Settings field callback to render the field.
- render_section() : void
- Settings section callback,
- sanitise_settings() : array<string|int, mixed>
- Settings sanitisation callback.
- set_action_links() : array<string|int, string>
- Return the site settings plugin action links.
- __construct() : void
- Initialise the class.
- add_settings_fields() : void
- Add the fields to the form.
- add_settings_sections() : void
- Add the sections to the form.
- render_input_element() : void
- Render the input field based on field type.
- set_fields() : void
- Initialise the fields array.
- set_fields_contact_requests() : void
- Set the email address for contact requests.
- set_fields_external_api() : void
- Set the external API requirements.
- set_fields_general() : void
- General site settings fields.
- set_fields_google_recaptcha() : void
- Set the threshold and keys for the Google reCaptcha API.
- set_fields_images() : void
- Set home and fallback images.
- set_fields_sharing() : void
- Set the supported social sharing services.
- set_fields_smtp() : void
- Set SMTP username, password and sender settings.
- set_fields_social_media() : void
- Set the social media accounts.
- set_fields_users() : void
- Set the user account settings.
- set_sections() : void
- Initialise the sections array.
- set_token_expiration_description() : string
- Set the description for the token expiry field.
- validate_github_token() : array<string|int, mixed>
- Validate the GitHub token by checking the expiry date.
Constants
CAPABILITY
The user capability required to access the settings page.
protected
string
CAPABILITY
= 'manage_options'
Tags
DEFAULT_INPUT_CONTAINER
Default setting field input partial.
protected
string
DEFAULT_INPUT_CONTAINER
= 'input-default.php'
Tags
DESCRIPTION_FIELD_CONTAINER
The settings field or section description paragraph element template.
protected
string
DESCRIPTION_FIELD_CONTAINER
= 'setting-description.php'
Tags
FILE_NAME
The settings export file name.
protected
string
FILE_NAME
= 'pfeifferNet-settings.json'
Tags
PAGE_SLUG
The settings menu slug.
protected
string
PAGE_SLUG
= 'pnet-site-settings'
Tags
SETTINGS_CONTAINER
Settings page partial.
protected
string
SETTINGS_CONTAINER
= 'form-settings.php'
Tags
Properties
$current_settings
The array of settings values currently stored.
protected
array<string|int, mixed>
$current_settings
= array()
Tags
$default_input
The fully qualified path to the default setting field input partial.
protected
string
$default_input
= ''
Tags
$description_field
The fully qualified path to the setting section or field description partial.
protected
string
$description_field
= ''
Tags
$fields
The array of settings input fields and their definition.
protected
array<string|int, mixed>
$fields
= array()
- Note that $uid is the key to the value in the settings array.
{ Array of settings input fields, keyed by field uid. @type array $uid { The field settings. Always use underscores in key name. @type string $label Field label on settings page. @type string $section Section field belongs in. @type string $type Input field type. @type string $class CSS class to apply to field. @type string $placeholder Field placeholder tag text. @type string $title Field title tag text. @type string $description Field description text. } }
Tags
$instances
The array of instances of this class and sub-classes.
protected
static array<string|int, object>
$instances
= array()
Tags
$media_selector
The instance of the Media_Selector class.
protected
Media_Selector
$media_selector
Tags
$page_hook
The page hook.
protected
string
$page_hook
= ''
Tags
$page_icon_url
The page icon url.
protected
string
$page_icon_url
= ''
Tags
$page_title
The page title.
protected
string
$page_title
= ''
Tags
$sections
The array of settings sections and their definition.
protected
array<string|int, mixed>
$sections
= array()
{ Array of sections, keyed by section id. @type array $id { The section settings. @type callable $callback The section display callback. @type array $description Optional. The section description to display below title.. @type string $title The section title. } }
Tags
$settings_container
The fully qualified path to the settings page partial.
protected
string
$settings_container
= ''
Tags
$settings_key
The plugin settings options key.
protected
string
$settings_key
= ''
Tags
Methods
add_options_menu()
Add entry to options menu.
public
add_options_menu() : void
Tags
get_export()
Get the settings export file contents.
public
get_export() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —$export { The export file contents. @type string $filename The settings export filename. @type string $sitename The site that created the settings file. @type string $plugin The name of this plugin. @type string $version This plugin version. @type string $created The human-readable date/time stamp when the export file was created. This will be in the server timezone. @type string $timestamp The linux date/time stamp when the export file was created. @type array $settings An array of settings key/value pairs }
get_instance()
Creates and/or returns the instance of this class.
public
static get_instance() : object
Tags
Return values
object —The instance of this class.
import()
Import settings.
public
import(array<string|int, mixed> $import) : bool
Parameters
- $import : array<string|int, mixed>
-
The import file contents.
Tags
Return values
bool —True if settings imported, false if not.
initialise_settings()
Register the setting and add sections and fields.
public
initialise_settings() : void
Tags
render()
Render settings page.
public
render() : void
- Require the user to have appropriate permissions.
Tags
render_field()
Settings field callback to render the field.
public
render_field(array<string|int, mixed> $field) : void
Parameters
- $field : array<string|int, mixed>
-
Array of field definition data.
Tags
render_section()
Settings section callback,
public
render_section(array<string|int, mixed> $section) : void
- Echo any content at the top of the section (between heading and fields).
Parameters
- $section : array<string|int, mixed>
-
{ Array of data added to the callback. @type string $id The settings section id. @type string $title The settings section title. @type callable $callback The settings section callback. }
Tags
sanitise_settings()
Settings sanitisation callback.
public
sanitise_settings(array<string|int, mixed> $input) : array<string|int, mixed>
- Provide hook to allow other plugins to validate extended settings fields.
Parameters
- $input : array<string|int, mixed>
-
Array of settings data from form or input file.
Tags
Return values
array<string|int, mixed> —The sanitised settings data.
set_action_links()
Return the site settings plugin action links.
public
set_action_links(array<string|int, string> $actions, string $plugin_file, array<string|int, mixed> $plugin_data, string $context) : array<string|int, string>
- This will only be called if the plugin is active.
Parameters
- $actions : array<string|int, string>
-
Associative array of action names to anchor tags.
- $plugin_file : string
-
Plugin file name, ie my-plugin/my-plugin.php.
- $plugin_data : array<string|int, mixed>
-
Associative array of plugin data from the plugin file headers.
- $context : string
-
Plugin status context, ie 'all', 'active', 'inactive', 'recently_active'.
Tags
Return values
array<string|int, string> —The modified array of plugin action links.
__construct()
Initialise the class.
protected
__construct() : void
Tags
add_settings_fields()
Add the fields to the form.
protected
add_settings_fields() : void
- Provide filter hook to allow other plugins to modify or extend settings fields.
Tags
add_settings_sections()
Add the sections to the form.
protected
add_settings_sections() : void
- Provide filter hook to allow other plugins to modify or extend settings sections.
Tags
render_input_element()
Render the input field based on field type.
protected
render_input_element(array<string|int, mixed> $field, string $field_name, string $field_id[, string $field_value = '' ]) : void
Parameters
- $field : array<string|int, mixed>
-
Array of field definition data.
- $field_name : string
-
The name of the field.
- $field_id : string
-
The value for the field id attribute.
- $field_value : string = ''
-
Optional. The current value of the field.
Tags
set_fields()
Initialise the fields array.
protected
set_fields() : void
- Populate the array of settings fields and their definition.
Tags
set_fields_contact_requests()
Set the email address for contact requests.
protected
set_fields_contact_requests() : void
- Populate the array of settings fields and their definition.
- The array key is the field uid. This the name of the setting within the array of settings.
- The sequence determines the order within the section.
Tags
set_fields_external_api()
Set the external API requirements.
protected
set_fields_external_api() : void
- Populate the array of settings fields and their definition.
- The array key is the field uid. This the name of the setting within the array of settings.
- The sequence determines the order within the section.
Tags
set_fields_general()
General site settings fields.
protected
set_fields_general() : void
- Populate the array of settings fields and their definition.
- The array key is the field uid. This the name of the setting within the array of settings.
- The sequence determines the order within the section.
Tags
set_fields_google_recaptcha()
Set the threshold and keys for the Google reCaptcha API.
protected
set_fields_google_recaptcha() : void
- Populate the array of settings fields and their definition.
- The array key is the field uid. This the name of the setting within the array of settings.
- The sequence determines the order within the section.
Tags
set_fields_images()
Set home and fallback images.
protected
set_fields_images() : void
- Populate the array of settings fields and their definition.
- The array key is the field uid. This the name of the setting within the array of settings.
- The sequence determines the order within the section.
Tags
set_fields_sharing()
Set the supported social sharing services.
protected
set_fields_sharing() : void
- Populate the array of settings fields and their definition.
- The array key is the field uid. This the name of the setting within the array of settings.
- The sequence determines the order within the section.
Tags
set_fields_smtp()
Set SMTP username, password and sender settings.
protected
set_fields_smtp() : void
- Populate the array of settings fields and their definition.
- The array key is the field uid. This the name of the setting within the array of settings.
- The sequence determines the order within the section.
Tags
set_fields_social_media()
Set the social media accounts.
protected
set_fields_social_media() : void
- Populate the array of settings fields and their definition.
- The array key is the field uid. This the name of the setting within the array of settings.
- The sequence determines the order within the section.
Tags
set_fields_users()
Set the user account settings.
protected
set_fields_users() : void
- Populate the array of settings fields and their definition.
- The array key is the field uid. This the name of the setting within the array of settings.
- The sequence determines the order within the section.
Tags
set_sections()
Initialise the sections array.
protected
set_sections() : void
- Populate the array of settings sections and their definition.
- The array key is the section id.
- The sequence determines the order down the settings page.
Tags
set_token_expiration_description()
Set the description for the token expiry field.
protected
set_token_expiration_description(string $expiry_date) : string
Parameters
- $expiry_date : string
-
The token expiry date and time.
Tags
Return values
string —The token expiry description text.
validate_github_token()
Validate the GitHub token by checking the expiry date.
protected
validate_github_token(string $token) : array<string|int, mixed>
- If token is unchanged, exit early.
- If the token is valid, set the expiry date field.
- If the token is invalid, clear both fields.
Parameters
- $token : string
-
The GitHub token.
Tags
Return values
array<string|int, mixed> —The (maybe) modified GitHub token data. @type string $github_token The GitHub token. @type string $github_token_expiry The GitHub token expiry date.