Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class APFTest_SortableCheckboxes extends AdminPageFramework {
- public function setUp() {
- // To reset the options uncomment the next line.
- // delete_option( get_class( $this ) );
- $this->setRootMenuPage( __( 'Sortable Checkboxes', 'apf-test-sortable-checkboxes' ) );
- $this->addSubMenuItems(
- array(
- 'title' => __( 'Settings', 'apf-test-sortable-checkboxes' ),
- 'page_slug' => 'apftsc_settings'
- )
- );
- }
- public function do_apftsc_settings( $oFactory ) {
- echo "<h3>Saved Data</h3>";
- AdminPageFramework_Debug::dump( $this->oProp->aOptions );
- }
- public function load_apftsc_settings( $oFactory ) {
- // Section
- $oFactory->addSettingSections(
- 'apftsc_settings', // the target page slug
- array(
- 'section_id' => 'sortable_checkboxes_section',
- 'title' => __( 'Sortable Checkboxes', 'apf-test-sortable-checkboxes' ),
- )
- );
- $oFactory->addSettingFields(
- 'sortable_checkboxes_section', // the target section ID
- array(
- 'field_id' => 'checkbox_number_select',
- 'type' => 'inline_mixed',
- 'title' => __( 'Checkbox, Number & Select', 'admin-page-framework-loader' ),
- 'sortable' => true,
- 'content' => $this->___getFirstRowCheckboxes(),
- array( // Second field
- 'content' => $this->___getSecondRowCheckboxes(),
- ),
- array( // Third field
- 'content' => $this->___getThirdRowCheckboxes(),
- ),
- ),
- array(
- 'field_id' => '_submit',
- 'type' => 'submit',
- 'save' => false,
- 'show_title_column' => false,
- )
- );
- }
- private function ___getFirstRowCheckboxes() {
- $_aSavedCheckboxes = $this->oUtil->getElement(
- $this->oProp->aOptions,
- array( 'sortable_checkboxes_section', 'checkbox_number_select', 0 ),
- array(
- 'a' => 0,
- 'b' => 1, // checked
- 'c' => 0,
- )
- );
- return $this->___getCheckboxLabels( $_aSavedCheckboxes );
- }
- private function ___getSecondRowCheckboxes() {
- $_aSavedCheckboxes = $this->oUtil->getElement(
- $this->oProp->aOptions,
- array( 'sortable_checkboxes_section', 'checkbox_number_select', 1 ),
- array(
- 'x' => 0,
- 'y' => 0,
- 'z' => 1,
- )
- );
- return $this->___getCheckboxLabels( $_aSavedCheckboxes );
- }
- private function ___getThirdRowCheckboxes() {
- $_aSavedCheckboxes = $this->oUtil->getElement(
- $this->oProp->aOptions,
- array( 'sortable_checkboxes_section', 'checkbox_number_select', 2 ),
- array(
- 'one' => 1,
- 'two' => 1,
- 'three' => 0,
- )
- );
- return $this->___getCheckboxLabels( $_aSavedCheckboxes );
- }
- private function ___getCheckboxLabels( array $aSavedCheckboxes ) {
- $_aCheckboxes = array();
- foreach( $aSavedCheckboxes as $_sKey => $_iValue ) {
- $_aCheckboxes[] = array(
- 'field_id' => $_sKey,
- 'type' => 'checkbox',
- 'label' => $this->___getCheckboxLabelByKey( $_sKey ),
- 'value' => $_iValue,
- );
- }
- return $_aCheckboxes;
- }
- private function ___getCheckboxLabelByKey( $sKey ) {
- $_aLabels = array(
- 'a' => 'A',
- 'b' => 'B',
- 'c' => 'C',
- 'x' => 'X',
- 'y' => 'Y',
- 'z' => 'Z',
- 'one' => 'One',
- 'two' => 'Two',
- 'three' => 'Three',
- );
- return isset( $_aLabels[ $sKey ] )
- ? $_aLabels[ $sKey ]
- : '';
- }
- }
- new APFTest_SortableCheckboxes( null, APFTest_SortableCheckboxesBootstrap::$sFilePath );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement