TODO: To change the header's content go to Dr.Explain menu Options : Project Settings : HTML (CHM) Export : Setup HTML Template and Layout
|
|||||
|
|||||
TODO: To change the footer's content go to Dr.Explain menu Options : Project Settings : HTML (CHM) Export : Setup HTML Template and Layout
|
require_once( dirname( __FILE__ ) . '/admin-page-framework.min.php' );
|
//extending the framework admin factory class
class MyFirstPlugin extends AdminPageFramework {
//tell the framework what page to create
public function setUp() {
$this->setRootMenuPage( 'Settings' ); # set the top-level page, ie add a page to the Settings page
#add sub-menu pages
$this->addSubMenuItem(
array(
'title' => 'My First Page',
'page_slug' => 'my_first_page',
)
);
}
//Methods for Hooks, echo page content rule: do_{page slug} and it will be automatically gets called.
public function do_my_first_page() {
?>
<h3>Say Something</h3>
<p>This is my first admin page!</p>
<?php
}
}
//Instantiate the Class
new MyFirstPlugin;
|
//under settings menu
$this->setRootMenuPage('Settings');
|
public function setUp() {
// Create the root menu - specifies to which parent menu to add.
$this->setRootMenuPage( 'Settings' );
// Add the sub menus and the pages.
$this->addSubMenuItems(
array(
'title' => '1. My First Setting Page', // page and menu title
'page_slug' => 'my_first_settings_page' // page slug
)
);
}
|
//Methods for Hooks, echo page content rule: do_{page slug} and it will be automatically gets called.
public function do_my_first_page() {
?>
<h3>Say Something</h3>
<p>This is my first admin page!</p>
<?php
}
|
public function load_my_first_forms( $oAdminPage ) { // load_{page slug}
// Our code goes here.
}
|
$this->addSettingFields(
array( // Single text field
'field_id' => 'my_text_field',
'type' => 'text',
'title' => 'Text',
'description' => 'Type something here.', #description that will be placed below the input field
),
array( // Text Area
'field_id' => 'my_textarea_field',
'type' => 'textarea',
'title' => 'Single Text Area',
'description' => 'Type a text string here.',
'default' => 'Hello World! This is set as the default string.', #default value
),
array( // Submit button
'field_id' => 'submit_button',
'type' => 'submit',
)
);
|
class MyFirstPlugin extends AdminPageFramework {
public function setUp() {
$this->setRootMenuPage('Settings');
$this->addSubMenuItem(
array(
'title' => 'My form Page',
'page_slug' => 'my_form_page',
)
);
}
function load_my_form_page($oAdminPage){
$this->addSettingFields(
array( // Single text field
'field_id' => 'my_text_field',
'type' => 'text',
'title' => 'Text',
'description' => 'Type something here.', #description that will be placed below the input field
),
array( // Text Area
'field_id' => 'my_textarea_field',
'type' => 'textarea',
'title' => 'Single Text Area',
'description' => 'Type a text string here.',
'default' => 'Hello World! This is set as the default string.', #default value
),
array( // Submit button
'field_id' => 'submit_button',
'type' => 'submit',
)
);
}
}
if ( is_admin() ) {
new MyFirstPlugin;
}
|
//method 1
$data = get_option( 'MyFirstPlugin' ,array());
$value = isset( $data['my_text_field'] ) ? $data['my_text_field'] : $data['my_text_field'];
|
//method 2
cho '<pre>my_text_field: ' . AdminPageFramework::getOption( 'MyFirstPlugin', 'my_text_field', 'default text value' ) . '</pre>';
echo '<pre>my_textarea_field: ' . AdminPageFramework::getOption( 'MyFirstPlugin', 'my_textarea_field', 'default text value' ) . '</pre>';
|
AdminPageFramework::getOption( 'APF_CreateForm', array( 'my_first_section', 'my_text_field', 2), 'default' )
|
$this->addSettingSections(
'my_second_form', #page slug apply for
//section definition arrays
array(
'section_id' => 'my_first_section', #section id
'title' => 'My First Form Section',
'description' => 'This section is for text fields.',
),
array(
'section_id' => 'my_second_section',
'title' => 'My Second Form Section',
'description' => 'This section is for selectors.',
)
);
|
$this->addSettingFields(
'my_first_section',
array(
'field_id' => 'my_text_field',
'type' => 'text',
'title' => 'Text',
'description' => 'To create multiple fields of the same type, add arrays with numeric keys.',
array(), // sub-field
array(), // sub-field
),
array(
'field_id' => 'my_repeatable_text_field',
'type' => 'text',
'title' => 'Text',
'repeatable' => true, #makes the field repeatable
)
);
$this->addSettingFields(
'my_second_section',
array(
'field_id' => 'my_checkbox',
'type' => 'checkbox',
'title' => __( 'Checkbox', 'admin-page-framework-demo' ),
'label' => __( 'Check me.', 'admin-page-framework-demo' ),
'default' => false,
),
array(
'field_id' => 'my_dropdown_list',
'title' => __( 'Drop-down List', 'admin-page-framework-demo' ),
'type' => 'select',
'default' => 1, // the index key of the label array below which yields 'Two'.
'label' => array(
0 => 'One',
1 => 'Two',
2 => 'Three',
),
),
array(
'field_id' => 'radio',
'title' => __( 'Radio Button', 'admin-page-framework-demo' ),
'type' => 'radio',
'label' => array(
'a' => 'Apple',
'b' => 'Banana',
'c' => 'Cherry'
),
'default' => 'c', // yields Cherry; its key is specified.
'after_label' => '<br />',
),
array( // Submit button
'field_id' => 'submit_button_b',
'type' => 'submit',
'show_title_column' => false, #hidden button title column mean align button to left bellow field label, see image in bellow:
)
);
|