WC_Dynamic_Gallery_Admin_Init

The WooCommerce Dynamic Gallery LITE WC Dynamic Gallery Admin Init class.

Defined (1)

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

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