PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.4.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.4.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Controllers / Admin / AdminController.php
AdminController.php
91 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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