Recent

Settings_APIclass

Settings_API

Settings API wrapper class

Namespace: WebberZone\Image_Optimizer\Admin\Settings
Since: 1.0.0
Source: includes/admin/settings/class-settings-api.php line 24

Methods

__construct()

Main constructor class.

Line: 155

public function __construct( $settings_key, $prefix, $args );
Type Name Description
string $settings_key Settings key.
string $prefix Prefix. Used for actions and filters.
mixed $args {

hooks()

Adds the functions to the appropriate WordPress hooks.

Line: 184

public function hooks(  );

admin_body_class()

Filters the CSS classes for the body tag in the admin.

Line: 198

public function admin_body_class( $classes ): string;
Type Name Description
string $classes Space-separated list of CSS classes.

Returns: string — Space-separated list of CSS classes.

set_props()

Sets properties.

Line: 220

public function set_props( $args );
Type Name Description
array|string $args {

set_translation_strings()

Sets translation strings.

Line: 256

public function set_translation_strings( $strings ): void;
Type Name Description
array $strings {

Returns: void

set_sections()

Set settings sections

Line: 290

public function set_sections( $sections ): object;
Type Name Description
array $sections Setting sections array in the format of: id => Title.

Returns: object — Class object.

add_section()

Add a single section

Line: 302

public function add_section( $section ): object;
Type Name Description
array $section New Section.

Returns: object — Object of the class instance.

set_registered_settings()

Set the settings fields for registered settings.

Line: 332

public function set_registered_settings( $registered_settings ): object;
Type Name Description
array $registered_settings {

Returns: object — Object of the class instance.

set_upgraded_settings()

Set the settings fields for settings to upgrade.

Line: 344

public function set_upgraded_settings( $upgraded_settings = ... ): object;
Type Name Description
array $upgraded_settings Settings array.

Returns: object — Object of the class instance.

add_custom_menu_page()

Add a menu page to the WordPress admin area.

Line: 357

public function add_custom_menu_page( $menu ): string|false;
Type Name Description
array $menu Array of settings for the menu page.

Returns: string|false — The resulting page’s hook_suffix, or false if the user does not have the capability required.

admin_menu()

Add admin menu.

Line: 435

public function admin_menu(  );

get_capability_for_menu() static

Get the appropriate capability for the menu based on the user’s roles and settings.

Line: 458

static public function get_capability_for_menu( $roles = ..., $base_capability = ..., $current_user = ..., $role_capabilities = ... ): string;
Type Name Description
array $roles Array of roles to check.
string $base_capability The default capability.
\WP_User $current_user The current user object.
array $role_capabilities Array of role capabilities.

Returns: string — The capability to use for the menu.

admin_enqueue_scripts()

Enqueue scripts and styles.

Line: 490

public function admin_enqueue_scripts( $hook );
Type Name Description
string $hook The current admin page.

enqueue_scripts_styles() static

Enqueues all scripts, styles, settings, and templates necessary to use the Settings API.

Line: 575

static public function enqueue_scripts_styles( $prefix, $args = ... );
Type Name Description
string $prefix Prefix which is used for creating the unique filters and actions.
array $args Array of arguments.

admin_init()

Initialize and registers the settings sections and fields to WordPress

Usually this should be called at admin_init hook.

This public function gets the initiated settings sections and fields. Then registers them to WordPress and ready for use.

Line: 625

public function admin_init(  );

get_registered_settings_types()

Flattens $this->registered_settings into $setting[id] => $setting[type] format.

Line: 694

public function get_registered_settings_types(  ): array;

Returns: array — Default settings

settings_defaults()

Default settings.

Line: 719

public function settings_defaults(  ): array;

Returns: array — Default settings

get_default_option()

Get the default option for a specific key

Line: 774

public function get_default_option( $key = ... ): mixed;
Type Name Description
string $key Key of the option to fetch.

Returns: mixed

settings_reset()

Reset settings.

Line: 791

public function settings_reset(  ): void;

Returns: void

get_sanitize_callback()

Get sanitization callback for given Settings key.

Line: 802

public function get_sanitize_callback( $key = ... ): mixed;
Type Name Description
string $key Settings key.

Returns: mixed — Callback function or false if callback isn’t found.

get_locked_settings()

Get the settings keys that are rendered locked (disabled or pro-gated).

Line: 847

public function get_locked_settings(  ): array;

Returns: array — Map of settings key => true for each locked setting.

settings_sanitize()

Sanitize the form data being submitted.

Line: 867

public function settings_sanitize( $input ): array;
Type Name Description
mixed $input Unsanitized input. An array for form submissions, but REST and WP-CLI may pass anything.

Returns: array — Sanitized array

plugin_settings()

Render the settings page.

Line: 966

public function plugin_settings(  );

show_navigation()

Show navigations as tab

Shows all the settings section labels as tab

Line: 1017

public function show_navigation(  );

show_form()

Show the section settings forms

This public function displays every sections in a different form

Line: 1095

public function show_form(  );

Add rating links to the admin dashboard

Line: 1163

public function admin_footer_text( $footer_text ): string;
Type Name Description
string $footer_text The existing footer text.

Returns: string — Updated Footer text

settings_help()

Function to add the contextual help in the settings page.

Line: 1178

public function settings_help(  );

parse_field_args() static

Parse field arguments with defaults.

Line: 1200

static public function parse_field_args( $field, $section = ... ): array;
Type Name Description
array $field Field arguments.
string $section Section name.

Returns: array — Parsed field arguments.

get_encryption_key() static

Get the encryption key for API key encryption/decryption.

Line: 1238

static public function get_encryption_key( $prefix = ... ): string;
Type Name Description
string $prefix Optional prefix for fallback key.

Returns: string — The encryption key.

encrypt_api_key() static

Encrypts an API key using either OpenSSL or Sodium, if available.

Line: 1250

static public function encrypt_api_key( $key, $prefix = ... ): string;
Type Name Description
string $key The API key to encrypt.
string $prefix Optional prefix for fallback key.

Returns: string — The encrypted API key, or the plain text key if no secure method is available.

decrypt_api_key() static

Decrypts an API key using either OpenSSL or Sodium, if available.

Line: 1284

static public function decrypt_api_key( $encrypted_key, $prefix = ... ): string;
Type Name Description
string $encrypted_key The encrypted API key to decrypt.
string $prefix Optional prefix for fallback key.

Returns: string — The decrypted API key, or the encrypted key if no secure method is available.