Created
May 21, 2015 10:12
-
-
Save michaeluno/4ef2600a0df1d91b9967 to your computer and use it in GitHub Desktop.
Shows how to create asortable lables with Admin Page Framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Admin Page Framework Example - Sortable Labels | |
Plugin URI: http://en.michaeluno.jp/admin-page-framework | |
Description: Shows how to create asortable lables. | |
Author: Michael Uno | |
Author URI: http://michaeluno.jp | |
Version: 1.0.0 | |
Requirements: PHP 5.2.4 or above, WordPress 3.3 or above. Admin Page Framework 3.5.8 or above | |
*/ | |
// Include the library file. Set your file path here. | |
$_sLibraryPath = defined( 'WP_DEBUG' ) && WP_DEBUG | |
? dirname( dirname( __FILE__ ) ) . '/admin-page-framework/development/admin-page-framework.php' | |
: dirname( dirname( __FILE__ ) ) . '/admin-page-framework/library/admin-page-framework/admin-page-framework.php'; | |
if ( ! class_exists( 'AdminPageFramework' ) && ! include( $_sLibraryPath ) ) { | |
return; | |
} | |
class APF_Example_SortableLables extends AdminPageFramework { | |
public function start() {} | |
/* | |
* Use the setUp() method to define settings of this meta box. | |
*/ | |
public function setUp() { | |
$this->setRootMenuPage( | |
__( 'Sortable Labels', 'admin-page-framework-example' ) // top level menu name | |
); | |
$this->addSubMenuItems( | |
array( | |
'title' => __( 'Sortable Labels', 'admin-page-framework-example' ), // page title | |
'page_slug' => 'apf_example_sortable_labels', // page slug | |
) | |
); | |
} | |
/** | |
* | |
* @callback action load_{page slug} | |
*/ | |
public function load_apf_example_sortable_labels() { | |
/** | |
* Adds setting fields in the meta box. | |
*/ | |
$this->addSettingFields( | |
array( | |
'field_id' => 'sortable_labels', | |
'type' => 'hidden', | |
'title' => __( 'Sortale Labels', 'admin-page-framework-example' ), | |
'label' => $this->getLabelByValue( | |
$this->getValue( array( 'sortable_labels', 0 ), 'a' ) | |
), | |
'default' => 'a', | |
'sortable' => true, | |
array( // second item | |
'label' => $this->getLabelByValue( | |
$this->getValue( array( 'sortable_labels', 1 ), 'b' ) | |
), | |
'default' => 'b', | |
), | |
array( // third item | |
'label' => $this->getLabelByValue( | |
$this->getValue( array( 'sortable_labels', 2 ), 'c' ) | |
), | |
'default' => 'c', | |
), | |
), | |
array( | |
'field_id' => 'submit', | |
'type' => 'submit', | |
) | |
); | |
} | |
/** | |
* | |
* @return string | |
*/ | |
private function getLabelByValue( $sValue ) { | |
switch( $sValue ) { | |
case 'a': | |
return 'Apple'; | |
case 'b': | |
return 'Banana'; | |
case 'c': | |
return 'Cherry'; | |
default: | |
return $sValue; | |
} | |
} | |
/** | |
* | |
* @callback do_{page slug} | |
*/ | |
public function do_apf_example_sortable_labels() { | |
echo "<h3>Saved Options</h3>"; | |
$this->oDebug->dump( | |
get_option( get_class( $this ), array() ) | |
); | |
} | |
} | |
new APF_Example_SortableLables; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey michaeluno,
This was my solution, I think it's simple and can give you ideas for inclusion in the framework.
$labels = array(
'a' => 'Apple',
'b' => 'Banana',
'c' => 'Cherry'
);
$opts = $this->getValue('sortable_labels',$labels) ;
Thank you very much for your time and assistance (Y)