Abandoned
1 year ago
AffiliationClicks
1 year ago
AffiliationPayoutGroups
2 years ago
AffiliationPayouts
1 year ago
AffiliationReferrals
1 year ago
AffiliationRequests
1 year ago
Affiliations
1 year ago
Bumps
1 year ago
CancellationInsights
1 year ago
Cart
3 years ago
Checkouts
2 years ago
Coupons
1 year ago
Customers
1 year ago
Dashboard
2 years ago
Invoices
1 year ago
Licenses
1 year ago
Onboarding
1 year ago
Orders
1 year ago
ProductCollections
1 year ago
ProductGroups
1 year ago
Products
1 year ago
Restore
2 years ago
Settings
1 year ago
Subscriptions
1 year ago
Tables
1 year ago
Upsells
1 year ago
.gitkeep
3 years ago
Account.php
3 years ago
AdminController.php
1 year ago
Connection.php
3 years ago
PluginSettings.php
3 years ago
AdminController.php
91 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Controllers\Admin; |
| 4 | |
| 5 | use SureCartCore\Responses\RedirectResponse; |
| 6 | |
| 7 | abstract class AdminController { |
| 8 | /** |
| 9 | * Preload API Request Paths |
| 10 | * |
| 11 | * @param array $preload_paths The preload paths. |
| 12 | * |
| 13 | * @return void |
| 14 | */ |
| 15 | public function preloadPaths( $preload_paths ) { |
| 16 | wp_add_inline_script( |
| 17 | 'wp-api-fetch', |
| 18 | sprintf( |
| 19 | 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', |
| 20 | wp_json_encode( |
| 21 | array_reduce( |
| 22 | $preload_paths, |
| 23 | 'rest_preload_api_request', |
| 24 | array() |
| 25 | ) |
| 26 | ) |
| 27 | ), |
| 28 | 'after' |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * The header. |
| 34 | * |
| 35 | * @param array $args The arguments. |
| 36 | * |
| 37 | * @return void |
| 38 | */ |
| 39 | public function withHeader( $args ) { |
| 40 | add_action( |
| 41 | 'in_admin_header', |
| 42 | function() use ( $args ) { |
| 43 | return \SureCart::render( |
| 44 | 'layouts/partials/admin-header', |
| 45 | [ |
| 46 | 'breadcrumbs' => $args['breadcrumbs'] ?? [], |
| 47 | 'suffix' => $args['suffix'] ?? '', |
| 48 | 'claim_url' => ! \SureCart::account()->claimed ? \SureCart::routeUrl( 'account.claim' ) : '', |
| 49 | 'report_url' => $args['report_url'] ?? '', |
| 50 | ] |
| 51 | ); |
| 52 | } |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Add notices. |
| 58 | * |
| 59 | * @param array $items The notices. |
| 60 | * |
| 61 | * @return void |
| 62 | */ |
| 63 | public function withNotices( $items ) { |
| 64 | add_action( |
| 65 | 'admin_notices', |
| 66 | function() use ( $items ) { |
| 67 | foreach ( $items as $key => $item ) { |
| 68 | if ( (bool) ( $_REQUEST[ $key ] ?? false ) ) { |
| 69 | ?> |
| 70 | <div class="notice notice-success is-dismissible"> |
| 71 | <p><?php echo esc_html( $item ); ?></p> |
| 72 | </div> |
| 73 | <?php |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Redirect back to the previous page. |
| 82 | * |
| 83 | * @param @param \SureCartCore\Requests\RequestInterface $request Request. |
| 84 | * |
| 85 | * @return \SureCartCore\Responses\RedirectResponse |
| 86 | */ |
| 87 | public function redirectBack( $request ) { |
| 88 | return ( new RedirectResponse( $request ) )->back(); |
| 89 | } |
| 90 | } |
| 91 |