Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeluno/f85acea84185c1c25d28 to your computer and use it in GitHub Desktop.
Save michaeluno/f85acea84185c1c25d28 to your computer and use it in GitHub Desktop.
Demonstrates how to add tabbed sections in meta boxes with Admin Page Framewrok.
<?php
/*
Plugin Name: Admin Page Framework Demo - Tabbed Sections in Meta Boxes
Plugin URI: http://en.michaeluno.jp/admin-page-framework
Description: Demonstrates how to add tabbed sections in meta boxes with Admin Page Framework.
Author: Michael Uno
Author URI: http://michaeluno.jp
Version: 1.0.0
Requirements: Admin Page Framework
*/
if ( ! class_exists( 'AdminPageFramework' ) ) {
include_once( dirname( dirname( __FILE__ ) ) . '/admin-page-framework/development/admin-page-framework.php' );
// include_once( dirname( dirname( __FILE__ ) ) . '/admin-page-framework/library/admin-page-framework.min.php' );
}
class APFDemo_TabbedSectionsInMetaBoxes extends AdminPageFramework_MetaBox {
/**
* Do set-ups.
*/
public function setUp() {
/*
* Create tabbed sections.
*/
$this->addSettingSections(
array(
'section_id' => 'tab_section_a',
'section_tab_slug' => 'tabbed_sections',
'title' => __( 'Section Tab A', 'admin-page-framework-demo' ),
'description' => __( 'This is the first item of the tabbed section.', 'admin-page-framework-demo' ),
)
);
$this->addSettingSections(
array(
'section_id' => 'tab_section_b',
'section_tab_slug' => 'tabbed_sections',
'title' => __( 'Section Tab B', 'admin-page-framework-demo' ),
'description' => __( 'This is the second item of the tabbed section.', 'admin-page-framework-demo' ),
)
);
/*
* Add form fields into the meta box.
*/
$this->addSettingFields(
'tab_section_a', // target section id
array(
'field_id' => 'text_field_in_section_tab',
'title' => __( 'Text', 'admin-page-framework-demo' ),
'type' => 'text',
'default' => 'xyz',
),
array(
'field_id' => 'repeatable_field_in_section_tab',
'title' => __( 'Repeatable Field', 'admin-page-framework-demo' ),
'type' => 'text',
'repeatable' => true,
)
);
$this->addSettingFields(
'tab_section_b', // target section id
array(
'field_id' => 'text_field_in_tab_section_b',
'title' => __( 'TinyMCE', 'admin-page-framework-demo' ),
'type' => 'textarea',
'rich' => true,
),
array(
'field_id' => 'color_in_tab_section_b',
'title' => __( 'Color', 'admin-page-framework-demo' ),
'type' => 'color',
'repeatable' => true,
)
);
}
}
if ( is_admin() ) {
new APFDemo_TabbedSectionsInMetaBoxes(
null, // meta box ID - can be null. If null is passed, the ID gets automatically generated and the class name with all lower case characters will be applied.
__( 'Section Tabs', 'admin-page-framework-demo' ), // title
array( 'apf_posts' ), // post type slugs: post, page, etc.
'normal', // context (what kind of metabox this is)
'default' // priority
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment