| 1 | <?php |
|---|
| 2 | // don't load directly |
|---|
| 3 | if(!defined('ABSPATH')) { |
|---|
| 4 | header('Status: 403 Forbidden'); |
|---|
| 5 | header('HTTP/1.1 403 Forbidden'); |
|---|
| 6 | exit(); |
|---|
| 7 | } |
|---|
| 8 | |
|---|
| 9 | /** |
|---|
| 10 | * Retrieve Settings Tabs |
|---|
| 11 | * Default sections by tab below |
|---|
| 12 | * @since 1.2.4 |
|---|
| 13 | * @return array |
|---|
| 14 | */ |
|---|
| 15 | function wpematico_get_tools_tabs() { |
|---|
| 16 | $tabs = array(); |
|---|
| 17 | $tabs['tools'] = __('Tools', 'wpematico'); |
|---|
| 18 | $tabs['debug_info'] = __('System Status', 'wpematico'); |
|---|
| 19 | $danger = WPeMatico::get_danger_options(); |
|---|
| 20 | |
|---|
| 21 | if(!empty($danger['wpematico_debug_log_file'])) { |
|---|
| 22 | $tabs['debug_log'] = __('Logs', 'wpematico'); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | return apply_filters('wpematico_tools_tabs', $tabs); |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | /** |
|---|
| 30 | * Retrieve debug_info tools sections |
|---|
| 31 | * Use in same way to add sections to the different tabs "wpematico_get_'tab-key'_sections" |
|---|
| 32 | * @since 2.3.9 |
|---|
| 33 | * @return array with Settings tab sections |
|---|
| 34 | */ |
|---|
| 35 | //function wpematico_get_debug_log_sections() { |
|---|
| 36 | // $danger = WPeMatico::get_danger_options(); |
|---|
| 37 | // $sections = array(); |
|---|
| 38 | // |
|---|
| 39 | // if(!empty($danger['wpematico_debug_log_file'])) { |
|---|
| 40 | // $sections['debug_log_file'] = __('Debug Log File', 'wpematico'); |
|---|
| 41 | // $sections = apply_filters('wpematico_get_debug_sections', $sections); |
|---|
| 42 | // } |
|---|
| 43 | // |
|---|
| 44 | // return $sections; |
|---|
| 45 | // |
|---|
| 46 | //} |
|---|
| 47 | |
|---|
| 48 | function wpematico_get_debug_info_sections() { |
|---|
| 49 | $sections = array(); |
|---|
| 50 | $sections['debug_file'] = __('Debug File', 'wpematico'); |
|---|
| 51 | $sections['danger_zone'] = __('Danger Zone', 'wpematico'); |
|---|
| 52 | $sections = apply_filters('wpematico_get_debug_sections', $sections); |
|---|
| 53 | |
|---|
| 54 | return $sections; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | function wpematico_get_tools_sections() { |
|---|
| 58 | $sections = array(); |
|---|
| 59 | $sections['tools'] = __('WPeMatico Tools', 'wpematico'); |
|---|
| 60 | $sections['feed_viewer'] = __('Feed Viewer', 'wpematico'); |
|---|
| 61 | $sections = apply_filters('wpematico_get_debug_sections', $sections); |
|---|
| 62 | |
|---|
| 63 | return $sections; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | //Make Tabs calling actions and Sections if exist |
|---|
| 67 | function wpematico_tools_page() { |
|---|
| 68 | global $pagenow, $wp_roles, $current_user; |
|---|
| 69 | //$cfg = get_option(WPeMatico :: OPTION_KEY); |
|---|
| 70 | $current_tab = (isset($_GET['tab']) ) ? sanitize_text_field( $_GET['tab'] ) : 'tools'; |
|---|
| 71 | $tabs = wpematico_get_tools_tabs(); |
|---|
| 72 | $sections = array(); |
|---|
| 73 | $get_sections= "wpematico_get_".$current_tab."_sections"; |
|---|
| 74 | if(function_exists($get_sections)) { |
|---|
| 75 | //$sections = $get_sections(); |
|---|
| 76 | add_action('wpematico_tools_tab_'.$current_tab, 'wpematico_print_tab_sections',0,1); |
|---|
| 77 | |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | ?> |
|---|
| 81 | <div class="wrap"> |
|---|
| 82 | <h2 class="nav-tab-wrapper"> |
|---|
| 83 | <?php |
|---|
| 84 | foreach($tabs as $tab_id => $tab_name) { |
|---|
| 85 | $tab_url = add_query_arg(array( |
|---|
| 86 | 'tab' => $tab_id |
|---|
| 87 | )); |
|---|
| 88 | |
|---|
| 89 | $tab_url = remove_query_arg(array( |
|---|
| 90 | 'section' |
|---|
| 91 | ), $tab_url); |
|---|
| 92 | |
|---|
| 93 | $active = $current_tab == $tab_id ? ' nav-tab-active' : ''; |
|---|
| 94 | echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr(sanitize_text_field($tab_name)) . '" class="nav-tab' . $active . '">' . ( $tab_name ) . '</a>'; |
|---|
| 95 | } |
|---|
| 96 | ?> |
|---|
| 97 | </h2> |
|---|
| 98 | <div class="metabox-holder"> |
|---|
| 99 | <?php |
|---|
| 100 | do_action('wpematico_tools_tab_' . $current_tab); |
|---|
| 101 | ?> |
|---|
| 102 | </div><!-- .metabox-holder --> |
|---|
| 103 | </div><!-- .wrap --> |
|---|
| 104 | <?php |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | function wpematico_print_tab_sections() { |
|---|
| 109 | global $pagenow, $wp_roles, $current_user; |
|---|
| 110 | $current_tab = (isset($_GET['tab']) ) ? sanitize_text_field( $_GET['tab'] ) : 'tools'; |
|---|
| 111 | $sections = array(); |
|---|
| 112 | $get_sections= "wpematico_get_".$current_tab."_sections"; |
|---|
| 113 | if(function_exists($get_sections)) { |
|---|
| 114 | $sections = $get_sections(); |
|---|
| 115 | } |
|---|
| 116 | $current_section = (isset($_GET['section']) ) ? sanitize_text_field( $_GET['section'] ) : key($sections); |
|---|
| 117 | ?> |
|---|
| 118 | <div class="wpe_wrap"> |
|---|
| 119 | <h3 class="nav-section-wrapper"> |
|---|
| 120 | <?php |
|---|
| 121 | $f = TRUE; |
|---|
| 122 | foreach($sections as $section_id => $section_name) { |
|---|
| 123 | $section_url = add_query_arg(array( |
|---|
| 124 | 'section' => $section_id |
|---|
| 125 | )); |
|---|
| 126 | if(!$f) |
|---|
| 127 | echo " | "; |
|---|
| 128 | else |
|---|
| 129 | $f = FALSE; |
|---|
| 130 | $active = $current_section == $section_id ? ' nav-section-active' : ''; |
|---|
| 131 | echo '<a href="' . esc_url($section_url) . '" title="' . esc_attr($section_name) . '" class="nav-section' . $active . '">' . ( $section_name ) . '</a>'; |
|---|
| 132 | } |
|---|
| 133 | ?> |
|---|
| 134 | </h3> |
|---|
| 135 | <div class="metabox-holder"> |
|---|
| 136 | <?php |
|---|
| 137 | do_action('wpematico_tools_section_' . $current_section); |
|---|
| 138 | ?> |
|---|
| 139 | </div><!-- .metabox-holder --> |
|---|
| 140 | </div><!-- .wrap --> |
|---|
| 141 | <?php |
|---|
| 142 | } |
|---|
| 143 | |
|---|