| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined('WPINC') ) { |
| 4 |
wp_die(); |
| 5 |
} |
| 6 |
|
| 7 |
global $submenu, $parent_file, $submenu_file, $plugin_page, $pagenow; |
| 8 |
|
| 9 |
// Vars. |
| 10 |
$parent_slug = 'edit.php?post_type=' . FLRT_FILTERS_SET_POST_TYPE; |
| 11 |
|
| 12 |
// Generate array of navigation items. |
| 13 |
$tabs = array(); |
| 14 |
if( isset($submenu[ $parent_slug ]) ) { |
| 15 |
foreach( $submenu[ $parent_slug ] as $i => $sub_item ) { |
| 16 |
|
| 17 |
// Check user can access page. |
| 18 |
if ( !current_user_can( $sub_item[1] ) ) { |
| 19 |
continue; |
| 20 |
} |
| 21 |
|
| 22 |
// Ignore "Add New". |
| 23 |
if( $i === 1 ) { |
| 24 |
continue; |
| 25 |
} |
| 26 |
|
| 27 |
// Define tab. |
| 28 |
$tab = array( |
| 29 |
'text' => $sub_item[0], |
| 30 |
'url' => $sub_item[2] |
| 31 |
); |
| 32 |
|
| 33 |
// Convert submenu slug "test" to "$parent_slug&page=test". |
| 34 |
if( !strpos($sub_item[2], '.php') ) { |
| 35 |
$tab['url'] = add_query_arg( array( 'page' => $sub_item[2] ), $parent_slug ); |
| 36 |
} |
| 37 |
|
| 38 |
// Detect active state. |
| 39 |
if( $submenu_file === $sub_item[2] || $plugin_page === $sub_item[2] ) { |
| 40 |
$tab['is_active'] = true; |
| 41 |
} |
| 42 |
|
| 43 |
// Special case for "Add New" page. |
| 44 |
if( $i === 0 && $submenu_file === 'post-new.php?post_type=' . FLRT_FILTERS_SET_POST_TYPE ) { |
| 45 |
$tab['is_active'] = true; |
| 46 |
} |
| 47 |
$tabs[] = $tab; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
$tabs = apply_filters( 'wpc_header_nav_tabs', $tabs ); |
| 52 |
|
| 53 |
// Bail early if set to false. |
| 54 |
if( $tabs === false ) { |
| 55 |
return; |
| 56 |
} |
| 57 |
?> |
| 58 |
<div class="wpc-admin-toolbar"> |
| 59 |
<h2><img src="<?php echo esc_attr( flrt_get_icon_svg('#333333') ); ?>" alt="" width="20" /> <?php echo esc_html( flrt_get_plugin_name() ); ?></h2> |
| 60 |
<?php foreach( $tabs as $tab ) { |
| 61 |
$is_active = !empty( $tab['is_active'] ) ? ' is-active' : ''; |
| 62 |
|
| 63 |
printf( |
| 64 |
'<a class="wpc-tab%s" href="%s">%s</a>', $is_active, esc_url( $tab['url'] ), esc_html( $tab['text'] ) |
| 65 |
); |
| 66 |
} ?> |
| 67 |
|
| 68 |
<div class="wpc-admin-right"> |
| 69 |
<?php do_action('wpc_admin_toolbar_right'); ?> |
| 70 |
</div> |
| 71 |
</div> |