Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save michaeluno/9361576 to your computer and use it in GitHub Desktop.
Save michaeluno/9361576 to your computer and use it in GitHub Desktop.
Demonstrates the use section tabs and repeatable sections with Admin Page Framework. This is a sample plugin introduced in the tutorial, Use Section Tabs and Repeatable Sections (http://en.michaeluno.jp/admin-page-framework/tutorials-v3/06-use-section-tabs-and-repeatable-sections/).
<?php
/*
* Plugin Name: Admin Page Framework Tutorial 06 - Use Advanced Section Settings
* Plugin URI: http://en.michaeluno.jp/admin-page-framework
* Description: Use section tabs and repeatable sections
* Author: Michael Uno
* Author URI: http://michaeluno.jp
* Version: 1.0.1
* Requirements: PHP 5.2.4 or above, WordPress 3.4 or above. Admin Page Framework 3.0.0 or above
*/
// Set your path here
include( dirname( __FILE__ ) . '/library/apf/admin-page-framework.php' );
// Extend the class
class APF_AdvancedSections extends AdminPageFramework {
// Define the setup() method to set how many pages, page titles and icons etc.
public function setUp() {
// Set the root menu
$this->setRootMenuPage( 'Settings' ); // specifies to which parent menu to add.
// Add the sub menus and the pages
$this->addSubMenuItems(
array(
'title' => '6. Advanced Sections', // the page and menu title
'page_slug' => 'advanced_sections' // the page slug
)
);
// Add form sections
$this->addSettingSections(
'advanced_sections', // target page slug
array(
'section_id' => 'repeatable_tabbed_section',
'section_tab_slug' => 'repeatable_sections',
'repeatable' => true,
'title' => 'Repeatable Tabbed Section',
'description' => 'This section is a repeatable tabbed section.',
)
);
// Add form fields
$this->addSettingFields(
'repeatable_tabbed_section', // target page slug
array(
'field_id' => 'my_section_title',
'type' => 'section_title',
),
array(
'field_id' => 'my_color',
'type' => 'color',
'title' => 'Color',
'repeatable' => true,
'sortable' => true,
),
array(
'field_id' => 'my_image',
'type' => 'image',
'title' => 'Image',
'repeatable' => true,
'sortable' => true,
'attributes' => array(
'style' => 'max-width: 300px;',
)
)
);
}
/**
* @callback action do_ + page slug
*/
public function do_advanced_sections() {
submit_button();
/**
*Show the saved option value.
* The extended class name is used as the option key. This can be changed by passing a custom string to the constructor.
*/
echo '<h3>Options as an array</h4>';
echo $this->oDebug->getArray( get_option( 'APF_AdvancedSections' ) );
echo '<h3>Retrieve individual field values</h4>';
echo '<pre>APF_AdvancedSections[repeatable_tabbed_section][0][my_section_title]: ' . AdminPageFramework::getOption( 'APF_AdvancedSections', array( 'repeatable_tabbed_section', '0', 'my_section_title' ), 'default title value' ) . '</pre>';
echo '<pre>APF_AdvancedSections[repeatable_tabbed_section][1][my_color]: ' . AdminPageFramework::getOption( 'APF_AdvancedSections', array( 'repeatable_tabbed_section', '0', 'color' ), 'default color value' ) . '</pre>';
}
}
// Instantiate the class object.
new APF_AdvancedSections;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment