Recent

Settings_API class

Settings_API

Settings API wrapper class

Namespace: WebberZone\Better_Search\Admin\Settings
Source: includes/admin/settings/class-settings-api.php line 23

Methods

__construct()

Main constructor class.

Line: 156

public function __construct( $settings_key, $prefix, $args );
TypeNameDescription
string$settings_keySettings key.
string$prefixPrefix. Used for actions and filters.
mixed$args{

hooks()

Adds the functions to the appropriate WordPress hooks.

Line: 185

public function hooks(  );

admin_body_class()

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

Line: 199

public function admin_body_class( $classes ): string;
TypeNameDescription
string$classesSpace-separated list of CSS classes.

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

set_props()

Sets properties.

Line: 221

public function set_props( $args );
TypeNameDescription
array|string$args{

set_translation_strings()

Sets translation strings.

Line: 257

public function set_translation_strings( $strings ): void;
TypeNameDescription
array$strings{

Returns: void

set_sections()

Set settings sections

Line: 291

public function set_sections( $sections ): object;
TypeNameDescription
array$sectionsSetting sections array in the format of: id => Title.

Returns: object — Class object.

add_section()

Add a single section

Line: 303

public function add_section( $section ): object;
TypeNameDescription
array$sectionNew Section.

Returns: object — Object of the class instance.

set_registered_settings()

Set the settings fields for registered settings.

Line: 333

public function set_registered_settings( $registered_settings ): object;
TypeNameDescription
array$registered_settings{

Returns: object — Object of the class instance.

set_upgraded_settings()

Set the settings fields for settings to upgrade.

Line: 345

public function set_upgraded_settings( $upgraded_settings = ... ): object;
TypeNameDescription
array$upgraded_settingsSettings array.

Returns: object — Object of the class instance.

add_custom_menu_page()

Add a menu page to the WordPress admin area.

Line: 358

public function add_custom_menu_page( $menu ): string|false;
TypeNameDescription
array$menuArray 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: 436

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: 459

static public function get_capability_for_menu( $roles = ..., $base_capability = ..., $current_user = ..., $role_capabilities = ... ): string;
TypeNameDescription
array$rolesArray of roles to check.
string$base_capabilityThe default capability.
\WP_User$current_userThe current user object.
array$role_capabilitiesArray of role capabilities.

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

admin_enqueue_scripts()

Enqueue scripts and styles.

Line: 491

public function admin_enqueue_scripts( $hook );
TypeNameDescription
string$hookThe current admin page.

enqueue_scripts_styles() static

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

Line: 576

static public function enqueue_scripts_styles( $prefix, $args = ... );
TypeNameDescription
string$prefixPrefix which is used for creating the unique filters and actions.
array$argsArray 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: 626

public function admin_init(  );

get_registered_settings_types()

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

Line: 692

public function get_registered_settings_types(  ): array;

Returns: array — Default settings

settings_defaults()

Default settings.

Line: 717

public function settings_defaults(  ): array;

Returns: array — Default settings

get_default_option()

Get the default option for a specific key

Line: 772

public function get_default_option( $key = ... ): mixed;
TypeNameDescription
string$keyKey of the option to fetch.

Returns: mixed

settings_reset()

Reset settings.

Line: 789

public function settings_reset(  ): void;

Returns: void

get_sanitize_callback()

Get sanitization callback for given Settings key.

Line: 800

public function get_sanitize_callback( $key = ... ): mixed;
TypeNameDescription
string$keySettings key.

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

settings_sanitize()

Sanitize the form data being submitted.

Line: 851

public function settings_sanitize( $input ): array;
TypeNameDescription
array$inputInput unclean array.

Returns: array — Sanitized array

plugin_settings()

Render the settings page.

Line: 943

public function plugin_settings(  );

show_navigation()

Show navigations as tab

Shows all the settings section labels as tab

Line: 994

public function show_navigation(  );

show_form()

Show the section settings forms

This public function displays every sections in a different form

Line: 1072

public function show_form(  );

Add rating links to the admin dashboard

Line: 1140

public function admin_footer_text( $footer_text ): string;
TypeNameDescription
string$footer_textThe existing footer text.

Returns: string — Updated Footer text

settings_help()

Function to add the contextual help in the settings page.

Line: 1155

public function settings_help(  );

parse_field_args() static

Parse field arguments with defaults.

Line: 1177

static public function parse_field_args( $field, $section = ... ): array;
TypeNameDescription
array$fieldField arguments.
string$sectionSection name.

Returns: array — Parsed field arguments.

get_encryption_key() static

Get the encryption key for API key encryption/decryption.

Line: 1215

static public function get_encryption_key( $prefix = ... ): string;
TypeNameDescription
string$prefixOptional 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: 1227

static public function encrypt_api_key( $key, $prefix = ... ): string;
TypeNameDescription
string$keyThe API key to encrypt.
string$prefixOptional 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: 1261

static public function decrypt_api_key( $encrypted_key, $prefix = ... ): string;
TypeNameDescription
string$encrypted_keyThe encrypted API key to decrypt.
string$prefixOptional prefix for fallback key.

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