admin.php
353 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WordPress Admin Routes. |
| 4 | * WARNING: Do not use \SureCart::route()->all() here, otherwise you will override |
| 5 | * ALL custom admin pages which you most likely do not want to do. |
| 6 | * |
| 7 | * @link https://docs.wpemerge.com/#/framework/routing/methods |
| 8 | * |
| 9 | * @package SureCart |
| 10 | */ |
| 11 | |
| 12 | use SureCart\Models\ApiToken; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; |
| 16 | } |
| 17 | |
| 18 | /* |
| 19 | |-------------------------------------------------------------------------- |
| 20 | | Onboarding |
| 21 | |-------------------------------------------------------------------------- |
| 22 | */ |
| 23 | \SureCart::route() |
| 24 | ->get() |
| 25 | ->where( 'admin', 'sc-getting-started' ) |
| 26 | ->name( 'onboarding.show' ) |
| 27 | ->middleware( 'user.can:manage_options' ) |
| 28 | ->middleware( 'assets.components' ) |
| 29 | ->middleware( 'assets.brand_colors' ) |
| 30 | ->handle( 'Onboarding@show' ); |
| 31 | |
| 32 | /* |
| 33 | |-------------------------------------------------------------------------- |
| 34 | | Dashboard |
| 35 | |-------------------------------------------------------------------------- |
| 36 | */ |
| 37 | \SureCart::route() |
| 38 | ->get() |
| 39 | ->where( 'admin', 'sc-dashboard' ) |
| 40 | ->middleware( 'user.can:manage_options' ) |
| 41 | ->middleware( 'assets.components' ) |
| 42 | ->name( 'dashboard.show' ) |
| 43 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\Dashboard\\' ) |
| 44 | ->handle( 'DashboardController@index' ); |
| 45 | |
| 46 | /* |
| 47 | |-------------------------------------------------------------------------- |
| 48 | | Complete Signup |
| 49 | |-------------------------------------------------------------------------- |
| 50 | */ |
| 51 | \SureCart::route() |
| 52 | ->get() |
| 53 | ->where( 'admin', 'sc-complete-signup' ) |
| 54 | ->middleware( 'user.can:manage_options' ) |
| 55 | ->middleware( 'assets.components' ) |
| 56 | ->middleware( 'assets.brand_colors' ) |
| 57 | ->group( |
| 58 | function() { |
| 59 | \SureCart::route()->get()->handle( 'Onboarding@complete' ); |
| 60 | \SureCart::route()->post()->middleware( 'nonce:update_plugin_settings' )->handle( 'Onboarding@save' ); |
| 61 | } |
| 62 | ); |
| 63 | |
| 64 | |
| 65 | /* |
| 66 | |-------------------------------------------------------------------------- |
| 67 | | Orders |
| 68 | |-------------------------------------------------------------------------- |
| 69 | */ |
| 70 | \SureCart::route() |
| 71 | ->where( 'admin', 'sc-orders' ) |
| 72 | ->middleware( 'user.can:edit_sc_orders' ) |
| 73 | ->middleware( 'assets.components' ) |
| 74 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\Orders\\' ) |
| 75 | ->group( |
| 76 | function() { |
| 77 | \SureCart::route()->get()->where( 'sc_url_var', false, 'action' )->handle( 'OrdersViewController@index' ); |
| 78 | \SureCart::route()->get()->where( 'sc_url_var', 'edit', 'action' )->handle( 'OrdersViewController@edit' ); |
| 79 | \SureCart::route()->get()->where( 'sc_url_var', 'archive', 'action' )->handle( 'OrdersViewController@archive' ); |
| 80 | } |
| 81 | ); |
| 82 | |
| 83 | /* |
| 84 | |-------------------------------------------------------------------------- |
| 85 | | Invoices |
| 86 | |-------------------------------------------------------------------------- |
| 87 | */ |
| 88 | \SureCart::route() |
| 89 | ->where( 'admin', 'sc-invoices' ) |
| 90 | ->middleware( 'user.can:edit_sc_invoices' ) |
| 91 | ->middleware( 'assets.components' ) |
| 92 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\Invoices\\' ) |
| 93 | ->group( |
| 94 | function() { |
| 95 | \SureCart::route()->get()->where( 'sc_url_var', false, 'action' )->handle( 'InvoicesViewController@index' ); |
| 96 | \SureCart::route()->get()->where( 'sc_url_var', 'edit', 'action' )->handle( 'InvoicesViewController@edit' ); |
| 97 | \SureCart::route()->get()->where( 'sc_url_var', 'archive', 'action' )->handle( 'InvoicesViewController@archive' ); |
| 98 | } |
| 99 | ); |
| 100 | |
| 101 | /* |
| 102 | |-------------------------------------------------------------------------- |
| 103 | | Products |
| 104 | |-------------------------------------------------------------------------- |
| 105 | */ |
| 106 | \SureCart::route() |
| 107 | ->where( 'admin', 'sc-products' ) |
| 108 | ->middleware( 'user.can:edit_sc_products' ) |
| 109 | ->middleware( 'assets.components' ) |
| 110 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\Products\\' ) |
| 111 | ->group( |
| 112 | function() { |
| 113 | \SureCart::route()->get()->where( 'sc_url_var', false, 'action' )->handle( 'ProductsController@index' ); |
| 114 | \SureCart::route()->get()->where( 'sc_url_var', 'edit', 'action' )->handle( 'ProductsController@edit' ); |
| 115 | \SureCart::route()->get()->where( 'sc_url_var', 'toggle_archive', 'action' )->middleware( 'archive_model:product' )->handle( 'ProductsController@toggleArchive' ); |
| 116 | } |
| 117 | ); |
| 118 | |
| 119 | /* |
| 120 | |-------------------------------------------------------------------------- |
| 121 | | Coupons |
| 122 | |-------------------------------------------------------------------------- |
| 123 | */ |
| 124 | \SureCart::route() |
| 125 | ->where( 'admin', 'sc-coupons' ) |
| 126 | ->middleware( 'user.can:edit_sc_coupons' ) |
| 127 | ->middleware( 'assets.components' ) |
| 128 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\Coupons\\' ) |
| 129 | ->group( |
| 130 | function() { |
| 131 | \SureCart::route()->get()->where( 'sc_url_var', false, 'action' )->handle( 'CouponsController@index' ); |
| 132 | \SureCart::route()->get()->where( 'sc_url_var', 'edit', 'action' )->handle( 'CouponsController@edit' ); |
| 133 | } |
| 134 | ); |
| 135 | |
| 136 | /* |
| 137 | |-------------------------------------------------------------------------- |
| 138 | | Customers |
| 139 | |-------------------------------------------------------------------------- |
| 140 | */ |
| 141 | \SureCart::route() |
| 142 | ->where( 'admin', 'sc-customers' ) |
| 143 | ->middleware( 'user.can:edit_sc_customers' ) |
| 144 | ->middleware( 'assets.components' ) |
| 145 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\Customers\\' ) |
| 146 | ->group( |
| 147 | function() { |
| 148 | \SureCart::route()->get()->where( 'sc_url_var', false, 'action' )->handle( 'CustomersController@index' ); |
| 149 | \SureCart::route()->get()->where( 'sc_url_var', 'edit', 'action' )->handle( 'CustomersController@edit' ); |
| 150 | } |
| 151 | ); |
| 152 | |
| 153 | /* |
| 154 | |-------------------------------------------------------------------------- |
| 155 | | Licenses |
| 156 | |-------------------------------------------------------------------------- |
| 157 | */ |
| 158 | \SureCart::route() |
| 159 | ->where( 'admin', 'sc-licenses' ) |
| 160 | ->middleware( 'user.can:edit_sc_products' ) |
| 161 | ->middleware( 'assets.components' ) |
| 162 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\Licenses\\' ) |
| 163 | ->group( |
| 164 | function() { |
| 165 | \SureCart::route()->get()->where( 'sc_url_var', false, 'action' )->handle( 'LicensesController@index' ); |
| 166 | \SureCart::route()->get()->where( 'sc_url_var', 'edit', 'action' )->handle( 'LicensesController@edit' ); |
| 167 | } |
| 168 | ); |
| 169 | |
| 170 | /* |
| 171 | |-------------------------------------------------------------------------- |
| 172 | | Abandoned Checkouts |
| 173 | |-------------------------------------------------------------------------- |
| 174 | */ |
| 175 | \SureCart::route() |
| 176 | ->where( 'admin', 'sc-abandoned-checkouts' ) |
| 177 | ->middleware( 'user.can:edit_sc_orders' ) |
| 178 | ->middleware( 'assets.components' ) |
| 179 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\Abandoned\\' ) |
| 180 | ->group( |
| 181 | function() { |
| 182 | \SureCart::route()->get()->where( 'sc_url_var', false, 'action' )->handle( 'AbandonedCheckoutViewController@index' ); |
| 183 | \SureCart::route()->get()->where( 'sc_url_var', 'edit', 'action' )->handle( 'AbandonedCheckoutViewController@edit' ); |
| 184 | } |
| 185 | ); |
| 186 | |
| 187 | /* |
| 188 | |-------------------------------------------------------------------------- |
| 189 | | Subscriptions |
| 190 | |-------------------------------------------------------------------------- |
| 191 | */ |
| 192 | \SureCart::route() |
| 193 | ->where( 'admin', 'sc-subscriptions' ) |
| 194 | ->middleware( 'user.can:edit_sc_subscriptions' ) |
| 195 | ->middleware( 'assets.components' ) |
| 196 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\Subscriptions\\' ) |
| 197 | ->group( |
| 198 | function() { |
| 199 | \SureCart::route()->get()->where( 'sc_url_var', false, 'action' )->handle( 'SubscriptionsController@index' ); |
| 200 | \SureCart::route()->get()->where( 'sc_url_var', 'show', 'action' )->handle( 'SubscriptionsController@show' ); |
| 201 | \SureCart::route()->get()->where( 'sc_url_var', 'edit', 'action' )->handle( 'SubscriptionsController@edit' ); |
| 202 | } |
| 203 | ); |
| 204 | |
| 205 | \SureCart::route() |
| 206 | ->where( 'admin', 'cart' ) |
| 207 | ->middleware( 'user.can:manage_options' ) |
| 208 | ->middleware( 'assets.components' ) |
| 209 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\Cart\\' ) |
| 210 | ->group( |
| 211 | function() { |
| 212 | \SureCart::route()->get()->where( 'sc_url_var', false, 'action' )->handle( 'CartController@edit' ); |
| 213 | \SureCart::route()->get()->where( 'sc_url_var', 'show', 'action' )->handle( 'CartController@edit' ); |
| 214 | \SureCart::route()->get()->where( 'sc_url_var', 'edit', 'action' )->handle( 'CartController@edit' ); |
| 215 | } |
| 216 | ); |
| 217 | |
| 218 | /* |
| 219 | |-------------------------------------------------------------------------- |
| 220 | | Upgrade Paths |
| 221 | |-------------------------------------------------------------------------- |
| 222 | */ |
| 223 | \SureCart::route() |
| 224 | ->where( 'admin', 'sc-product-groups' ) |
| 225 | ->middleware( 'user.can:edit_sc_products' ) |
| 226 | ->middleware( 'assets.components' ) |
| 227 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\ProductGroups\\' ) |
| 228 | ->group( |
| 229 | function() { |
| 230 | \SureCart::route()->get()->where( 'sc_url_var', false, 'action' )->handle( 'ProductGroupsController@index' ); |
| 231 | \SureCart::route()->get()->where( 'sc_url_var', 'show', 'action' )->handle( 'ProductGroupsController@show' ); |
| 232 | \SureCart::route()->get()->where( 'sc_url_var', 'edit', 'action' )->handle( 'ProductGroupsController@show' ); |
| 233 | } |
| 234 | ); |
| 235 | |
| 236 | /* |
| 237 | |-------------------------------------------------------------------------- |
| 238 | | Upgrade Paths |
| 239 | |-------------------------------------------------------------------------- |
| 240 | */ |
| 241 | \SureCart::route() |
| 242 | ->where( 'admin', 'sc-bumps' ) |
| 243 | ->middleware( 'user.can:edit_sc_products' ) |
| 244 | ->middleware( 'assets.components' ) |
| 245 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\Bumps\\' ) |
| 246 | ->group( |
| 247 | function() { |
| 248 | \SureCart::route()->get()->where( 'sc_url_var', false, 'action' )->handle( 'BumpsController@index' ); |
| 249 | \SureCart::route()->get()->where( 'sc_url_var', 'edit', 'action' )->handle( 'BumpsController@edit' ); |
| 250 | } |
| 251 | ); |
| 252 | |
| 253 | /* |
| 254 | |-------------------------------------------------------------------------- |
| 255 | | Settings |
| 256 | |-------------------------------------------------------------------------- |
| 257 | */ |
| 258 | \SureCart::route() |
| 259 | ->get() |
| 260 | ->where( 'admin', 'sc-settings' ) |
| 261 | ->middleware( 'user.can:manage_sc_account_settings' ) |
| 262 | ->middleware( 'assets.components' ) |
| 263 | ->middleware( 'assets.brand_colors' ) |
| 264 | ->setNamespace( '\\SureCart\\Controllers\\Admin\\Settings\\' ) |
| 265 | ->group( |
| 266 | function() { |
| 267 | // limit menu routes if no API token. |
| 268 | if ( ! ApiToken::get() ) { |
| 269 | // without the var. |
| 270 | \SureCart::route()->get()->where( 'sc_url_var', false, 'tab' )->handle( 'ConnectionSettings@show' ); |
| 271 | \SureCart::route()->post()->where( 'sc_url_var', false, 'tab' )->middleware( 'nonce:update_plugin_settings' )->handle( 'ConnectionSettings@save' ); |
| 272 | |
| 273 | // with the var. |
| 274 | \SureCart::route()->get()->where( 'sc_url_var', 'connection', 'tab' )->handle( 'ConnectionSettings@show' ); |
| 275 | \SureCart::route()->post()->where( 'sc_url_var', 'connection', 'tab' )->middleware( 'nonce:update_plugin_settings' )->handle( 'ConnectionSettings@save' ); |
| 276 | |
| 277 | // Advanced. |
| 278 | \SureCart::route()->get()->where( 'sc_url_var', 'advanced', 'tab' )->name( 'settings.advanced' )->handle( 'AdvancedSettings@show' ); |
| 279 | \SureCart::route()->post()->where( 'sc_url_var', 'advanced', 'tab' )->middleware( 'nonce:update_plugin_settings' )->handle( 'AdvancedSettings@save' ); |
| 280 | |
| 281 | // Cache. |
| 282 | \SureCart::route()->post()->where( 'sc_url_var', 'clear', 'cache' )->middleware( 'nonce:update_plugin_settings' )->handle( 'CacheSettings@clear' ); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | // Settings. |
| 287 | \SureCart::route()->get()->where( 'sc_url_var', false, 'tab' )->name( 'settings.account' )->handle( 'AccountSettings@show' ); |
| 288 | \SureCart::route()->get()->where( 'sc_url_var', 'brand', 'tab' )->name( 'settings.brand' )->handle( 'BrandSettings@show' ); |
| 289 | \SureCart::route()->get()->where( 'sc_url_var', 'order', 'tab' )->name( 'settings.order' )->handle( 'OrderSettings@show' ); |
| 290 | \SureCart::route()->get()->where( 'sc_url_var', 'abandoned_checkout', 'tab' )->name( 'settings.abandoned_checkout' )->handle( 'AbandonedCheckoutSettings@show' ); |
| 291 | \SureCart::route()->get()->where( 'sc_url_var', 'customer_notification_protocol', 'tab' )->name( 'settings.customer' )->handle( 'CustomerSettings@show' ); |
| 292 | \SureCart::route()->get()->where( 'sc_url_var', 'subscription_protocol', 'tab' )->name( 'settings.subscription' )->handle( 'SubscriptionSettings@show' ); |
| 293 | \SureCart::route()->get()->where( 'sc_url_var', 'portal_protocol', 'tab' )->name( 'settings.portal' )->handle( 'PortalSettings@show' ); |
| 294 | \SureCart::route()->get()->where( 'sc_url_var', 'tax_protocol', 'tab' )->where( 'sc_url_var', 'region', 'type' )->name( 'settings.tax.region' )->handle( 'TaxRegionSettings@show' ); |
| 295 | \SureCart::route()->get()->where( 'sc_url_var', 'tax_protocol', 'tab' )->name( 'settings.tax' )->handle( 'TaxSettings@show' ); |
| 296 | \SureCart::route()->get()->where( 'sc_url_var', 'upgrade', 'tab' )->name( 'settings.upgrade' )->handle( 'UpgradeSettings@show' ); |
| 297 | |
| 298 | // Connection. |
| 299 | \SureCart::route()->get()->where( 'sc_url_var', 'connection', 'tab' )->name( 'settings.connection' )->handle( 'ConnectionSettings@show' ); |
| 300 | \SureCart::route()->post()->where( 'sc_url_var', 'connection', 'tab' )->middleware( 'nonce:update_plugin_settings' )->name( 'settings.connection.save' )->handle( 'ConnectionSettings@save' ); |
| 301 | |
| 302 | // Advanced. |
| 303 | \SureCart::route()->get()->where( 'sc_url_var', 'advanced', 'tab' )->name( 'settings.advanced' )->handle( 'AdvancedSettings@show' ); |
| 304 | \SureCart::route()->post()->where( 'sc_url_var', 'advanced', 'tab' )->middleware( 'nonce:update_plugin_settings' )->name( 'settings.advanced.save' )->handle( 'AdvancedSettings@save' ); |
| 305 | |
| 306 | // Processors. |
| 307 | \SureCart::route()->get()->where( 'sc_url_var', 'processors', 'tab' )->name( 'settings.processors' )->handle( 'ProcessorsSettings@show' ); |
| 308 | |
| 309 | // Export |
| 310 | \SureCart::route()->get()->where( 'sc_url_var', 'export', 'tab' )->name( 'settings.export' )->handle( 'ExportSettings@show' ); |
| 311 | |
| 312 | // Cache. |
| 313 | \SureCart::route()->post()->where( 'sc_url_var', 'clear', 'cache' )->middleware( 'nonce:update_plugin_settings' )->handle( 'CacheSettings@clear' ); |
| 314 | } |
| 315 | ); |
| 316 | |
| 317 | /* |
| 318 | |-------------------------------------------------------------------------- |
| 319 | | Connection |
| 320 | |-------------------------------------------------------------------------- |
| 321 | */ |
| 322 | \SureCart::route() |
| 323 | ->get() |
| 324 | ->where( 'admin', 'sc-plugin' ) |
| 325 | ->middleware( 'user.can:manage_options' ) |
| 326 | ->middleware( 'assets.components' ) |
| 327 | ->group( |
| 328 | function() { |
| 329 | \SureCart::route()->get()->name( 'plugin.show' )->handle( 'PluginSettings@show' ); |
| 330 | \SureCart::route()->post()->middleware( 'nonce:update_plugin_settings' )->handle( 'PluginSettings@save' ); |
| 331 | } |
| 332 | ); |
| 333 | |
| 334 | /* |
| 335 | |-------------------------------------------------------------------------- |
| 336 | | Webhooks |
| 337 | |-------------------------------------------------------------------------- |
| 338 | */ |
| 339 | \SureCart::route() |
| 340 | ->get() |
| 341 | ->where( 'sc_url_var', 'remove_webhook', 'action' ) |
| 342 | ->name( 'webhook.remove' ) |
| 343 | ->middleware( 'nonce:remove_webhook' ) |
| 344 | ->middleware( 'user.can:edit_sc_webhooks' ) |
| 345 | ->handle( '\\SureCart\\Controllers\\Web\\WebhookController@remove' ); |
| 346 | \SureCart::route() |
| 347 | ->get() |
| 348 | ->where( 'sc_url_var', 'ignore_webhook', 'action' ) |
| 349 | ->name( 'webhook.ignore' ) |
| 350 | ->middleware( 'nonce:ignore_webhook' ) |
| 351 | ->middleware( 'user.can:edit_sc_webhooks' ) |
| 352 | ->handle( '\\SureCart\\Controllers\\Web\\WebhookController@ignore' ); |
| 353 |