Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_CRM_Data | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
110 | |
0.00% |
0 / 1 |
| get_crm_data | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
72 | |||
| activate_crm_jetpackforms_extension | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Compatibility functions for the Jetpack CRM plugin. |
| 4 | * |
| 5 | * @since 9.0.0 |
| 6 | * |
| 7 | * @package automattic/jetpack |
| 8 | */ |
| 9 | |
| 10 | namespace Automattic\Jetpack; |
| 11 | |
| 12 | use WP_Error; |
| 13 | |
| 14 | /** |
| 15 | * Provides Jetpack CRM plugin data. |
| 16 | */ |
| 17 | class Jetpack_CRM_Data { |
| 18 | |
| 19 | const JETPACK_CRM_PLUGIN_SLUG = 'zero-bs-crm/ZeroBSCRM.php'; |
| 20 | |
| 21 | /** |
| 22 | * Provides Jetpack CRM plugin data for use in the Contact Form block sidebar menu. |
| 23 | * |
| 24 | * @return array An array containing the Jetpack CRM plugin data. |
| 25 | */ |
| 26 | public function get_crm_data() { |
| 27 | $plugins = Plugins_Installer::get_plugins(); |
| 28 | |
| 29 | // Set default values. |
| 30 | $response = array( |
| 31 | 'crm_installed' => false, |
| 32 | 'crm_active' => false, |
| 33 | 'crm_version' => null, |
| 34 | 'jp_form_ext_enabled' => null, |
| 35 | 'can_install_crm' => false, |
| 36 | 'can_activate_crm' => false, |
| 37 | 'can_activate_extension' => false, |
| 38 | ); |
| 39 | |
| 40 | if ( isset( $plugins[ self::JETPACK_CRM_PLUGIN_SLUG ] ) ) { |
| 41 | $response['crm_installed'] = true; |
| 42 | |
| 43 | $crm_data = $plugins[ self::JETPACK_CRM_PLUGIN_SLUG ]; |
| 44 | |
| 45 | $response['crm_active'] = $crm_data['active']; |
| 46 | $response['crm_version'] = $crm_data['Version']; |
| 47 | |
| 48 | if ( $response['crm_active'] ) { |
| 49 | if ( function_exists( 'zeroBSCRM_isExtensionInstalled' ) ) { |
| 50 | $response['jp_form_ext_enabled'] = zeroBSCRM_isExtensionInstalled( 'jetpackforms' ); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | $response['can_install_crm'] = $response['crm_installed'] ? false : current_user_can( 'install_plugins' ); |
| 56 | $response['can_activate_crm'] = $response['crm_active'] ? false : current_user_can( 'activate_plugins' ); |
| 57 | |
| 58 | if ( $response['crm_active'] && function_exists( 'zeroBSCRM_extension_install_jetpackforms' ) ) { |
| 59 | // phpcs:ignore WordPress.WP.Capabilities.Unknown |
| 60 | $response['can_activate_extension'] = current_user_can( 'admin_zerobs_manage_options' ); |
| 61 | } |
| 62 | |
| 63 | return $response; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Activates Jetpack CRM's Jetpack Forms extension. This is used by a button in the Jetpack Contact Form |
| 68 | * sidebar menu. |
| 69 | * |
| 70 | * @return true|WP_Error Returns true if activation is success, else returns a WP_Error object. |
| 71 | */ |
| 72 | public function activate_crm_jetpackforms_extension() { |
| 73 | if ( function_exists( 'zeroBSCRM_extension_install_jetpackforms' ) ) { |
| 74 | return zeroBSCRM_extension_install_jetpackforms(); |
| 75 | } |
| 76 | |
| 77 | return new WP_Error( 'jp_forms_extension_activation_failed', esc_html__( 'The Jetpack Forms extension could not be activated.', 'jetpack' ) ); |
| 78 | } |
| 79 | } |