Nessuna descrizione

class-jetpack-crm-data.php 2.3KB

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