← All changes
|
backend/src/Common/Exceptions/ForbiddenException.php
+8
-11
0.2.1
→
1.5.1
View file →
| @@ -1,23 +1,20 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * @copyright © TMS-Plugins. All rights reserved. | |
| 4 | + * @copyright © Melograno Venture Studio. All rights reserved. | |
| 5 | 5 | * @licence See LICENCE.md for license details. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace IvyForms\Common\Exceptions; |
| 9 | 9 | |
| 10 | -// phpcs:disable PSR1.Files.SideEffects | |
| 11 | -if (!defined('ABSPATH')) { | |
| 12 | - exit; // Exit if accessed directly | |
| 13 | -} | |
| 14 | - | |
| 15 | 10 | use Exception; |
| 16 | 11 | |
| 17 | 12 | /** |
| 18 | 13 | * Class ForbiddenException |
| 19 | 14 | * |
| 15 | + * Handled by Controller to return a JSON 403 REST response. | |
| 16 | + * | |
| 20 | 17 | * @package IvyForms\Common\Exceptions |
| 21 | 18 | */ |
| 22 | 19 | class ForbiddenException extends Exception |
| 23 | 20 | { |
| @@ -27,13 +24,13 @@ | ||
| 27 | 24 | * @param string $message |
| 28 | 25 | * @param int $code |
| 29 | 26 | * @param Exception|null $previous |
| 30 | 27 | */ |
| 31 | - public function __construct($message = 'forbidden', $code = 0, Exception $previous = null) | |
| 28 | + public function __construct($message = '', $code = 403, ?Exception $previous = null) | |
| 32 | 29 | { |
| 30 | + if ($message === '' || $message === 'forbidden') { | |
| 31 | + $message = esc_html__('You do not have permission to access this page.', 'ivyforms'); | |
| 32 | + } | |
| 33 | + | |
| 33 | 34 | parent::__construct($message, $code, $previous); |
| 34 | - wp_die( | |
| 35 | - esc_html__('You do not have permission to access this page.', 'ivyforms'), | |
| 36 | - 403 | |
| 37 | - ); | |
| 38 | 35 | } |
| 39 | 36 | } |