Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. <?php
  2. class APFTest_SortableCheckboxes extends AdminPageFramework {
  3.  
  4. public function setUp() {
  5.  
  6. // To reset the options uncomment the next line.
  7. // delete_option( get_class( $this ) );
  8.  
  9. $this->setRootMenuPage( __( 'Sortable Checkboxes', 'apf-test-sortable-checkboxes' ) );
  10.  
  11. $this->addSubMenuItems(
  12. array(
  13. 'title' => __( 'Settings', 'apf-test-sortable-checkboxes' ),
  14. 'page_slug' => 'apftsc_settings'
  15. )
  16. );
  17.  
  18. }
  19.  
  20. public function do_apftsc_settings( $oFactory ) {
  21. echo "<h3>Saved Data</h3>";
  22. AdminPageFramework_Debug::dump( $this->oProp->aOptions );
  23. }
  24.  
  25. public function load_apftsc_settings( $oFactory ) {
  26.  
  27. // Section
  28. $oFactory->addSettingSections(
  29. 'apftsc_settings', // the target page slug
  30. array(
  31. 'section_id' => 'sortable_checkboxes_section',
  32. 'title' => __( 'Sortable Checkboxes', 'apf-test-sortable-checkboxes' ),
  33. )
  34. );
  35.  
  36. $oFactory->addSettingFields(
  37. 'sortable_checkboxes_section', // the target section ID
  38. array(
  39. 'field_id' => 'checkbox_number_select',
  40. 'type' => 'inline_mixed',
  41. 'title' => __( 'Checkbox, Number & Select', 'admin-page-framework-loader' ),
  42. 'sortable' => true,
  43. 'content' => $this->___getFirstRowCheckboxes(),
  44. array( // Second field
  45. 'content' => $this->___getSecondRowCheckboxes(),
  46. ),
  47. array( // Third field
  48. 'content' => $this->___getThirdRowCheckboxes(),
  49. ),
  50. ),
  51. array(
  52. 'field_id' => '_submit',
  53. 'type' => 'submit',
  54. 'save' => false,
  55. 'show_title_column' => false,
  56. )
  57. );
  58. }
  59. private function ___getFirstRowCheckboxes() {
  60. $_aSavedCheckboxes = $this->oUtil->getElement(
  61. $this->oProp->aOptions,
  62. array( 'sortable_checkboxes_section', 'checkbox_number_select', 0 ),
  63. array(
  64. 'a' => 0,
  65. 'b' => 1, // checked
  66. 'c' => 0,
  67. )
  68. );
  69. return $this->___getCheckboxLabels( $_aSavedCheckboxes );
  70.  
  71. }
  72. private function ___getSecondRowCheckboxes() {
  73. $_aSavedCheckboxes = $this->oUtil->getElement(
  74. $this->oProp->aOptions,
  75. array( 'sortable_checkboxes_section', 'checkbox_number_select', 1 ),
  76. array(
  77. 'x' => 0,
  78. 'y' => 0,
  79. 'z' => 1,
  80. )
  81. );
  82. return $this->___getCheckboxLabels( $_aSavedCheckboxes );
  83. }
  84. private function ___getThirdRowCheckboxes() {
  85. $_aSavedCheckboxes = $this->oUtil->getElement(
  86. $this->oProp->aOptions,
  87. array( 'sortable_checkboxes_section', 'checkbox_number_select', 2 ),
  88. array(
  89. 'one' => 1,
  90. 'two' => 1,
  91. 'three' => 0,
  92. )
  93. );
  94. return $this->___getCheckboxLabels( $_aSavedCheckboxes );
  95. }
  96.  
  97. private function ___getCheckboxLabels( array $aSavedCheckboxes ) {
  98. $_aCheckboxes = array();
  99. foreach( $aSavedCheckboxes as $_sKey => $_iValue ) {
  100. $_aCheckboxes[] = array(
  101. 'field_id' => $_sKey,
  102. 'type' => 'checkbox',
  103. 'label' => $this->___getCheckboxLabelByKey( $_sKey ),
  104. 'value' => $_iValue,
  105. );
  106. }
  107. return $_aCheckboxes;
  108. }
  109. private function ___getCheckboxLabelByKey( $sKey ) {
  110. $_aLabels = array(
  111. 'a' => 'A',
  112. 'b' => 'B',
  113. 'c' => 'C',
  114. 'x' => 'X',
  115. 'y' => 'Y',
  116. 'z' => 'Z',
  117. 'one' => 'One',
  118. 'two' => 'Two',
  119. 'three' => 'Three',
  120. );
  121. return isset( $_aLabels[ $sKey ] )
  122. ? $_aLabels[ $sKey ]
  123. : '';
  124.  
  125. }
  126. }
  127.  
  128. new APFTest_SortableCheckboxes( null, APFTest_SortableCheckboxesBootstrap::$sFilePath );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement