Basic usage:
1 2 3 4 5 6 7 8 9 10 11 12 |
add_action( 'xbox_init', 'my_admin_page'); function my_admin_page(){ $options = array( 'id' => 'my-admin-page',//It will be used as "option_name" key to save the data in the wp_options table 'title' => 'My Admin Page', 'menu_title' => 'Xbox Admin Page', ); $xbox = xbox_new_admin_page( $options ); } |
Result:
Tip:
You can see a complete example inside the folder “../xbox/example/”
../xbox/example/admin-page.php
../xbox/example/metabox.php
../xbox/example/advanced-import.php
To hide all examples add this code to your project.
1 2 3 4 5 |
if( ! defined( 'XBOX_HIDE_DEMO' ) ){ define( 'XBOX_HIDE_DEMO', true ); } |
Advanced usage, with available options:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
add_action( 'xbox_init', 'my_admin_page'); function my_admin_page(){ $options = array( 'id' => 'my-admin-page',//It will be used as "option_name" key to save the data in the wp_options table 'title' => 'Theme Options', 'menu_title' => 'Xbox Admin Page', 'icon' => XBOX_URL.'/img/xbox-light.png', 'skin' => 'teal',// Skins: blue, lightblue, green, teal, pink, purple, bluepurple, yellow, orange'. 'layout' => 'wide',//Layouts: wide, boxed 'position' => 60, 'parent' => false,//The slug name for the parent menu (or the file name of a standard WordPress admin page). 'capability' => 'manage_options',//https://codex.wordpress.org/Roles_and_Capabilities 'header' => array( 'icon' => '<img src="'.XBOX_URL.'/img/xbox-light.png"/>', 'desc' => 'Custom description for theme options', ), 'saved_message' => __( 'Settings updated', 'xbox' ), 'reset_message' => __( 'Settings reset', 'xbox' ), 'form_options' => array( 'id' => 'id-form-tag', 'action' => '', 'method' => 'post', 'save_button_text' => __('Save Changes', 'xbox'), 'save_button_class' => '', 'reset_button_text' => __('Reset to Defaults', 'xbox'), 'reset_button_class' => '', ), 'import_settings' => array( 'update_uploads_url' => true, 'update_plugins_url' => true, 'show_authentication_fields' => false,//Show username and password fields ), ); $xbox = xbox_new_admin_page( $options ); } |
Result:
Now, let’s add some fields to our admin page:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
add_action( 'xbox_init', 'my_admin_page'); function my_admin_page(){ $options = array(...);//Prev code $xbox = xbox_new_admin_page( $options ); $xbox->add_field(array( 'id' => 'default-logo', 'name' => __( 'Default Logo', 'textdomain' ), 'type' => 'file', )); $xbox->add_field(array( 'id' => 'slogan', 'name' => __( 'Slogan', 'textdomain' ), 'type' => 'text', 'grid' => '3-of-6' )); $xbox->add_field(array( 'id' => 'show-slogan', 'name' => __( 'Show slogan', 'textdomain' ), 'type' => 'switcher', 'default' => 'on', )); $xbox->add_field( array( 'id' => 'font-family', 'name' => __( 'Font family', 'textdomain' ), 'type' => 'select', 'default' => 'Open Sans', 'items' => array( '' => 'None', 'Google Fonts' => XboxItems::google_fonts(), 'Web Safe Fonts' => XboxItems::web_safe_fonts() ), 'options' => array( 'sort' => 'asc', 'search' => true, ), 'grid' => '3-of-8' )); } |
Result:
To make it more interesting we will add some tabs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
add_action( 'xbox_init', 'my_admin_page'); function my_admin_page(){ $options = array();//Prev code $xbox = xbox_new_admin_page( $options ); $xbox->add_main_tab( array( 'id' => 'main-tab', 'items' => array( 'logo' => '<i class="xbox-icon xbox-icon-image"></i>Logo', 'header' => '<i class="xbox-icon xbox-icon-arrow-up"></i>Header', 'footer' => '<i class="xbox-icon xbox-icon-arrow-down"></i>Footer', ), )); $xbox->open_tab_item('logo'); $xbox->add_field(array( 'id' => 'default-logo', 'name' => __( 'Default Logo', 'textdomain' ), 'type' => 'file', )); $xbox->add_field(array( 'id' => 'slogan', 'name' => __( 'Slogan', 'textdomain' ), 'type' => 'text', 'grid' => '3-of-6' )); $xbox->add_field(array( 'id' => 'show-slogan', 'name' => __( 'Show slogan', 'textdomain' ), 'type' => 'switcher', 'default' => 'on', )); $xbox->add_field( array( 'id' => 'font-family', 'name' => __( 'Font family', 'textdomain' ), 'type' => 'select', 'default' => 'Open Sans', 'items' => array( '' => 'None', 'Google Fonts' => XboxItems::google_fonts(), 'Web Safe Fonts' => XboxItems::web_safe_fonts() ), 'options' => array( 'sort' => 'asc', 'search' => true, ), 'grid' => '3-of-8' )); $xbox->close_tab_item('logo'); $xbox->open_tab_item('header'); //Add fields $xbox->close_tab_item('header'); $xbox->open_tab_item('footer'); //Add fields $xbox->close_tab_item('footer'); $xbox->close_tab('main-tab'); } |
Result:
Get saved values:
Note:
Always use ‘xbox_init’ hook to create your admin pages.