WC_Compare_Admin_Init

The WooCommerce Compare Products LITE WC Compare Admin Init class.

Defined (1)

The class is defined in the following location(s).

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