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