Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| HelpCenterFeature | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| initialize | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| canToggle | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace NewfoldLabs\WP\Module\HelpCenter; |
| 4 | |
| 5 | use NewfoldLabs\WP\Module\HelpCenter\HelpCenter; |
| 6 | use NewfoldLabs\WP\Module\HelpCenter\Data\Brands; |
| 7 | use NewfoldLabs\WP\Module\Data\SiteCapabilities; |
| 8 | |
| 9 | use function NewfoldLabs\WP\ModuleLoader\container as getContainer; |
| 10 | |
| 11 | /** |
| 12 | * Child class for a feature |
| 13 | * |
| 14 | * Child classes should define a name property as the feature name for all API calls. This name will be used in the registry. |
| 15 | * Child class naming convention is {FeatureName}Feature. |
| 16 | */ |
| 17 | class HelpCenterFeature extends \NewfoldLabs\WP\Module\Features\Feature { |
| 18 | /** |
| 19 | * The feature name. |
| 20 | * |
| 21 | * @var string |
| 22 | */ |
| 23 | protected $name = 'helpCenter'; |
| 24 | |
| 25 | /** |
| 26 | * The feature value. Defaults to on. |
| 27 | * |
| 28 | * @var boolean |
| 29 | */ |
| 30 | protected $value = true; |
| 31 | |
| 32 | /** |
| 33 | * Initialize staging feature. |
| 34 | */ |
| 35 | public function initialize() { |
| 36 | if ( function_exists( 'add_action' ) ) { |
| 37 | |
| 38 | // Register module |
| 39 | add_action( |
| 40 | 'plugins_loaded', |
| 41 | function () { |
| 42 | $container = getContainer(); |
| 43 | define( 'NFD_HELPCENTER_PLUGIN_DIRNAME', dirname( $container->plugin()->basename ) ); |
| 44 | define( 'NFD_HELPCENTER_PLUGIN_URL', $container->plugin()->url ); |
| 45 | new HelpCenter( $container ); |
| 46 | // Define the brand |
| 47 | Brands::set_current_brand( $container ); |
| 48 | } |
| 49 | ); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Checks for capability and if user has permissions to toggle. |
| 55 | * |
| 56 | * @return bool True if the feature toggle is allowed, false otherwise. |
| 57 | */ |
| 58 | public function canToggle() { |
| 59 | $capabilies = new SiteCapabilities(); |
| 60 | $hasCapability = $capabilies->get( 'canAccessHelpCenter' ); |
| 61 | $canManageOptions = current_user_can( 'manage_options' ); |
| 62 | return (bool) $hasCapability && $canManageOptions; |
| 63 | } |
| 64 | } |