| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
global $submenu, $parent_file, $submenu_file, $plugin_page, $pagenow; |
| 8 |
|
| 9 |
$parent_slug = 'edit.php?post_type=' . FLRT_FILTERS_SET_POST_TYPE; |
| 10 |
|
| 11 |
|
| 12 |
$current_tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : ''; |
| 13 |
$current_page = isset($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
| 14 |
$tabs = array(); |
| 15 |
|
| 16 |
// Submenu entries that must NOT become toolbar tabs: the toolbar mirrors the |
| 17 |
// sidebar, but only the everyday destinations belong up there. «What's new» |
| 18 |
// keeps its sidebar entry (and badge) and is reachable from there. |
| 19 |
$hidden_in_toolbar = apply_filters('wpc_header_nav_hidden_slugs', array( |
| 20 |
class_exists('\FilterEverything\Filter\WhatsNew') ? \FilterEverything\Filter\WhatsNew::PAGE_SLUG : 'filters-whats-new', |
| 21 |
)); |
| 22 |
|
| 23 |
if (isset($submenu[$parent_slug])) { |
| 24 |
foreach ($submenu[$parent_slug] as $i => $sub_item) { |
| 25 |
|
| 26 |
if (!current_user_can($sub_item[1])) { |
| 27 |
continue; |
| 28 |
} |
| 29 |
|
| 30 |
if ($i === 1) { |
| 31 |
continue; |
| 32 |
} |
| 33 |
|
| 34 |
if (in_array($sub_item[2], $hidden_in_toolbar, true)) { |
| 35 |
continue; |
| 36 |
} |
| 37 |
|
| 38 |
$tab = array( |
| 39 |
'text' => $sub_item[0], |
| 40 |
'url' => $sub_item[2] |
| 41 |
); |
| 42 |
|
| 43 |
if (!strpos($sub_item[2], '.php')) { |
| 44 |
$tab['url'] = add_query_arg(array('page' => $sub_item[2]), $parent_slug); |
| 45 |
} |
| 46 |
|
| 47 |
$tab_tab = ''; |
| 48 |
$tab_url_parts = wp_parse_url($tab['url']); |
| 49 |
if (isset($tab_url_parts['query'])) { |
| 50 |
parse_str($tab_url_parts['query'], $tab_qs); |
| 51 |
if (isset($tab_qs['tab'])) { |
| 52 |
$tab_tab = sanitize_key($tab_qs['tab']); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
$tab['is_active'] = false; |
| 57 |
|
| 58 |
$tab_matches = false; |
| 59 |
if (strpos($sub_item[2], '.php') === false) { |
| 60 |
$current_page = isset($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
| 61 |
$tab_matches = ($current_page === sanitize_key($sub_item[2])); |
| 62 |
} else { |
| 63 |
$tab_matches = ($submenu_file === $sub_item[2] || $plugin_page === $sub_item[2]); |
| 64 |
} |
| 65 |
$is_same_submenu = $tab_matches; |
| 66 |
|
| 67 |
if ($is_same_submenu) { |
| 68 |
// Any Settings tab (Import/Export included — it has no toolbar tab of |
| 69 |
// its own any more) keeps the «Settings» tab active |
| 70 |
if($current_page == 'filters-settings'){ |
| 71 |
$tab['is_active'] = true; |
| 72 |
}elseif ($current_tab) { |
| 73 |
if ($tab_tab && $tab_tab === $current_tab) { |
| 74 |
$tab['is_active'] = true; |
| 75 |
} |
| 76 |
} else { |
| 77 |
if (empty($tab_tab)) { |
| 78 |
$tab['is_active'] = true; |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
if ($i === 0 && $submenu_file === 'post-new.php?post_type=' . FLRT_FILTERS_SET_POST_TYPE) { |
| 84 |
$tab['is_active'] = true; |
| 85 |
} |
| 86 |
$tabs[] = $tab; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
$tabs = apply_filters('wpc_header_nav_tabs', $tabs); |
| 91 |
|
| 92 |
if ($tabs === false) { |
| 93 |
return; |
| 94 |
} |
| 95 |
?> |
| 96 |
<div class="wpc-admin-toolbar"> |
| 97 |
<h2><a class="wpc-toolbar-brand" href="<?php echo esc_url( admin_url( 'edit.php?post_type=' . FLRT_FILTERS_SET_POST_TYPE ) ); ?>"><img src="<?php |
| 98 |
echo esc_attr(flrt_get_icon_svg('#333333')); |
| 99 |
?>" alt="" width="24"/> <?php |
| 100 |
echo esc_html(flrt_get_plugin_name()); |
| 101 |
// The running version, always visible on every plugin screen in both builds |
| 102 |
// (PRO used to print it on the right next to the licence status); the |
| 103 |
// logo + name link back to the Filter Sets list |
| 104 |
echo ' <span class="wpc-plugin-version">' . esc_html( FLRT_PLUGIN_VER ) . '</span>'; |
| 105 |
?></a></h2> |
| 106 |
<?php foreach ($tabs as $tab) { |
| 107 |
$is_active = !empty($tab['is_active']) ? ' is-active' : ''; |
| 108 |
$is_pro = str_contains($tab['text'], 'wpc-pro-badge') ? ' wpc-pro-badge-text' : ''; |
| 109 |
$tab_text = str_replace('wpc-pro-badge', 'wpc-pro-badge-transparent', $tab['text']); |
| 110 |
$extra_class = preg_replace( '/[^a-z]/', '', strtolower( wp_kses($tab_text, [] ) ) ); |
| 111 |
printf( |
| 112 |
'<a class="wpc-tab%s%s wpc-%s" href="%s">%s</a>', |
| 113 |
$is_active, |
| 114 |
$is_pro, |
| 115 |
$extra_class, |
| 116 |
esc_url($tab['url']), |
| 117 |
wp_kses($tab_text, array( |
| 118 |
'span' => array( |
| 119 |
'class' => array(), |
| 120 |
), |
| 121 |
)) |
| 122 |
); |
| 123 |
} ?> |
| 124 |
<div class="wpc-admin-right"> |
| 125 |
<?php do_action('wpc_admin_toolbar_right'); ?> |
| 126 |
</div> |
| 127 |
</div> |