YIT_Plugin_Panel

YIT Plugin Panel.

Defined (1)

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

/plugin-fw/lib/yit-plugin-panel.php  
  1. /* @class YIT_Plugin_Panel 
  2. * @package Yithemes 
  3. * @since 1.0 
  4. * @author Your Inspiration Themes 
  5. */ 
  6.  
  7. class YIT_Plugin_Panel { 
  8.  
  9. /** 
  10. * @var string version of class 
  11. */ 
  12. public $version = '1.0.0'; 
  13.  
  14. /** 
  15. * @var array a setting list of parameters 
  16. */ 
  17. public $settings = array(); 
  18.  
  19. /** 
  20. * @var array 
  21. */ 
  22. protected $_tabs_path_files; 
  23.  
  24. /** 
  25. * @var array 
  26. */ 
  27. private $_main_array_options = array(); 
  28.  
  29. /** 
  30. * @var YIT_Plugin_Panel_Sidebar 
  31. */ 
  32. public $sidebar; 
  33.  
  34. /** 
  35. * @var array 
  36. */ 
  37. public $links; 
  38.  
  39. /** 
  40. * Constructor 
  41. * @since 1.0 
  42. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  43. * @param array $args 
  44. */ 
  45. public function __construct( $args = array() ) { 
  46.  
  47. if ( ! empty( $args ) ) { 
  48.  
  49. $default_args = array( 
  50. 'parent_slug' => 'edit.php?',  
  51. 'page_title' => __( 'Plugin Settings', 'yith-plugin-fw' ),  
  52. 'menu_title' => __( 'Settings', 'yith-plugin-fw' ),  
  53. 'capability' => 'manage_options',  
  54. 'icon_url' => '',  
  55. 'position' => null 
  56. ); 
  57.  
  58. $this->settings = wp_parse_args( $args, $default_args ); 
  59. $this->_tabs_path_files = $this->get_tabs_path_files(); 
  60.  
  61. if ( isset( $this->settings['create_menu_page'] ) && $this->settings['create_menu_page'] ) { 
  62. $this->add_menu_page(); 
  63.  
  64. if ( !empty( $this->settings[ 'links' ] ) ) { 
  65. $this->links = $this->settings[ 'links' ]; 
  66.  
  67. add_action( 'admin_init', array( $this, 'register_settings' ) ); 
  68. add_action( 'admin_menu', array( $this, 'add_setting_page' ), 20 ); 
  69. add_action( 'admin_menu', array( $this, 'add_premium_version_upgrade_to_menu' ), 100 ); 
  70. add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_menu' ), 100 ); 
  71. add_action( 'admin_init', array( $this, 'add_fields' ) ); 
  72.  
  73. /** add YIT Plugin sidebar */ 
  74. $this->sidebar = YIT_Plugin_Panel_Sidebar::instance( $this ); 
  75.  
  76. add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); 
  77.  
  78. /** 
  79. * Add Menu page link 
  80. * @return void 
  81. * @since 1.0 
  82. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  83. */ 
  84. public function add_menu_page() { 
  85. global $admin_page_hooks; 
  86.  
  87. if( ! isset( $admin_page_hooks['yit_plugin_panel'] ) ) { 
  88. $position = apply_filters( 'yit_plugins_menu_item_position', '62.32' ); 
  89. // YITH Plugins text must not be translated 
  90. current_user_can( 'manage_options' ) && add_menu_page( 'yit_plugin_panel', 'YITH Plugins', 'manage_options', 'yit_plugin_panel', NULL, YIT_CORE_PLUGIN_URL . '/assets/images/yithemes-icon.png', $position ); 
  91.  
  92. /** 
  93. * Remove duplicate submenu 
  94. * Submenu page hack: Remove the duplicate YIT Plugin link on subpages 
  95. * @return void 
  96. * @since 1.0 
  97. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  98. */ 
  99. public function remove_duplicate_submenu_page() { 
  100. /** === Duplicate Items Hack === */ 
  101. remove_submenu_page( 'yit_plugin_panel', 'yit_plugin_panel' ); 
  102.  
  103. /** 
  104. * Enqueue script and styles in admin side 
  105. * Add style and scripts to administrator 
  106. * @return void 
  107. * @since 1.0 
  108. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  109. */ 
  110. public function admin_enqueue_scripts() { 
  111.  
  112. global $wp_scripts, $pagenow; 
  113.  
  114. //scripts 
  115. wp_enqueue_media(); 
  116. wp_enqueue_script( 'jquery-ui' ); 
  117. wp_enqueue_script( 'jquery-ui-core' ); 
  118. wp_enqueue_script( 'jquery-ui-slider' ); 
  119. wp_enqueue_script( 'jquery-ui-dialog' ); 
  120. wp_enqueue_script( 'jquery-chosen', YIT_CORE_PLUGIN_URL . '/assets/js/chosen/chosen.jquery.js', array( 'jquery' ), '1.1.0', true ); 
  121. wp_register_script( 'yit-plugin-panel', YIT_CORE_PLUGIN_URL . '/assets/js/yit-plugin-panel.js', array( 'jquery', 'jquery-chosen', 'wp-color-picker'), $this->version, true ); 
  122. wp_register_script( 'codemirror', YIT_CORE_PLUGIN_URL . '/assets/js/codemirror/codemirror.js', array( 'jquery' ), $this->version, true ); 
  123. wp_register_script( 'codemirror-javascript', YIT_CORE_PLUGIN_URL . '/assets/js/codemirror/javascript.js', array( 'jquery', 'codemirror' ), $this->version, true ); 
  124. wp_register_script( 'colorbox', YIT_CORE_PLUGIN_URL . '/assets/js/jquery.colorbox.js', array( 'jquery' ), '1.6.3', true ); 
  125. wp_enqueue_script( 'yith_how_to', YIT_CORE_PLUGIN_URL . '/assets/js/how-to.js', array('jquery'), $this->version, true ); 
  126.  
  127. //styles 
  128. $jquery_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2'; 
  129. wp_register_style( 'codemirror', YIT_CORE_PLUGIN_URL . '/assets/css/codemirror/codemirror.css' ); 
  130. wp_enqueue_style( 'jquery-ui-overcast', YIT_CORE_PLUGIN_URL . '/assets/css/overcast/jquery-ui-custom/jquery-ui-1.8.9.custom.css', false, '1.8.9', 'all' ); 
  131. wp_register_style( 'yit-plugin-style', YIT_CORE_PLUGIN_URL . '/assets/css/yit-plugin-panel.css', array(), $this->version ); 
  132. wp_enqueue_style( 'raleway-font', '//fonts.googleapis.com/css?family=Raleway:400, 500, 600, 700, 800, 100, 200, 300, 900' ); 
  133. wp_enqueue_style( 'jquery-chosen', YIT_CORE_PLUGIN_URL . '/assets/css/chosen/chosen.css' ); 
  134. wp_enqueue_style( 'yit-jquery-ui-style', '//code.jquery.com/ui/' . $jquery_version . '/themes/smoothness/jquery-ui.css', array(), $jquery_version ); 
  135. wp_register_style( 'colorbox', YIT_CORE_PLUGIN_URL . '/assets/css/colorbox.css', array(), $this->version ); 
  136. wp_register_style( 'yit-upgrade-to-pro', YIT_CORE_PLUGIN_URL . '/assets/css/yit-upgrade-to-pro.css', array( 'colorbox' ), $this->version ); 
  137.  
  138. if( ( 'admin.php' == $pagenow && strpos( get_current_screen()->id, 'yith-plugins_page' ) !== false ) || apply_filters( 'yit_plugin_panel_asset_loading', false ) ) { 
  139. wp_enqueue_style( 'yit-plugin-style' ); 
  140. wp_enqueue_script( 'yit-plugin-panel' ); 
  141.  
  142. if( 'admin.php' == $pagenow && strpos( get_current_screen()->id, 'yith_upgrade_premium_version' ) !== false ) { 
  143. wp_enqueue_style( 'yit-upgrade-to-pro' ); 
  144. wp_enqueue_script( 'colorbox' ); 
  145.  
  146.  
  147. /** 
  148. * Register Settings 
  149. * Generate wp-admin settings pages by registering your settings and using a few callbacks to control the output 
  150. * @return void 
  151. * @since 1.0 
  152. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  153. */ 
  154. public function register_settings() { 
  155. register_setting( 'yit_' . $this->settings['parent'] . '_options', 'yit_' . $this->settings['parent'] . '_options', array( $this, 'options_validate' ) ); 
  156.  
  157. /** 
  158. * Options Validate 
  159. * a callback function called by Register Settings function 
  160. * @param $input 
  161. * @return array validate input fields 
  162. * @since 1.0 
  163. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  164. */ 
  165. public function options_validate( $input ) { 
  166.  
  167. $current_tab = ! empty( $input['current_tab'] ) ? $input['current_tab'] : 'general'; 
  168.  
  169. $yit_options = $this->get_main_array_options(); 
  170.  
  171. // default 
  172. $valid_input = $this->get_options(); 
  173.  
  174. $submit = ( ! empty( $input['submit-general'] ) ? true : false ); 
  175. $reset = ( ! empty( $input['reset-general'] ) ? true : false ); 
  176.  
  177. foreach ( $yit_options[$current_tab] as $section => $data ) { 
  178. foreach ( $data as $option ) { 
  179. if ( isset( $option['sanitize_call'] ) && isset( $option['id'] ) ) { //yiw_debug($option, false); 
  180. if ( is_array( $option['sanitize_call'] ) ) : 
  181. foreach ( $option['sanitize_call'] as $callback ) { 
  182. if ( is_array( $input[$option['id']] ) ) { 
  183. $valid_input[$option['id']] = array_map( $callback, $input[$option['id']] ); 
  184. else { 
  185. $valid_input[$option['id']] = call_user_func( $callback, $input[$option['id']] ); 
  186. else : 
  187. if ( is_array( $input[$option['id']] ) ) { 
  188. $valid_input[$option['id']] = array_map( $option['sanitize_call'], $input[$option['id']] ); 
  189. else { 
  190. $valid_input[$option['id']] = call_user_func( $option['sanitize_call'], $input[$option['id']] ); 
  191. endif; 
  192. else { 
  193. if ( isset( $option['id'] ) ) { 
  194. if ( isset( $input[$option['id']] ) ) { 
  195. $valid_input[$option['id']] = $input[$option['id']]; 
  196. else { 
  197. $valid_input[$option['id']] = 'no'; 
  198.  
  199.  
  200.  
  201. return $valid_input; 
  202.  
  203. /** 
  204. * Add Setting SubPage 
  205. * add Setting SubPage to wordpress administrator 
  206. * @return array validate input fields 
  207. * @since 1.0 
  208. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  209. */ 
  210. public function add_setting_page() { 
  211. $this->settings['icon_url'] = isset( $this->settings['icon_url'] ) ? $this->settings['icon_url'] : ''; 
  212. $this->settings['position'] = isset( $this->settings['position'] ) ? $this->settings['position'] : null; 
  213. $parent = $this->settings['parent_slug'] . $this->settings['parent_page']; 
  214.  
  215. if ( ! empty( $parent ) ) { 
  216. add_submenu_page( $parent, $this->settings['page_title'], $this->settings['menu_title'], $this->settings['capability'], $this->settings['page'], array( $this, 'yit_panel' ) ); 
  217. } else { 
  218. add_menu_page( $this->settings['page_title'], $this->settings['menu_title'], $this->settings['capability'], $this->settings['page'], array( $this, 'yit_panel' ), $this->settings['icon_url'], $this->settings['position'] ); 
  219. /** === Duplicate Items Hack === */ 
  220. $this->remove_duplicate_submenu_page(); 
  221. do_action( 'yit_after_add_settings_page' ); 
  222.  
  223.  
  224.  
  225. /** 
  226. * Add Premium Version upgrade menu item 
  227. * @return void 
  228. * @since 2.9.13 
  229. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  230. */ 
  231. public function add_premium_version_upgrade_to_menu() { 
  232. global $submenu; 
  233.  
  234. if( apply_filters( 'yit_show_upgrade_to_premium_version', ! isset( $submenu['yit_plugin_panel']['how_to'] ) ) ) { 
  235. $submenu['yit_plugin_panel']['how_to'] = array( 
  236. sprintf( '%s%s%s', '<span id="yith-how-to-premium">', __( 'How to install premium version', 'yith-plugin-fw' ), '</span>' ),  
  237. 'install_plugins',  
  238. '//support.yithemes.com/hc/en-us/articles/217840988',  
  239. __( 'How to install premium version', 'yith-plugin-fw' ),  
  240. ); 
  241.  
  242. /** 
  243. * Show a tabbed panel to setting page 
  244. * a callback function called by add_setting_page => add_submenu_page 
  245. * @return void 
  246. * @since 1.0 
  247. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  248. */ 
  249. public function yit_panel() { 
  250.  
  251. $tabs = ''; 
  252. $current_tab = $this->get_current_tab(); 
  253. $yit_options = $this->get_main_array_options(); 
  254.  
  255. // tabs 
  256. foreach ( $this->settings['admin-tabs'] as $tab => $tab_value ) { 
  257. $active_class = ( $current_tab == $tab ) ? ' nav-tab-active' : ''; 
  258. $tabs .= '<a class="nav-tab' . $active_class . '" href="?' . $this->settings['parent_page'] . '&page=' . $this->settings['page'] . '&tab=' . $tab . '">' . $tab_value . '</a>'; 
  259. ?> 
  260. <div id="icon-themes" class="icon32"><br /></div> 
  261. <h2 class="yith nav-tab-wrapper"> 
  262. <?php echo $tabs ?> 
  263. </h2> 
  264. <?php 
  265. $custom_tab_action = $this->is_custom_tab( $yit_options, $current_tab ); 
  266. $hide_sidebar = $this->hide_sidebar(); 
  267. if ( $custom_tab_action ) { 
  268. $this->print_custom_tab( $custom_tab_action, $hide_sidebar ); 
  269. return; 
  270. ?> 
  271. <?php $this->print_video_box(); ?> 
  272. <?php 
  273. $panel_content_class = !$hide_sidebar ? apply_filters( 'yit_admin_panel_content_class', 'yit-admin-panel-content-wrap' ) : 'yit-admin-panel-content-wrap-no-sidebar'; 
  274. ?> 
  275. <div id="wrap" class="plugin-option yit-admin-panel-container"> 
  276. <?php $this->message(); ?> 
  277. <div class="<?php echo $panel_content_class; ?>"> 
  278. <h2><?php echo $this->get_tab_title() ?></h2> 
  279. <?php if ( $this->is_show_form() ) : ?> 
  280. <form method="post" action="options.php"> 
  281. <?php do_settings_sections( 'yit' ); ?> 
  282. <p> </p> 
  283. <?php settings_fields( 'yit_' . $this->settings['parent'] . '_options' ); ?> 
  284. <input type="hidden" name="<?php echo $this->get_name_field( 'current_tab' ) ?>" value="<?php echo esc_attr( $current_tab ) ?>" /> 
  285. <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'yith-plugin-fw' ) ?>" style="float:left;margin-right:10px;" /> 
  286. </form> 
  287. <form method="post"> 
  288. <?php $warning = __( 'If you continue with this action, you will reset all options in this page.', 'yith-plugin-fw' ) ?> 
  289. <input type="hidden" name="yit-action" value="reset" /> 
  290. <input type="submit" name="yit-reset" class="button-secondary" value="<?php _e( 'Reset to default', 'yith-plugin-fw' ) ?>" onclick="return confirm('<?php echo $warning . '\n' . __( 'Are you sure?', 'yith-plugin-fw' ) ?>');" /> 
  291. </form> 
  292. <p> </p> 
  293. <?php endif ?> 
  294. </div> 
  295. <?php 
  296. /** 
  297. * Add panel Sidebar 
  298. */ 
  299. if ( !$hide_sidebar ) 
  300. $this->print_panel_sidebar(); 
  301. ?> 
  302. </div> 
  303. <?php 
  304.  
  305. public function is_custom_tab( $options, $current_tab ) { 
  306. foreach ( $options[$current_tab] as $section => $option ) { 
  307. if ( isset( $option['type'] ) && isset( $option['action'] ) && 'custom_tab' == $option['type'] && ! empty( $option['action'] ) ) { 
  308. return $option['action']; 
  309. else { 
  310. return false; 
  311. return false; 
  312.  
  313. /** 
  314. * Print the panel sidebar 
  315. * @return void 
  316. * @since 1.0 
  317. * @author Leanza Francesco <leanzafrancesco@gmail.com> 
  318. */ 
  319. public function print_panel_sidebar() { 
  320. $this->sidebar->print_panel_sidebar(); 
  321.  
  322. /** 
  323. * @param $options 
  324. * @param $current_tab 
  325. * @return bool 
  326. * @author Leanza Francesco <leanzafrancesco@gmail.com> 
  327. */ 
  328. public function hide_sidebar( $options = '', $current_tab = '' ) { 
  329. if ( $options === '' ) 
  330. $options = $this->get_main_array_options(); 
  331. if ( $current_tab === '' ) 
  332. $current_tab = $this->get_current_tab(); 
  333.  
  334. $hide = false; 
  335.  
  336. foreach ( $options[ $current_tab ] as $section => $option ) { 
  337. if ( isset( $option[ 'hide_sidebar' ] ) ) { 
  338. $hide = !!$option[ 'hide_sidebar' ]; 
  339. break; 
  340.  
  341. $page = isset( $this->settings[ 'page' ] ) ? $this->settings[ 'page' ] : ''; 
  342.  
  343. return apply_filters( 'yit_panel_hide_sidebar', $hide, $page ); 
  344.  
  345. /** 
  346. * Fire the action to print the custom tab 
  347. * @param string $action Action to fire 
  348. * @param bool $hide_sidebar 
  349. * @return void 
  350. * @since 1.0 
  351. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  352. * @author Leanza Francesco <leanzafrancesco@gmail.com> 
  353. */ 
  354. public function print_custom_tab( $action, $hide_sidebar = false ) { 
  355. if ( !$hide_sidebar ) { 
  356. $panel_content_class = apply_filters( 'yit_admin_panel_content_class', 'yit-admin-panel-content-wrap' ) ; 
  357. echo "<div class='yit-admin-panel-container'>"; 
  358. echo "<div class='$panel_content_class'>"; 
  359.  
  360. do_action( $action ); 
  361.  
  362. echo "</div>"; 
  363. $this->print_panel_sidebar(); 
  364. echo "</div>"; 
  365. } else { 
  366. do_action( $action ); 
  367.  
  368. /** 
  369. * Add sections and fields to setting panel 
  370. * read all options and show sections and fields 
  371. * @return void 
  372. * @since 1.0 
  373. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  374. */ 
  375. public function add_fields() { 
  376. $yit_options = $this->get_main_array_options(); 
  377. $current_tab = $this->get_current_tab(); 
  378.  
  379. if ( ! $current_tab ) { 
  380. return; 
  381. foreach ( $yit_options[$current_tab] as $section => $data ) { 
  382. add_settings_section( "yit_settings_{$current_tab}_{$section}", $this->get_section_title( $section ), $this->get_section_description( $section ), 'yit' ); 
  383. foreach ( $data as $option ) { 
  384. if ( isset( $option['id'] ) && isset( $option['type'] ) && isset( $option['name'] ) ) { 
  385. add_settings_field( "yit_setting_" . $option['id'], $option['name'], array( $this, 'render_field' ), 'yit', "yit_settings_{$current_tab}_{$section}", array( 'option' => $option, 'label_for' => $this->get_id_field( $option['id'] ) ) ); 
  386.  
  387.  
  388. /** 
  389. * Add the tabs to admin bar menu 
  390. * set all tabs of settings page on wp admin bar 
  391. * @return void|array return void when capability is false 
  392. * @since 1.0 
  393. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  394. */ 
  395. public function add_admin_bar_menu() { 
  396.  
  397. global $wp_admin_bar; 
  398.  
  399. if ( ! current_user_can( 'manage_options' ) ) { 
  400. return; 
  401.  
  402. if ( ! empty( $this->settings['admin_tabs'] ) ) { 
  403. foreach ( $this->settings['admin-tabs'] as $item => $title ) { 
  404.  
  405. $wp_admin_bar->add_menu( array( 
  406. 'parent' => $this->settings['parent'],  
  407. 'title' => $title,  
  408. 'id' => $this->settings['parent'] . '-' . $item,  
  409. 'href' => admin_url( 'themes.php' ) . '?page=' . $this->settings['parent_page'] . '&tab=' . $item 
  410. ) ); 
  411.  
  412.  
  413. /** 
  414. * Get current tab 
  415. * get the id of tab showed, return general is the current tab is not defined 
  416. * @return string 
  417. * @since 1.0 
  418. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  419. */ 
  420. function get_current_tab() { 
  421. $admin_tabs = array_keys( $this->settings['admin-tabs'] ); 
  422.  
  423. if ( ! isset( $_GET['page'] ) || $_GET['page'] != $this->settings['page'] ) { 
  424. return false; 
  425. if ( isset( $_REQUEST['yit_tab_options'] ) ) { 
  426. return $_REQUEST['yit_tab_options']; 
  427. elseif ( isset( $_GET['tab'] ) && isset( $this->_tabs_path_files[$_GET['tab']] ) ) { 
  428. return $_GET['tab']; 
  429. elseif ( isset( $admin_tabs[0] ) ) { 
  430. return $admin_tabs[0]; 
  431. else { 
  432. return 'general'; 
  433.  
  434.  
  435. /** 
  436. * Message 
  437. * define an array of message and show the content od message if 
  438. * is find in the query string 
  439. * @return void 
  440. * @since 1.0 
  441. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  442. */ 
  443. public function message() { 
  444.  
  445. $message = array( 
  446. 'element_exists' => $this->get_message( '<strong>' . __( 'The element you have entered already exists. Please, enter another name.', 'yith-plugin-fw' ) . '</strong>', 'error', false ),  
  447. 'saved' => $this->get_message( '<strong>' . __( 'Settings saved', 'yith-plugin-fw' ) . '.</strong>', 'updated', false ),  
  448. 'reset' => $this->get_message( '<strong>' . __( 'Settings reset', 'yith-plugin-fw' ) . '.</strong>', 'updated', false ),  
  449. 'delete' => $this->get_message( '<strong>' . __( 'Element deleted correctly.', 'yith-plugin-fw' ) . '</strong>', 'updated', false ),  
  450. 'updated' => $this->get_message( '<strong>' . __( 'Element updated correctly.', 'yith-plugin-fw' ) . '</strong>', 'updated', false ),  
  451. 'settings-updated' => $this->get_message( '<strong>' . __( 'Element updated correctly.', 'yith-plugin-fw' ) . '</strong>', 'updated', false ),  
  452. 'imported' => $this->get_message( '<strong>' . __( 'Database imported correctly.', 'yith-plugin-fw' ) . '</strong>', 'updated', false ),  
  453. 'no-imported' => $this->get_message( '<strong>' . __( 'An error has occurred during import. Please try again.', 'yith-plugin-fw' ) . '</strong>', 'error', false ),  
  454. 'file-not-valid' => $this->get_message( '<strong>' . __( 'The added file is not valid.', 'yith-plugin-fw' ) . '</strong>', 'error', false ),  
  455. 'cant-import' => $this->get_message( '<strong>' . __( 'Sorry, import is disabled.', 'yith-plugin-fw' ) . '</strong>', 'error', false ),  
  456. 'ord' => $this->get_message( '<strong>' . __( 'Sorting successful.', 'yith-plugin-fw' ) . '</strong>', 'updated', false ) 
  457. ); 
  458.  
  459. foreach ( $message as $key => $value ) { 
  460. if ( isset( $_GET[$key] ) ) { 
  461. echo $message[$key]; 
  462.  
  463.  
  464. /** 
  465. * Get Message 
  466. * return html code of message 
  467. * @param $message 
  468. * @param string $type can be 'error' or 'updated' 
  469. * @param bool $echo 
  470. * @return void|string 
  471. * @since 1.0 
  472. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  473. */ 
  474. public function get_message( $message, $type = 'error', $echo = true ) { 
  475. $message = '<div id="message" class="' . $type . ' fade"><p>' . $message . '</p></div>'; 
  476. if ( $echo ) { 
  477. echo $message; 
  478. return $message; 
  479.  
  480.  
  481. /** 
  482. * Get Tab Path Files 
  483. * return an array with filenames of tabs 
  484. * @return array 
  485. * @since 1.0 
  486. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  487. */ 
  488. function get_tabs_path_files() { 
  489.  
  490. $option_files_path = $this->settings['options-path'] . '/'; 
  491.  
  492. $tabs = array(); 
  493.  
  494. foreach ( (array) glob( $option_files_path . '*.php' ) as $filename ) { 
  495. preg_match( '/(.*)-options\.(.*)/', basename( $filename ), $filename_parts ); 
  496.  
  497. if ( ! isset( $filename_parts[1] ) ) { 
  498. continue; 
  499.  
  500. $tab = $filename_parts[1]; 
  501.  
  502. $tabs[$tab] = $filename; 
  503.  
  504. return $tabs; 
  505.  
  506. /** 
  507. * Get main array options 
  508. * return an array with all options defined on options-files 
  509. * @return array 
  510. * @since 1.0 
  511. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  512. */ 
  513. function get_main_array_options() { 
  514. if ( ! empty( $this->_main_array_options ) ) { 
  515. return $this->_main_array_options; 
  516.  
  517. foreach ( $this->settings['admin-tabs'] as $item => $v ) { 
  518. $path = $this->settings['options-path'] . '/' . $item . '-options.php'; 
  519. if ( file_exists( $path ) ) { 
  520. $this->_main_array_options = array_merge( $this->_main_array_options, include $path ); 
  521.  
  522. return $this->_main_array_options; 
  523.  
  524.  
  525. /** 
  526. * Set an array with all default options 
  527. * put default options in an array 
  528. * @return array 
  529. * @since 1.0 
  530. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  531. */ 
  532. public function get_default_options() { 
  533. $yit_options = $this->get_main_array_options(); 
  534. $default_options = array(); 
  535.  
  536. foreach ( $yit_options as $tab => $sections ) { 
  537. foreach ( $sections as $section ) { 
  538. foreach ( $section as $id => $value ) { 
  539. if ( isset( $value['std'] ) && isset( $value['id'] ) ) { 
  540. $default_options[$value['id']] = $value['std']; 
  541.  
  542. unset( $yit_options ); 
  543. return $default_options; 
  544.  
  545.  
  546. /** 
  547. * Get the title of the tab 
  548. * return the title of tab 
  549. * @return string 
  550. * @since 1.0 
  551. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  552. */ 
  553. function get_tab_title() { 
  554. $yit_options = $this->get_main_array_options(); 
  555. $current_tab = $this->get_current_tab(); 
  556.  
  557. foreach ( $yit_options[$current_tab] as $sections => $data ) { 
  558. foreach ( $data as $option ) { 
  559. if ( isset( $option['type'] ) && $option['type'] == 'title' ) { 
  560. return $option['name']; 
  561.  
  562. /** 
  563. * Get the title of the section 
  564. * return the title of section 
  565. * @param $section 
  566. * @return string 
  567. * @since 1.0 
  568. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  569. */ 
  570. function get_section_title( $section ) { 
  571. $yit_options = $this->get_main_array_options(); 
  572. $current_tab = $this->get_current_tab(); 
  573.  
  574. foreach ( $yit_options[$current_tab][$section] as $option ) { 
  575. if ( isset( $option['type'] ) && $option['type'] == 'section' ) { 
  576. return $option['name']; 
  577.  
  578. /** 
  579. * Get the description of the section 
  580. * return the description of section if is set 
  581. * @param $section 
  582. * @return string 
  583. * @since 1.0 
  584. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  585. */ 
  586. function get_section_description( $section ) { 
  587. $yit_options = $this->get_main_array_options(); 
  588. $current_tab = $this->get_current_tab(); 
  589.  
  590. foreach ( $yit_options[$current_tab][$section] as $option ) { 
  591. if ( isset( $option['type'] ) && $option['type'] == 'section' && isset( $option['desc'] ) ) { 
  592. return '<p>' . $option['desc'] . '</p>'; 
  593.  
  594.  
  595. /** 
  596. * Show form when necessary 
  597. * return true if 'showform' is not defined 
  598. * @return bool 
  599. * @since 1.0 
  600. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  601. */ 
  602. function is_show_form() { 
  603. $yit_options = $this->get_main_array_options(); 
  604. $current_tab = $this->get_current_tab(); 
  605.  
  606. foreach ( $yit_options[$current_tab] as $sections => $data ) { 
  607. foreach ( $data as $option ) { 
  608. if ( ! isset( $option['type'] ) || $option['type'] != 'title' ) { 
  609. continue; 
  610. if ( isset( $option['showform'] ) ) { 
  611. return $option['showform']; 
  612. else { 
  613. return true; 
  614.  
  615. /** 
  616. * Get name field 
  617. * return a string with the name of the input field 
  618. * @param string $name 
  619. * @return string 
  620. * @since 1.0 
  621. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  622. */ 
  623. function get_name_field( $name = '' ) { 
  624. return 'yit_' . $this->settings['parent'] . '_options[' . $name . ']'; 
  625.  
  626. /** 
  627. * Get id field 
  628. * return a string with the id of the input field 
  629. * @param string $id 
  630. * @return string 
  631. * @since 1.0 
  632. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  633. */ 
  634. function get_id_field( $id ) { 
  635. return 'yit_' . $this->settings['parent'] . '_options_' . $id; 
  636.  
  637.  
  638. /** 
  639. * Render the field showed in the setting page 
  640. * include the file of the option type, if file do not exists 
  641. * return a text area 
  642. * @param array $param 
  643. * @return void 
  644. * @since 1.0 
  645. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  646. */ 
  647. function render_field( $param ) { 
  648.  
  649. if ( ! empty( $param ) && isset( $param ['option'] ) ) { 
  650. $option = $param ['option']; 
  651. $db_options = $this->get_options(); 
  652.  
  653. $custom_attributes = array(); 
  654.  
  655. if ( ! empty( $option['custom_attributes'] ) && is_array( $option['custom_attributes'] ) ) { 
  656. foreach ( $option['custom_attributes'] as $attribute => $attribute_value ) { 
  657. $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; 
  658.  
  659. $custom_attributes = implode( ' ', $custom_attributes ); 
  660. $std = isset( $option['std'] ) ? $option['std'] : ''; 
  661. $db_value = ( isset( $db_options[$option['id']] ) ) ? $db_options[$option['id']] : $std; 
  662.  
  663. if ( isset( $option['deps'] ) ) { 
  664. $deps = $option['deps']; 
  665. $type = YIT_CORE_PLUGIN_PATH . '/templates/panel/types/' . $option['type'] . '.php'; 
  666. if ( file_exists( $type ) ) { 
  667. include $type; 
  668. else { 
  669. do_action( "yit_panel_{$option['type']}", $option, $db_value, $custom_attributes ); 
  670.  
  671. /** 
  672. * Get options from db 
  673. * return the options from db, if the options aren't defined in the db,  
  674. * get the default options ad add the options in the db 
  675. * @return array 
  676. * @since 1.0 
  677. * @author Emanuela Castorina <emanuela.castorina@yithemes.it> 
  678. */ 
  679. public function get_options() { 
  680. $options = get_option( 'yit_' . $this->settings['parent'] . '_options' ); 
  681. if ( $options === false || ( isset( $_REQUEST['yit-action'] ) && $_REQUEST['yit-action'] == 'reset' ) ) { 
  682. $options = $this->get_default_options(); 
  683. return $options; 
  684.  
  685. /** 
  686. * Show a box panel with specific content in two columns as a new woocommerce type 
  687. * @param array $args 
  688. * @return void 
  689. * @since 1.0 
  690. * @author Emanuela Castorina <emanuela.castorina@yithemes.com> 
  691. */ 
  692. public function add_infobox( $args = array() ) { 
  693. if ( ! empty( $args ) ) { 
  694. extract( $args ); 
  695. require_once( YIT_CORE_PLUGIN_TEMPLATE_PATH . '/panel/boxinfo.php' ); 
  696.  
  697. /** 
  698. * Show a box panel with specific content in two columns as a new woocommerce type 
  699. * @param array $args 
  700. * @return void 
  701. * @since 1.0 
  702. * @author Emanuela Castorina <emanuela.castorina@yithemes.com> 
  703. */ 
  704. public function add_videobox( $args = array() ) { 
  705. if ( ! empty( $args ) ) { 
  706. extract( $args ); 
  707. require_once( YIT_CORE_PLUGIN_TEMPLATE_PATH . '/panel/videobox.php' ); 
  708.  
  709. /** 
  710. * Fire the action to print the custom tab 
  711. * @return void 
  712. * @since 1.0 
  713. * @author Antonino Scarf <antonino.scarfi@yithemes.com> 
  714. */ 
  715. public function print_video_box() { 
  716. $file = $this->settings['options-path'] . '/video-box.php'; 
  717.  
  718. if ( ! file_exists( $file ) ) { 
  719. return;