| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Admin meni class |
| 5 |
* |
| 6 |
* @package Timetics |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace Timetics\Core\Admin; |
| 10 |
|
| 11 |
/** |
| 12 |
* Class Menu |
| 13 |
*/ |
| 14 |
class Menu |
| 15 |
{ |
| 16 |
|
| 17 |
use \Timetics\Utils\Singleton; |
| 18 |
|
| 19 |
/** |
| 20 |
* Initialize |
| 21 |
* |
| 22 |
* @return void |
| 23 |
*/ |
| 24 |
public function init() |
| 25 |
{ |
| 26 |
add_action('admin_menu', array($this, 'register_admin_menu')); |
| 27 |
|
| 28 |
add_action('timetics_menu', array($this, 'add_pro_admin_menu')); |
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
/** |
| 34 |
* Register admin menu |
| 35 |
* |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
|
| 39 |
public function register_admin_menu() |
| 40 |
{ |
| 41 |
global $submenu; |
| 42 |
$capability = 'manage_timetics'; |
| 43 |
$slug = 'timetics'; |
| 44 |
$url = 'admin.php?page=' . $slug . '#'; |
| 45 |
$timetics_menu_position = 'timetics_menu_position_'; |
| 46 |
$timetics_menu_permission = 'timetics_menu_permission_'; |
| 47 |
|
| 48 |
$menu_items = array( |
| 49 |
[ 'id' => 'overview', |
| 50 |
'title' => esc_html__('Overview', 'timetics'), |
| 51 |
'link' => '/', |
| 52 |
'capability' => apply_filters( $timetics_menu_permission . 'overview', $capability ), |
| 53 |
'position' => apply_filters( $timetics_menu_position . 'overview', 1 ), |
| 54 |
], |
| 55 |
[ |
| 56 |
'id' => 'meeting', |
| 57 |
'title' => esc_html__('Meetings', 'timetics'), |
| 58 |
'link' => '/meetings', |
| 59 |
'capability' => apply_filters( $timetics_menu_permission . 'meeting', 'read_booking' ), |
| 60 |
'position' => apply_filters( $timetics_menu_position . 'meeting', 2 ), |
| 61 |
], |
| 62 |
[ |
| 63 |
'id' => 'staff', |
| 64 |
'title' => esc_html__('Staff Members', 'timetics'), |
| 65 |
'link' => '/staff', |
| 66 |
'capability' => apply_filters( $timetics_menu_permission . 'staff', 'edit_staff' ), |
| 67 |
'position' => apply_filters( $timetics_menu_position . 'staff', 3 ), |
| 68 |
], |
| 69 |
|
| 70 |
[ |
| 71 |
'id' => 'booking', |
| 72 |
'title' => esc_html__('Bookings', 'timetics'), |
| 73 |
'link' => '/bookings', |
| 74 |
'capability' => apply_filters( $timetics_menu_permission . 'booking', 'read_booking' ), |
| 75 |
'position' => apply_filters( $timetics_menu_position . 'booking', 4 ), |
| 76 |
], |
| 77 |
[ |
| 78 |
'id' => 'customer', |
| 79 |
'title' => esc_html__('Customers', 'timetics'), |
| 80 |
'link' => '/customers', |
| 81 |
'capability' => apply_filters( $timetics_menu_permission . 'customer', 'manage_options' ), |
| 82 |
'position' => apply_filters( $timetics_menu_position . 'customer', 5 ), |
| 83 |
], |
| 84 |
[ |
| 85 |
'id' => 'settings', |
| 86 |
'title' => esc_html__('Settings', 'timetics'), |
| 87 |
'link' => '/settings', |
| 88 |
'capability' => apply_filters( $timetics_menu_permission . 'settings', 'manage_options' ), |
| 89 |
'position' => apply_filters( $timetics_menu_position . 'settings', 6 ), |
| 90 |
], |
| 91 |
[ 'id' => 'my-profile', |
| 92 |
'title' => esc_html__('My Profile', 'timetics'), |
| 93 |
'link' => '/my-profile', |
| 94 |
'capability' => apply_filters( $timetics_menu_permission . 'settings', 'edit_profile' ), |
| 95 |
'position' => apply_filters( $timetics_menu_position . 'my-profile', 7 ), |
| 96 |
], |
| 97 |
[ |
| 98 |
'id' => 'shortcode', |
| 99 |
'title' => esc_html__('Shortcodes', 'timetics'), |
| 100 |
'link' => '/shortcodes', |
| 101 |
'capability' => apply_filters( $timetics_menu_permission . 'shortcode', 'edit_profile' ), |
| 102 |
'position' => apply_filters( $timetics_menu_position . 'shortcode', 8 ), |
| 103 |
], |
| 104 |
[ |
| 105 |
'id' => 'onboard', |
| 106 |
'title' => esc_html__('Setup Wizard', 'timetics'), |
| 107 |
'link' => '/onboard', |
| 108 |
'capability' => apply_filters( $timetics_menu_permission . 'onboard', 'edit_profile' ), |
| 109 |
'position' => apply_filters( $timetics_menu_position . 'onboard', 9 ), |
| 110 |
], |
| 111 |
); |
| 112 |
|
| 113 |
add_menu_page( |
| 114 |
esc_html__('Timetics', 'timetics'), |
| 115 |
esc_html__('Timetics', 'timetics'), |
| 116 |
$capability, |
| 117 |
$slug, |
| 118 |
array($this, 'timetics_dashboard_view'), |
| 119 |
"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTE0OCIgaGVpZ2h0PSIxMTQ4IiB2aWV3Qm94PSIwIDAgMTE0OCAxMTQ4IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aCBkPSJNODQ2Ljc1MyA5NzAuNTQ1QzgxNS41MDMgOTk1LjAzOCA3NzEuMTE4IDk4Mi40NjggNzUxLjgzNCA5NDcuNzY1QzczMi44NTYgOTEzLjYxMyA3NDUuNjI5IDg3MS4wNDMgNzc1LjE4MiA4NDUuNDgxQzg0OC4yNjkgNzgyLjI2MyA4OTMuMjcgNjkwLjcyMSA4OTMuMjcgNTkwLjE4MUM4OTMuMjcgNDA1LjI1NiA3NDAuNjY2IDI1Mi42OTMgNTU1LjY5MyAyNTIuNjkzQzQ1My42ODYgMjUyLjY5MyAzNTcuODUzIDI5OC45OCAyOTMuNDEgMzc2LjQyNkMyNjkuMjIyIDQwNS40OTUgMjI4LjE1OCA0MTguNDg2IDE5NC44NTYgNDAwLjU1OUMxNjEuNjYzIDM4Mi42OTEgMTQ4LjczIDM0MS4wMTQgMTcwLjg4IDMxMC41MTVDMjYwLjEwOCAxODcuNjUxIDQwMi42MzggMTE0IDU1NS42OTMgMTE0QzgxOS4yOCAxMTQgMTAzMiAzMjYuNjYzIDEwMzIgNTkwLjE4MUMxMDMyIDc0MS41MzUgOTYzLjM1MSA4NzkuMTY0IDg0Ni43NTMgOTcwLjU0NVoiIGZpbGw9IndoaXRlIi8+CjxwYXRoIGQ9Ik0xODUuOTYyIDUyNi41MzFINjI0LjYwNFY5NjUuMDU3QzYyNC42MDQgMTAwMy4xMyA1OTMuNzI5IDEwMzQgNTU1LjY0MiAxMDM0QzUxNy41NTYgMTAzNCA0ODYuNjgxIDEwMDMuMTMgNDg2LjY4MSA5NjUuMDU3VjY2NC40MThIMTg1Ljk2MkMxNDcuODc1IDY2NC40MTggMTE3IDYzMy41NTEgMTE3IDU5NS40NzRDMTE3IDU1Ny4zOTggMTQ3Ljg3NSA1MjYuNTMxIDE4NS45NjIgNTI2LjUzMVoiIGZpbGw9IndoaXRlIi8+Cjwvc3ZnPgo=", |
| 120 |
10 |
| 121 |
); |
| 122 |
|
| 123 |
$menu_items = apply_filters('timetics_menu', $menu_items); |
| 124 |
$position = array_column($menu_items, 'position'); |
| 125 |
|
| 126 |
array_multisort($position, SORT_ASC, $menu_items); |
| 127 |
|
| 128 |
foreach ($menu_items as $item) { |
| 129 |
$external = ! empty( $item['external_link'] ) ? $item['external_link'] : false; |
| 130 |
|
| 131 |
$link = ! $external ? $url . $item['link'] : $item['link']; |
| 132 |
$submenu[$slug][] = [$item['title'], $item['capability'], $link]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Admin dashboard view |
| 138 |
* |
| 139 |
* @return void |
| 140 |
*/ |
| 141 |
public function timetics_dashboard_view() |
| 142 |
{ |
| 143 |
?> |
| 144 |
<div class="wrap" id="time_tics_dashboard"> |
| 145 |
</div> |
| 146 |
<?php |
| 147 |
} |
| 148 |
|
| 149 |
// Add submenu page under "Settings" |
| 150 |
public function add_pro_admin_menu( $menu_items ) |
| 151 |
{ |
| 152 |
if ( class_exists('TimeticsPro') ) { |
| 153 |
return $menu_items; |
| 154 |
} |
| 155 |
|
| 156 |
$menu_items[] = [ |
| 157 |
'id' => 'go-pro', |
| 158 |
'title' => esc_html__('Go Pro', 'timetics'), |
| 159 |
'link' => 'https://arraytics.com/timetics', |
| 160 |
'external_link' => true, |
| 161 |
'capability' => 'edit_profile', |
| 162 |
'position' => 9, |
| 163 |
]; |
| 164 |
|
| 165 |
return $menu_items; |
| 166 |
} |
| 167 |
} |
| 168 |
|