Knowledge Base

The Admin Class

The Admin Class

Building Admin Interfaces

Building Admin Pages

Admin pages can be generated using the build_admin_page() method. Here’s a simple example use case:

$admin_obj = new NS_Basics_Admin();
$args = array('page_name' => 'My Awesome Page', 'content' => 'My page content');
$example_page = $admin_obj->build_admin_page($args);

Building Admin Fields

Admin fields can be generated using the build_admin_field() method. Here’s a simple example use case:

$admin_obj = new NS_Basics_Admin();
$field_args = array('title' => 'My Awesome Field', 'name' => 'the_field_name', 'type' => 'text');
$example_field = $admin_obj->build_admin_field($field_args);

Retrieving Settings

Load All Settings

All admin settings can be retrieved with the load_settings() method. If the setting has not yet been saved in the database, it will automatically return the default value for that setting. See the example below on using this method:


$admin_obj = new NS_Basics_Admin();
$settings = $admin_obj->load_settings();
$example_setting = $settings['the_setting_name'];
echo $example_setting;

Load A Single Setting

There may be a scenario where you only what to load a single setting value. In this case, you can do the following:


$admin_obj = new NS_Basics_Admin();
$return_defaults = false;
$single_setting = 'the_setting_name';
$single_esc = true;
$example_setting = $admin_obj->load_settings($return_defaults, $single_setting, $single_esc);

Load Setting Defaults

To get the setting default values, you can do the following:


$admin_obj = new NS_Basics_Admin();
$return_defaults = true;
$example_setting = $admin_obj->load_settings($return_defaults);

Retrieving Meta-Box Settings

Loading Meta-Box Settings