Abandoned
1 month ago
AffiliationClicks
1 month ago
AffiliationPayoutGroups
2 years ago
AffiliationPayouts
9 months ago
AffiliationReferrals
6 months ago
AffiliationRequests
1 month ago
Affiliations
1 month ago
AutoFees
1 month ago
Bumps
1 month ago
CancellationInsights
1 month ago
Cart
3 years ago
Checkouts
2 months ago
Coupons
2 months ago
Customers
1 month ago
Dashboard
9 months ago
Invoices
1 month ago
Learn
2 months ago
Licenses
1 month ago
Onboarding
10 months ago
Orders
1 month ago
ProductCollections
1 year ago
ProductGroups
1 year ago
Products
1 month ago
Restore
2 years ago
Reviews
1 month ago
Settings
3 weeks ago
Subscriptions
1 month ago
Tables
4 months ago
Upsells
1 month ago
.gitkeep
3 years ago
Account.php
3 years ago
AdminController.php
9 months ago
PluginSettings.php
3 years ago
AdminController.php
92 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 | 'claim_expired' => \SureCart::account()->claim_expired ?? false, |
| 50 | 'report_url' => $args['report_url'] ?? '', |
| 51 | ] |
| 52 | ); |
| 53 | } |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Add notices. |
| 59 | * |
| 60 | * @param array $items The notices. |
| 61 | * |
| 62 | * @return void |
| 63 | */ |
| 64 | public function withNotices( $items ) { |
| 65 | add_action( |
| 66 | 'admin_notices', |
| 67 | function () use ( $items ) { |
| 68 | foreach ( $items as $key => $item ) { |
| 69 | if ( (bool) ( $_REQUEST[ $key ] ?? false ) ) { |
| 70 | ?> |
| 71 | <div class="notice notice-success is-dismissible"> |
| 72 | <p><?php echo esc_html( $item ); ?></p> |
| 73 | </div> |
| 74 | <?php |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Redirect back to the previous page. |
| 83 | * |
| 84 | * @param @param \SureCartCore\Requests\RequestInterface $request Request. |
| 85 | * |
| 86 | * @return \SureCartCore\Responses\RedirectResponse |
| 87 | */ |
| 88 | public function redirectBack( $request ) { |
| 89 | return ( new RedirectResponse( $request ) )->back(); |
| 90 | } |
| 91 | } |
| 92 |