| 1 |
<?php |
| 2 |
|
| 3 |
namespace Booktics\Admin; |
| 4 |
|
| 5 |
use Booktics\Contracts\Hookable_Service_Contract; |
| 6 |
|
| 7 |
/** |
| 8 |
* Menu class. Register menus |
| 9 |
* |
| 10 |
* @package Booktics/Admin_Menu |
| 11 |
*/ |
| 12 |
class Menu implements Hookable_Service_Contract { |
| 13 |
/** |
| 14 |
* Register hooks |
| 15 |
* |
| 16 |
* @return void |
| 17 |
*/ |
| 18 |
public function register() { |
| 19 |
add_action( 'admin_menu', array( $this, 'register_admin_menu' ) ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Register admin menu |
| 24 |
* |
| 25 |
* @return void |
| 26 |
*/ |
| 27 |
public function register_admin_menu() { |
| 28 |
global $submenu; |
| 29 |
$capability = 'manage_options'; |
| 30 |
$slug = 'booktics'; |
| 31 |
$url = 'admin.php?page=' . $slug . '#'; |
| 32 |
$booktics_menu_position = 'booktics_menu_position_'; |
| 33 |
$booktics_menu_permission = 'booktics_menu_permission_'; |
| 34 |
|
| 35 |
$menu_items = array( |
| 36 |
array( |
| 37 |
'id' => 'dashboard', |
| 38 |
'title' => esc_html__( 'Dashboard', 'booktics' ), |
| 39 |
'link' => '/', |
| 40 |
'capability' => apply_filters( $booktics_menu_permission . 'dashboard', $capability ), |
| 41 |
'position' => apply_filters( $booktics_menu_position . 'dashboard', 1 ), |
| 42 |
), |
| 43 |
array( |
| 44 |
'id' => 'appointments', |
| 45 |
'title' => esc_html__( 'Appointments', 'booktics' ), |
| 46 |
'link' => '/appointments', |
| 47 |
'capability' => apply_filters( $booktics_menu_permission . 'appointments', $capability ), |
| 48 |
'position' => apply_filters( $booktics_menu_position . 'appointments', 2 ), |
| 49 |
), |
| 50 |
array( |
| 51 |
'id' => 'services', |
| 52 |
'title' => esc_html__( 'Services', 'booktics' ), |
| 53 |
'link' => '/services', |
| 54 |
'capability' => apply_filters( $booktics_menu_permission . 'services', $capability ), |
| 55 |
'position' => apply_filters( $booktics_menu_position . 'services', 4 ), |
| 56 |
), |
| 57 |
array( |
| 58 |
'id' => 'team', |
| 59 |
'title' => esc_html__( 'Team Members', 'booktics' ), |
| 60 |
'link' => '/team-members', |
| 61 |
'capability' => apply_filters( $booktics_menu_permission . 'team', $capability ), |
| 62 |
'position' => apply_filters( $booktics_menu_position . 'team', 5 ), |
| 63 |
), |
| 64 |
array( |
| 65 |
'id' => 'orders', |
| 66 |
'title' => esc_html__( 'Orders', 'booktics' ), |
| 67 |
'link' => '/orders', |
| 68 |
'capability' => apply_filters( $booktics_menu_permission . 'orders', $capability ), |
| 69 |
'position' => apply_filters( $booktics_menu_position . 'orders', 6 ), |
| 70 |
), |
| 71 |
|
| 72 |
array( |
| 73 |
'id' => 'customers', |
| 74 |
'title' => esc_html__( 'Customers', 'booktics' ), |
| 75 |
'link' => '/customers', |
| 76 |
'capability' => apply_filters( $booktics_menu_permission . 'customers', $capability ), |
| 77 |
'position' => apply_filters( $booktics_menu_position . 'customers', 7 ), |
| 78 |
), |
| 79 |
array( |
| 80 |
'id' => 'settings', |
| 81 |
'title' => esc_html__( 'Settings', 'booktics' ), |
| 82 |
'link' => '/settings', |
| 83 |
'capability' => apply_filters( $booktics_menu_permission . 'settings', $capability ), |
| 84 |
'position' => apply_filters( $booktics_menu_position . 'settings', 8 ), |
| 85 |
), |
| 86 |
array( |
| 87 |
'id' => 'calender', |
| 88 |
'title' => esc_html__( 'Calender', 'booktics' ), |
| 89 |
'link' => '/appointments?view=Calender', |
| 90 |
'capability' => apply_filters( $booktics_menu_permission . 'appointments', $capability ), |
| 91 |
'position' => apply_filters( $booktics_menu_position . 'appointments', 3 ), |
| 92 |
), |
| 93 |
array( |
| 94 |
'id' => 'addons', |
| 95 |
'title' => esc_html__( 'Addons', 'booktics' ), |
| 96 |
'link' => '/addons', |
| 97 |
'capability' => apply_filters( $booktics_menu_permission . 'addons', $capability ), |
| 98 |
'position' => apply_filters( $booktics_menu_position . 'addons', 9 ), |
| 99 |
), |
| 100 |
); |
| 101 |
|
| 102 |
$svg = ' |
| 103 |
<svg width="48" height="48" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 104 |
<g clip-path="url(#clip0_3075_1675)"> |
| 105 |
<path d="M7.2331 11.2294L7.13197 12.3733C5.47929 11.4621 4.7062 9.44321 5.39834 7.63201C6.15553 5.65058 8.38435 4.65423 10.3658 5.41143C12.177 6.10356 13.1648 8.02563 12.7429 9.86423L11.8222 9.17635C11.8947 7.97385 11.1885 6.80973 10.0044 6.35722C8.54405 5.79918 6.90218 6.53314 6.34413 7.99344C5.89162 9.17758 6.28901 10.4805 7.2331 11.2294Z" fill="white"/> |
| 106 |
<path d="M9.13782 11.825L9.81242 12.7543C7.9675 13.1518 6.05908 12.1362 5.39231 10.3155C4.66288 8.32371 5.69027 6.10903 7.68209 5.37959C9.50278 4.71283 11.5097 5.5144 12.3983 7.17835L11.2522 7.26383C10.5176 6.30903 9.22061 5.89443 8.03027 6.33035C6.56231 6.86793 5.80548 8.49939 6.34307 9.96735C6.77899 11.1577 7.93407 11.8798 9.13782 11.825Z" fill="white"/> |
| 107 |
<path d="M9.0001 0.899994C13.4662 0.899994 17.1001 4.53386 17.1001 8.99999C17.1001 9.28147 17.0859 9.55889 17.0576 9.83328C16.8844 9.67938 16.6759 9.56294 16.441 9.49612L16.0765 9.39284C16.0835 9.26223 16.0876 9.13162 16.0876 8.99999C16.0876 5.09174 12.9083 1.91249 9.0001 1.91249C5.09185 1.91249 1.9126 5.09174 1.9126 8.99999C1.9126 12.9082 5.09185 16.0875 9.0001 16.0875C9.13172 16.0875 9.26233 16.0834 9.39295 16.0764L9.49622 16.4409C9.56305 16.6758 9.67948 16.8843 9.83136 17.0575C9.55798 17.0858 9.28056 17.1 9.0001 17.1C4.53396 17.1 0.900096 13.4661 0.900096 8.99999C0.900096 4.53386 4.53396 0.899994 9.0001 0.899994Z" fill="white"/> |
| 108 |
<path d="M8.73199 8.73283C8.85824 8.60645 9.01596 8.51607 9.18883 8.47106C9.36171 8.42604 9.54347 8.42801 9.71533 8.47677H9.71563L15.9212 10.2407C16.3259 10.3556 16.6106 10.7006 16.6464 11.1198C16.6822 11.5389 16.4603 11.9273 16.0813 12.109L14.7413 12.7528L16.8195 14.8311C17.0005 15.0116 17.1001 15.2519 17.1001 15.5075C17.1001 15.763 17.0006 16.0033 16.8198 16.1837L16.1833 16.8203C15.9969 17.0064 15.7522 17.0994 15.5073 17.0994C15.2625 17.0994 15.0177 17.0063 14.8313 16.82L12.7527 14.7412L12.109 16.0814C11.9269 16.4605 11.5373 16.6825 11.1196 16.6463C10.7006 16.6105 10.3557 16.3258 10.2409 15.9215L8.47724 9.71577C8.4284 9.54406 8.42627 9.36242 8.47107 9.18962C8.51587 9.01681 8.60598 8.85909 8.73209 8.73273L8.73199 8.73283ZM11.2078 15.6193L12.1494 13.6591C12.1844 13.5861 12.2364 13.5227 12.301 13.474C12.3656 13.4253 12.4409 13.3928 12.5206 13.3792C12.6004 13.3656 12.6822 13.3713 12.7593 13.3959C12.8364 13.4205 12.9064 13.4631 12.9636 13.5203L15.5075 16.0642L16.0641 15.5076L13.5203 12.9637C13.4631 12.9065 13.4205 12.8364 13.396 12.7593C13.3714 12.6823 13.3657 12.6004 13.3793 12.5207C13.3929 12.441 13.4254 12.3657 13.474 12.3011C13.5227 12.2365 13.5861 12.1845 13.659 12.1494L15.6191 11.2076L9.45572 9.45556L11.2078 15.6193ZM9.43871 9.45059L9.57712 8.96378L9.4376 9.45049L9.43871 9.45059Z" fill="white"/> |
| 109 |
</g> |
| 110 |
<defs> |
| 111 |
<clipPath id="clip0_3075_1675"> |
| 112 |
<rect width="48" height="48" fill="white"/> |
| 113 |
</clipPath> |
| 114 |
</defs> |
| 115 |
</svg> |
| 116 |
'; |
| 117 |
$svg_icon = 'data:image/svg+xml;base64,' . base64_encode( $svg ); |
| 118 |
|
| 119 |
add_menu_page( |
| 120 |
esc_html__( 'Booktics', 'booktics' ), |
| 121 |
esc_html__( 'Booktics', 'booktics' ), |
| 122 |
$capability, |
| 123 |
$slug, |
| 124 |
array( $this, 'booktics_dashboard_view' ), |
| 125 |
$svg_icon, |
| 126 |
10 |
| 127 |
); |
| 128 |
|
| 129 |
$menu_items = apply_filters( 'booktics_menu', $menu_items ); |
| 130 |
$position = array_column( $menu_items, 'position' ); |
| 131 |
|
| 132 |
array_multisort( $position, SORT_ASC, $menu_items ); |
| 133 |
|
| 134 |
foreach ( $menu_items as $item ) { |
| 135 |
$external = ! empty( $item['external_link'] ) ? $item['external_link'] : false; |
| 136 |
|
| 137 |
$link = ! $external ? $url . $item['link'] : $item['link']; |
| 138 |
$submenu[ $slug ][] = array( |
| 139 |
$item['title'], |
| 140 |
$item['capability'], |
| 141 |
$link, |
| 142 |
); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Render main menu page |
| 148 |
* |
| 149 |
* @return void |
| 150 |
*/ |
| 151 |
public function booktics_dashboard_view() { |
| 152 |
?> |
| 153 |
<div class="wrap" id="booktics_dashboard"></div> |
| 154 |
<?php |
| 155 |
} |
| 156 |
} |