PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.6.0
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.6.0
1.6.0 1.5.1 1.5.0 1.4.0 1.3.0 trunk 0.0.1 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0
suredonation / inc / abilities / ability-exception.php

ability-exception.php in SureDonation – Donation Forms, Fundraising Campaigns & Donor Management 1.6.0, at inc/abilities/ability-exception.php

66 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Abilities API Exception
4 *
5 * Carries a machine-readable error code alongside the message so a failed
6 * ability can surface a meaningful `WP_Error` code rather than one generic
7 * bucket for every failure.
8 *
9 * @package SureDonation
10 * @since 1.5.0
11 */
12
13 namespace SureDonation\Inc\Abilities;
14
15 use Exception;
16
17 // Exit if accessed directly.
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 /**
23 * Ability_Exception class.
24 *
25 * @since 1.5.0
26 */
27 class Ability_Exception extends Exception {
28 /**
29 * Default code used when a call site does not supply one.
30 */
31 public const DEFAULT_CODE = 'suredonation_ability_error';
32
33 /**
34 * Machine-readable error code.
35 *
36 * Exception::$code is an int by convention, so the string code lives here
37 * rather than being squeezed through the parent constructor.
38 *
39 * @var string
40 * @since 1.5.0
41 */
42 protected $error_code;
43
44 /**
45 * Constructor.
46 *
47 * @param string $error_code Machine-readable code (e.g. `campaign_not_found`).
48 * @param string $message Human-readable, translated message.
49 * @since 1.5.0
50 */
51 public function __construct( $error_code, $message ) {
52 parent::__construct( $message );
53 $this->error_code = '' !== $error_code ? $error_code : self::DEFAULT_CODE;
54 }
55
56 /**
57 * Get the machine-readable error code.
58 *
59 * @return string
60 * @since 1.5.0
61 */
62 public function get_error_code() {
63 return $this->error_code;
64 }
65 }
66