Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| HelpCenterFeatureHooks | |
0.00% |
0 / 16 |
|
0.00% |
0 / 4 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| hooks | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| filterValue | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| shouldDisable | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | namespace NewfoldLabs\WP\Module\HelpCenter; |
| 3 | |
| 4 | use NewfoldLabs\WP\Module\Data\SiteCapabilities; |
| 5 | |
| 6 | /** |
| 7 | * This class adds helpCenter feature hooks. |
| 8 | **/ |
| 9 | class HelpCenterFeatureHooks { |
| 10 | |
| 11 | /** |
| 12 | * Constructor. |
| 13 | */ |
| 14 | public function __construct() { |
| 15 | // set constant |
| 16 | if ( ! defined( 'USER_INTERACTION_SERVICE_BASE' ) ) { |
| 17 | define( 'USER_INTERACTION_SERVICE_BASE', 'https://hiive.cloud/workers/ai-proxy/' ); |
| 18 | } |
| 19 | |
| 20 | if ( function_exists( 'add_action' ) ) { |
| 21 | add_action( 'plugins_loaded', array( $this, 'hooks' ) ); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Add hooks. |
| 27 | */ |
| 28 | public function hooks() { |
| 29 | // add filter so we don't show/load help during onboarding |
| 30 | add_filter( 'newfold/features/filter/isEnabled:helpCenter', array( $this, 'filterValue' ) ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Feature filter based on capabilities. |
| 35 | * |
| 36 | * @param boolean $value the value |
| 37 | * @return boolean the filtered value |
| 38 | */ |
| 39 | public function filterValue( $value ) { |
| 40 | if ( $this->shouldDisable() ) { |
| 41 | $value = false; |
| 42 | } |
| 43 | return $value; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Context condition for disabling feature. |
| 48 | * |
| 49 | * @return boolean whether the feature should be disabled |
| 50 | */ |
| 51 | public function shouldDisable() { |
| 52 | // Do not load Help Center when in Onboarding (Onboarding has no admin bar to toggle this). |
| 53 | $isOnboarding = isset( $_GET['page'] ) && 'nfd-onboarding' === sanitize_text_field( $_GET['page'] ); |
| 54 | if ( $isOnboarding ) { |
| 55 | return true; |
| 56 | } |
| 57 | // Do not load if `canAccessHelpCenter` capability is not true |
| 58 | $capabilities = new SiteCapabilities(); |
| 59 | $hasCapability = $capabilities->get( 'canAccessHelpCenter' ); |
| 60 | if ( ! $hasCapability ) { |
| 61 | return true; |
| 62 | } |
| 63 | return false; |
| 64 | } |
| 65 | } |