/admin/admin-init.php

  1. <?php 
  2. /** "Copyright 2012 a3 Revolution Web Design" This software is distributed under the terms of GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 */ 
  3. // File Security Check 
  4. if ( ! defined( 'ABSPATH' ) ) exit; 
  5. ?> 
  6. <?php 
  7. /**----------------------------------------------------------------------------------- 
  8. A3rev Plugin Admin Init 
  9.   
  10. TABLE OF CONTENTS 
  11.   
  12. - var admin_menu 
  13. - init() 
  14. - set_default_settings() 
  15. - get_all_settings() 
  16. - add_admin_menu() 
  17. - register_admin_menu() 
  18. - add_admin_pages() 
  19. - admin_settings_tab() 
  20.   
  21. -----------------------------------------------------------------------------------*/ 
  22.  
  23. class WC_Dynamic_Gallery_Admin_Init extends WC_Dynamic_Gallery_Admin_UI 
  24.  
  25. /** 
  26. * @var array 
  27. */ 
  28. public $admin_menu = array(); 
  29.  
  30. /**-----------------------------------------------------------------------------------*/ 
  31. /** init() */ 
  32. /** Admin Init */ 
  33. /**-----------------------------------------------------------------------------------*/ 
  34. public function init() { 
  35.  
  36. $this->add_admin_menu(); 
  37.  
  38. // Filter to add admin pages for Amin UI process 
  39. add_filter( $this->plugin_name . '_admin_pages', array( $this, 'add_admin_pages' ) ); 
  40.  
  41. add_action( 'admin_menu', array( $this, 'register_admin_menu' ) ); 
  42.  
  43. add_action( 'plugins_loaded', array( $this, 'get_all_settings' ), 8 ); 
  44.  
  45. /**-----------------------------------------------------------------------------------*/ 
  46. /** set_default_settings() */ 
  47. /** Called when plugin just installed */ 
  48. /**-----------------------------------------------------------------------------------*/ 
  49. public function set_default_settings() { 
  50.  
  51. do_action( $this->plugin_name . '_set_default_settings' ); 
  52.  
  53. /**-----------------------------------------------------------------------------------*/ 
  54. /** get_all_settings() */ 
  55. /** Get all settings when plugin is loaded */ 
  56. /**-----------------------------------------------------------------------------------*/ 
  57. public function get_all_settings() { 
  58.  
  59. do_action( $this->plugin_name . '_get_all_settings' ); 
  60.  
  61. /** 
  62. * add_admin_menu() 
  63. * Add the Admin menu 
  64. * ============================================= 
  65. * check add_menu_page() function at http://codex.wordpress.org/Function_Reference/add_menu_page to know the parameters need to parse for type is menu 
  66. * check add_submenu_page() function at http://codex.wordpress.org/Function_Reference/add_submenu_page to know the parameters need to parse for type is submenu 
  67. * array ( 
  68. * array ( 
  69. * 'type' => 'menu' : (required) add it as main menu on left sidebar of Dashboard 
  70. * 'page_title' => 'Quotes & Orders Mode' : (required) The text to be displayed in the title tags of the page when the menu is selected 
  71. * 'menu_title' => 'Quotes & Orders Mode' : (required) The text to be displayed in the title tags of the page when the menu is selected 
  72. * 'capability' => 'manage_options' : (required) The capability required for this menu to be displayed to the user. 
  73. * View instruction at http://codex.wordpress.org/Roles_and_Capabilities 
  74. * 'menu_slug' => 'quotes-orders-mode' : (required) The slug name to refer to this menu by. 
  75. * 'function' => 'my_function_name' : (required) The function that displays the page content for the menu page. 
  76. * 'icon_url' => 'http://my_icon.png' : (optional) The url to the icon to be used for this menu. 
  77. * 'position' => 50 : (optional) The position in the menu order this menu should appear. 
  78. * By default, if this parameter is omitted, the menu will appear at the bottom of the menu structure. 
  79. * 'admin_url' => 'admin.php' : (required) The admin url : admin.php , options-general.php 
  80. * 'callback_function'=> 'my_callback_function': (optional) The callback function is called when this page does not have tab 
  81. * 'script_function' => 'my_script_function' : (optional) The script function that only include for this page. 
  82. * 'view_doc' => '' : (optional) Support html. The text show on the heading 
  83. * ),  
  84. * array ( 
  85. * 'type' => 'submenu' : (required) add it as sub menu on left sidebar of Dashboard 
  86. * 'parent_slug' => 'quotes-orders-mode' : (required) The slug name for the parent menu. 
  87. * 'page_title' => 'Quotes & Orders Mode' : (required) The text to be displayed in the title tags of the page when the menu is selected 
  88. * 'menu_title' => 'Quotes & Orders Mode' : (required) The text to be displayed in the title tags of the page when the menu is selected 
  89. * 'capability' => 'manage_options' : (required) The capability required for this menu to be displayed to the user. 
  90. * View instruction at http://codex.wordpress.org/Roles_and_Capabilities 
  91. * 'menu_slug' => 'quotes-orders-mode' : (required) The slug name to refer to this menu by. 
  92. * 'function' => 'my_function_name' : (required) The function that displays the page content for the menu page. 
  93. * 'admin_url' => 'admin.php' : (required) The admin url : admin.php , options-general.php 
  94. * 'callback_function'=> 'my_callback_function': (optional) The callback function is called when this page does not have tab 
  95. * 'script_function' => 'my_script_function' : (optional) The script function that only include for this page. 
  96. * 'view_doc' => '' : (optional) Support html. The text show on the heading 
  97. * ) 
  98. * ) 
  99. * 
  100. */ 
  101. public function add_admin_menu() { 
  102.  
  103. $this->admin_menu = apply_filters( $this->plugin_name . '_add_admin_menu', $this->admin_menu ); 
  104.  
  105. /**-----------------------------------------------------------------------------------*/ 
  106. /** register_admin_menu() */ 
  107. /* Setup the Admin menu in WordPress 
  108. /**-----------------------------------------------------------------------------------*/ 
  109. public function register_admin_menu() { 
  110.  
  111. if ( is_array( $this->admin_menu ) && count( $this->admin_menu ) > 0 ) { 
  112. foreach ( $this->admin_menu as $menu_item ) { 
  113. if ( ! isset( $menu_item['type'] ) || trim( $menu_item['type'] ) == '' ) continue; 
  114.  
  115. switch( $menu_item['type'] ) { 
  116.  
  117. case 'menu': 
  118.  
  119. $menu_page = add_menu_page( esc_html( $menu_item['page_title'] ), esc_html( $menu_item['menu_title'] ), $menu_item['capability'], $menu_item['menu_slug'] , $menu_item['function'], $menu_item['icon_url'], $menu_item['position'] ); 
  120.  
  121. if ( isset( $menu_item['script_function'] ) && trim( $menu_item['script_function'] ) != '' ) 
  122. add_action( "admin_print_scripts-" . $menu_page, $menu_item['script_function'] ); 
  123.  
  124. break; 
  125.  
  126. case 'submenu': 
  127.  
  128. $submenu_page = add_submenu_page( $menu_item['parent_slug'] , esc_html( $menu_item['page_title'] ), esc_html( $menu_item['menu_title'] ), $menu_item['capability'], $menu_item['menu_slug'] , $menu_item['function'] ); 
  129.  
  130. if ( isset( $menu_item['script_function'] ) && trim( $menu_item['script_function'] ) != '' ) 
  131. add_action( "admin_print_scripts-" . $submenu_page, $menu_item['script_function'] ); 
  132.  
  133. break; 
  134.  
  135.  
  136.  
  137. /**-----------------------------------------------------------------------------------*/ 
  138. /** add_admin_pages() */ 
  139. /* Get list page for Admin UI can include scripts and styles at header and footer 
  140. /**-----------------------------------------------------------------------------------*/ 
  141. public function add_admin_pages( $admin_pages ) { 
  142.  
  143. if ( ! is_array( $admin_pages ) ) $admin_pages = array(); 
  144.  
  145. if ( is_array( $this->admin_menu ) && count( $this->admin_menu ) > 0 ) { 
  146. foreach ( $this->admin_menu as $menu_item ) { 
  147. if ( ! isset( $menu_item['type'] ) || trim( $menu_item['type'] ) == '' ) continue; 
  148.  
  149. switch( $menu_item['type'] ) { 
  150.  
  151. case 'menu': 
  152. case 'submenu': 
  153. if ( ! in_array( $menu_item['menu_slug'], $admin_pages ) ) 
  154. $admin_pages[] = $menu_item['menu_slug']; 
  155. break; 
  156.  
  157.  
  158. return $admin_pages; 
  159.  
  160. /**-----------------------------------------------------------------------------------*/ 
  161. /** admin_settings_page() */ 
  162. /* Show Settings Page Layout 
  163. /**-----------------------------------------------------------------------------------*/ 
  164. public function admin_settings_page( $page_data = array() ) { 
  165. global $current_tab; 
  166.  
  167. if ( ! is_array( $page_data ) || count( $page_data ) < 1 ) return; 
  168.  
  169. $current_page = $page_data['menu_slug']; 
  170.  
  171. do_action( $this->plugin_name . '_page_start' ); 
  172. do_action( $this->plugin_name . '-' . $current_page . '_page_start' ); 
  173.  
  174. ?> 
  175. <div class="wrap"> 
  176. <div class="icon32 icon32-a3rev-ui-settings icon32-a3rev<?php echo $current_page; ?>" id="icon32-a3rev<?php echo $current_page; ?>"><br /></div> 
  177. <?php 
  178. $tabs = apply_filters( $this->plugin_name . '-' . $current_page . '_settings_tabs_array', array() ); 
  179.  
  180. if ( ! is_array( $tabs ) || count( $tabs ) < 1 ) { 
  181. ?> 
  182. <h2> 
  183. <?php 
  184. if ( $page_data !== false) { 
  185. echo esc_html( $page_data['page_title'] ); 
  186. if ( isset( $page_data['view_doc'] ) ) echo $page_data['view_doc']; 
  187. ?> 
  188. </h2> 
  189. <div style="width:100%; float:left;"> 
  190. <?php if ( isset( $page_data['callback_function'] ) && ! empty( $page_data['callback_function'] ) ) call_user_func( $page_data['callback_function'] ); ?> 
  191. </div> 
  192. <?php 
  193. } else { 
  194. ?> 
  195. <h2 class="nav-tab-wrapper"> 
  196. <?php 
  197. // Get current tab 
  198. $current_tab = ( empty( $_GET['tab'] ) ) ? '' : sanitize_text_field( urldecode( $_GET['tab'] ) ); 
  199.  
  200. $activated_first_tab = false; 
  201. $tab_data = false; 
  202. foreach ( $tabs as $tab ) { 
  203. echo '<a href="' . add_query_arg( array( 'page' => $current_page, 'tab' => $tab['name'] ), admin_url( $page_data['admin_url'] ) ) . '" class="nav-tab '; 
  204. if ( $current_tab == '' && $activated_first_tab === false ) { 
  205. echo 'nav-tab-active'; 
  206. $activated_first_tab = true; 
  207. $current_tab = $tab['name']; 
  208. $tab_data = $tab; 
  209. } elseif ( $current_tab == $tab['name'] ) { 
  210. echo 'nav-tab-active'; 
  211. $tab_data = $tab; 
  212. echo '">' . $tab['label'] . '</a>'; 
  213.  
  214. do_action( $this->plugin_name . '-' . $current_page . '_settings_tabs' ); 
  215. ?> 
  216. </h2> 
  217. <div style="width:100%; float:left;"> 
  218. <?php 
  219. if ( $tab_data !== false && isset ( $tab_data['callback_function'] ) && !empty( $tab_data['callback_function'] ) ) { 
  220. call_user_func( $tab_data['callback_function'] ); 
  221. } else { 
  222. do_action( $this->plugin_name . '-' . $current_page . '_settings_tabs_' . $current_tab ); 
  223. ?> 
  224. </div> 
  225. <?php 
  226. ?> 
  227. <div style="clear:both; margin-bottom:20px;"></div> 
  228. </div> 
  229. <?php 
  230.  
  231. do_action( $this->plugin_name . '_page_end' ); 
  232. do_action( $this->plugin_name . '-' . $current_page . '_page_end' ); 
  233.  
  234. /**-----------------------------------------------------------------------------------*/ 
  235. /** admin_settings_tab() */ 
  236. /* Show Settings Tab Layout 
  237. /**-----------------------------------------------------------------------------------*/ 
  238. public function admin_settings_tab( $current_page = '', $tab_data = array() ) { 
  239. global $current_subtab; 
  240.  
  241. if ( ! is_array( $tab_data ) || count( $tab_data ) < 1 ) return; 
  242.  
  243. $current_tab = $tab_data['name']; 
  244.  
  245. do_action( $this->plugin_name . '-' . $current_page . '_tab_start' ); 
  246. do_action( $this->plugin_name . '-' . $current_tab . '_tab_start' ); 
  247.  
  248. $subtabs = apply_filters( $this->plugin_name . '-' . $current_tab . '_settings_subtabs_array', array() ); 
  249.  
  250. if ( is_array( $subtabs ) && count( $subtabs ) > 0 ) { 
  251.  
  252. ?> 
  253. <div class="a3_subsubsub_section"> 
  254. <ul class="subsubsub"> 
  255. <?php 
  256. // Get current subtab 
  257. $current_subtab = ( empty( $_REQUEST['subtab'] ) ) ? '' : sanitize_text_field( urldecode( str_replace('#', '', $_REQUEST['subtab'] ) ) ); 
  258. $separate_text = ''; 
  259. $activated_first_subtab = false; 
  260. foreach ( $subtabs as $subtab ) { 
  261. echo '<li>' . $separate_text . '<a href="#' . trim( $subtab['name'] ) . '" class="'; 
  262. if ( $current_subtab == '' && $activated_first_subtab === false ) { 
  263. echo 'current'; 
  264. $activated_first_subtab = true; 
  265. $current_subtab = $subtab['name']; 
  266. } elseif ( $current_subtab == $subtab['name'] ) { 
  267. echo 'current'; 
  268. echo '">' . $subtab['label'] . '</a></li>' . "\n"; 
  269.  
  270. $separate_text = ' | '; 
  271.  
  272. do_action( $this->plugin_name . '-' . $current_tab . '_settings_subtabs' ); 
  273. ?> 
  274. </ul> 
  275. <br class="clear"> 
  276. <?php 
  277. foreach ( $subtabs as $subtab ) { 
  278. ?> 
  279. <div class="section" id="<?php echo trim( $subtab['name'] ); ?>"> 
  280. <?php if ( isset( $subtab['callback_function'] ) && !empty( $subtab['callback_function'] ) ) call_user_func( $subtab['callback_function'] ); ?> 
  281. </div> 
  282. <?php 
  283.  
  284. do_action( $this->plugin_name . '-' . $current_tab . '_settings_subtabs_content' ); 
  285. ?> 
  286.  
  287. </div> 
  288. <?php 
  289.  
  290. do_action( $this->plugin_name . '-' . $current_page . '_tab_end' ); 
  291. do_action( $this->plugin_name . '-' . $current_tab . '_tab_end' ); 
  292.  
  293. global $wc_dgallery_admin_init; 
  294. $wc_dgallery_admin_init = new WC_Dynamic_Gallery_Admin_Init(); 
  295.  
  296. ?> 
.