PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 15.0
Jetpack – WP Security, Backup, Speed, & Growth v15.0
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / src / class-jetpack-crm-data.php
class-jetpack-crm-data.php
80 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }
80