| @@ -15,38 +15,108 @@ | ||
| 15 | 15 | /** |
| 16 | 16 | * Just an easy way to represent a feature requirements status |
| 17 | 17 | */ |
| 18 | 18 | class FeatureRequirementsStatus { |
| 19 | + const AUTO_ENABLED = 0; | |
| 20 | + const MANUALLY_ENABLED = 1; | |
| 21 | + const FORCE_DISABLED = 2; | |
| 22 | + const TEMPORARILY_DISABLED = 3; | |
| 19 | 23 | |
| 20 | 24 | /** |
| 25 | + * Returns the status of a feature | |
| 26 | + * | |
| 27 | + * 0 is no issues | |
| 28 | + * 1 is usable but there are warnings | |
| 29 | + * 2 is not usable | |
| 30 | + * | |
| 31 | + * @var int | |
| 32 | + * @since 2.2 | |
| 33 | + */ | |
| 34 | + public $code; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * Optional message to describe status code | |
| 38 | + * | |
| 39 | + * @var string|array | |
| 40 | + * @since 2.2 | |
| 41 | + */ | |
| 42 | + public $message; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Optional feature object | |
| 46 | + * | |
| 47 | + * @var Feature|null | |
| 48 | + * @since 5.3.3 | |
| 49 | + */ | |
| 50 | + public $feature; | |
| 51 | + | |
| 52 | + /** | |
| 21 | 53 | * Initialize class |
| 22 | 54 | * |
| 23 | 55 | * @param int $code Status code. |
| 24 | 56 | * @param string|array $message Message describing status. |
| 57 | + * @param Feature $feature Feature object. | |
| 25 | 58 | * @since 2.2 |
| 26 | 59 | */ |
| 27 | - public function __construct( $code, $message = null ) { | |
| 28 | - $this->code = $code; | |
| 29 | - | |
| 60 | + public function __construct( $code, $message = null, $feature = null ) { | |
| 61 | + $this->code = $code; | |
| 30 | 62 | $this->message = $message; |
| 63 | + $this->feature = $feature; | |
| 31 | 64 | } |
| 32 | 65 | |
| 33 | 66 | /** |
| 34 | - * Returns the status of a feature | |
| 67 | + * Get the message for the feature requirements status | |
| 35 | 68 | * |
| 36 | - * 0 is no issues | |
| 37 | - * 1 is usable but there are warnngs | |
| 38 | - * 2 is not usable | |
| 69 | + * @return array The message to display | |
| 70 | + * @since 5.3.3 | |
| 71 | + */ | |
| 72 | + public function get_message() { | |
| 73 | + /** | |
| 74 | + * Filter the feature requirements status message | |
| 75 | + * | |
| 76 | + * @hook ep_feature_requirements_status_message | |
| 77 | + * @param {array} $message The message to display | |
| 78 | + * @param {FeatureRequirementsStatus} $status The feature requirements status object | |
| 79 | + * @since 5.3.3 | |
| 80 | + * @return array The message to display | |
| 81 | + */ | |
| 82 | + return apply_filters( 'ep_feature_requirements_status_message', (array) $this->message, $this ); | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Get the code for the feature requirements status | |
| 39 | 87 | * |
| 40 | - * @var int | |
| 41 | - * @since 2.2 | |
| 88 | + * @return int The code to display | |
| 89 | + * @since 5.3.3 | |
| 42 | 90 | */ |
| 43 | - public $code; | |
| 91 | + public function get_code() { | |
| 92 | + /** | |
| 93 | + * Filter the feature requirements status code | |
| 94 | + * | |
| 95 | + * @hook ep_feature_requirements_status_code | |
| 96 | + * @param {int} $code The code to display | |
| 97 | + * @param {FeatureRequirementsStatus} $status The feature requirements status object | |
| 98 | + * @since 5.3.3 | |
| 99 | + * @return int The code to display | |
| 100 | + */ | |
| 101 | + return apply_filters( 'ep_feature_requirements_status_code', (int) $this->code, $this ); | |
| 102 | + } | |
| 44 | 103 | |
| 45 | 104 | /** |
| 46 | - * Optional message to describe status code | |
| 105 | + * Get the feature object | |
| 47 | 106 | * |
| 48 | - * @var string|array | |
| 49 | - * @since 2.2 | |
| 107 | + * @return Feature|null The feature object | |
| 108 | + * @since 5.3.3 | |
| 50 | 109 | */ |
| 51 | - public $message; | |
| 110 | + public function get_feature() { | |
| 111 | + /** | |
| 112 | + * Filter the feature object | |
| 113 | + * | |
| 114 | + * @hook ep_feature_requirements_status_feature | |
| 115 | + * @param {Feature|null} $feature The feature object | |
| 116 | + * @param {FeatureRequirementsStatus} $status The feature requirements status object | |
| 117 | + * @since 5.3.3 | |
| 118 | + * @return Feature|null The feature object | |
| 119 | + */ | |
| 120 | + return apply_filters( 'ep_feature_requirements_status_feature', $this->feature, $this ); | |
| 121 | + } | |
| 52 | 122 | } |