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