AccountClaimMiddleware.php
3 years ago
AdminColorMiddleware.php
2 years ago
ArchiveModelMiddleware.php
5 days ago
BrandColorMiddleware.php
4 years ago
CheckoutFormModeMiddleware.php
2 months ago
CheckoutRedirectMiddleware.php
3 years ago
ComponentAssetsMiddleware.php
4 years ago
CustomerDashboardLinkRedirectMiddleware.php
1 year ago
CustomerDashboardRedirectMiddleware.php
1 year ago
EditModelMiddleware.php
2 months ago
InvoiceRedirectMiddleware.php
1 year ago
LoginLinkMiddleware.php
1 year ago
LoginMiddleware.php
2 years ago
NonceMiddleware.php
4 years ago
OrderRedirectMiddleware.php
3 years ago
PathRedirectMiddleware.php
3 years ago
PaymentFailureRedirectMiddleware.php
3 years ago
ProductReviewRedirectMiddleware.php
5 months ago
PurchaseRedirectMiddleware.php
3 years ago
SubscriptionRedirectMiddleware.php
3 years ago
UpsellMiddleware.php
2 years ago
WebhooksMiddleware.php
2 months ago
ArchiveModelMiddleware.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Middleware; |
| 4 | |
| 5 | use Closure; |
| 6 | use SureCartCore\Requests\RequestInterface; |
| 7 | use SureCartCore\Responses\RedirectResponse; |
| 8 | |
| 9 | /** |
| 10 | * Middleware for handling model archiving. |
| 11 | */ |
| 12 | class ArchiveModelMiddleware { |
| 13 | /** |
| 14 | * Handle the middleware. |
| 15 | * |
| 16 | * @param RequestInterface $request Request. |
| 17 | * @param Closure $next Next. |
| 18 | * @param string $model_name Model name (used for the nonce, e.g. `archive_{$model_name}`). |
| 19 | * @param string|null $capability Optional capability override. When omitted, defaults to |
| 20 | * `edit_sc_{$model_name}s`. Passed via `archive_model:foo,my_cap` |
| 21 | * when a sibling entity rides on another model's capability. |
| 22 | * @return function |
| 23 | */ |
| 24 | public function handle( RequestInterface $request, Closure $next, $model_name, $capability = null ) { |
| 25 | // check nonce. |
| 26 | if ( ! $request->query( 'nonce' ) || ! wp_verify_nonce( $request->query( 'nonce' ), "archive_$model_name" ) ) { |
| 27 | wp_die( esc_html__( 'Your session expired - please try again.', 'surecart' ) ); |
| 28 | } |
| 29 | |
| 30 | $capability = $capability ? $capability : "edit_sc_{$model_name}s"; |
| 31 | |
| 32 | if ( ! current_user_can( $capability ) ) { |
| 33 | wp_die( esc_html__( 'You do not have permission to do this.', 'surecart' ) ); |
| 34 | } |
| 35 | |
| 36 | return $next( $request ); |
| 37 | } |
| 38 | } |
| 39 |