PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/woocommerce/packages/woocommerce-admin/src/Marketing/InstalledExtensions.php

https://gitlab.com/campus-academy/krowkaramel
PHP | 347 lines | 207 code | 74 blank | 66 comment | 45 complexity | 3efb5be50650df032f00423dca997ca4 MD5 | raw file
  1. <?php
  2. /**
  3. * InstalledExtensions class file.
  4. */
  5. namespace Automattic\WooCommerce\Admin\Marketing;
  6. use Automattic\WooCommerce\Admin\Loader;
  7. use Automattic\WooCommerce\Admin\PluginsHelper;
  8. /**
  9. * Installed Marketing Extensions class.
  10. */
  11. class InstalledExtensions {
  12. /**
  13. * Gets an array of plugin data for the "Installed marketing extensions" card.
  14. *
  15. * Valid extensions statuses are: installed, activated, configured
  16. */
  17. public static function get_data() {
  18. $data = [];
  19. $automatewoo = self::get_automatewoo_extension_data();
  20. $mailchimp = self::get_mailchimp_extension_data();
  21. $facebook = self::get_facebook_extension_data();
  22. $pinterest = self::get_pinterest_extension_data();
  23. $google = self::get_google_extension_data();
  24. $hubspot = self::get_hubspot_extension_data();
  25. $amazon_ebay = self::get_amazon_ebay_extension_data();
  26. $mailpoet = self::get_mailpoet_extension_data();
  27. if ( $automatewoo ) {
  28. $data[] = $automatewoo;
  29. }
  30. if ( $mailchimp ) {
  31. $data[] = $mailchimp;
  32. }
  33. if ( $facebook ) {
  34. $data[] = $facebook;
  35. }
  36. if ( $pinterest ) {
  37. $data[] = $pinterest;
  38. }
  39. if ( $google ) {
  40. $data[] = $google;
  41. }
  42. if ( $hubspot ) {
  43. $data[] = $hubspot;
  44. }
  45. if ( $amazon_ebay ) {
  46. $data[] = $amazon_ebay;
  47. }
  48. if ( $mailpoet ) {
  49. $data[] = $mailpoet;
  50. }
  51. return $data;
  52. }
  53. /**
  54. * Get allowed plugins.
  55. *
  56. * @return array
  57. */
  58. public static function get_allowed_plugins() {
  59. return [
  60. 'automatewoo',
  61. 'mailchimp-for-woocommerce',
  62. 'creative-mail-by-constant-contact',
  63. 'facebook-for-woocommerce',
  64. 'pinterest-for-woocommerce',
  65. 'google-listings-and-ads',
  66. 'hubspot-for-woocommerce',
  67. 'woocommerce-amazon-ebay-integration',
  68. 'mailpoet',
  69. ];
  70. }
  71. /**
  72. * Get AutomateWoo extension data.
  73. *
  74. * @return array|bool
  75. */
  76. protected static function get_automatewoo_extension_data() {
  77. $slug = 'automatewoo';
  78. if ( ! PluginsHelper::is_plugin_installed( $slug ) ) {
  79. return false;
  80. }
  81. $data = self::get_extension_base_data( $slug );
  82. $data['icon'] = plugins_url( 'images/marketing/automatewoo.svg', WC_ADMIN_PLUGIN_FILE );
  83. if ( 'activated' === $data['status'] && function_exists( 'AW' ) ) {
  84. $data['settingsUrl'] = admin_url( 'admin.php?page=automatewoo-settings' );
  85. $data['docsUrl'] = 'https://automatewoo.com/docs/';
  86. $data['status'] = 'configured'; // Currently no configuration step.
  87. }
  88. return $data;
  89. }
  90. /**
  91. * Get MailChimp extension data.
  92. *
  93. * @return array|bool
  94. */
  95. protected static function get_mailchimp_extension_data() {
  96. $slug = 'mailchimp-for-woocommerce';
  97. if ( ! PluginsHelper::is_plugin_installed( $slug ) ) {
  98. return false;
  99. }
  100. $data = self::get_extension_base_data( $slug );
  101. $data['icon'] = plugins_url( 'images/marketing/mailchimp.svg', WC_ADMIN_PLUGIN_FILE );
  102. if ( 'activated' === $data['status'] && function_exists( 'mailchimp_is_configured' ) ) {
  103. $data['docsUrl'] = 'https://mailchimp.com/help/connect-or-disconnect-mailchimp-for-woocommerce/';
  104. $data['settingsUrl'] = admin_url( 'admin.php?page=mailchimp-woocommerce' );
  105. if ( mailchimp_is_configured() ) {
  106. $data['status'] = 'configured';
  107. }
  108. }
  109. return $data;
  110. }
  111. /**
  112. * Get Facebook extension data.
  113. *
  114. * @return array|bool
  115. */
  116. protected static function get_facebook_extension_data() {
  117. $slug = 'facebook-for-woocommerce';
  118. if ( ! PluginsHelper::is_plugin_installed( $slug ) ) {
  119. return false;
  120. }
  121. $data = self::get_extension_base_data( $slug );
  122. $data['icon'] = plugins_url( 'images/marketing/facebook.svg', WC_ADMIN_PLUGIN_FILE );
  123. if ( 'activated' === $data['status'] && function_exists( 'facebook_for_woocommerce' ) ) {
  124. $integration = facebook_for_woocommerce()->get_integration();
  125. if ( $integration->is_configured() ) {
  126. $data['status'] = 'configured';
  127. }
  128. $data['settingsUrl'] = facebook_for_woocommerce()->get_settings_url();
  129. $data['docsUrl'] = facebook_for_woocommerce()->get_documentation_url();
  130. }
  131. return $data;
  132. }
  133. /**
  134. * Get Pinterest extension data.
  135. *
  136. * @return array|bool
  137. */
  138. protected static function get_pinterest_extension_data() {
  139. $slug = 'pinterest-for-woocommerce';
  140. if ( ! PluginsHelper::is_plugin_installed( $slug ) ) {
  141. return false;
  142. }
  143. $data = self::get_extension_base_data( $slug );
  144. $data['icon'] = plugins_url( 'images/marketing/pinterest.svg', WC_ADMIN_PLUGIN_FILE );
  145. // TODO: Finalise docs url.
  146. $data['docsUrl'] = 'https://woocommerce.com/document/pinterest-for-woocommerce/?utm_medium=product';
  147. if ( 'activated' === $data['status'] && class_exists( 'Pinterest_For_Woocommerce' ) ) {
  148. $pinterest_onboarding_completed = Pinterest_For_Woocommerce()::is_setup_complete();
  149. if ( $pinterest_onboarding_completed ) {
  150. $data['status'] = 'configured';
  151. $data['settingsUrl'] = admin_url( 'admin.php?page=wc-admin&path=/pinterest/settings' );
  152. } else {
  153. $data['settingsUrl'] = admin_url( 'admin.php?page=wc-admin&path=/pinterest/landing' );
  154. }
  155. }
  156. return $data;
  157. }
  158. /**
  159. * Get Google extension data.
  160. *
  161. * @return array|bool
  162. */
  163. protected static function get_google_extension_data() {
  164. $slug = 'google-listings-and-ads';
  165. if ( ! PluginsHelper::is_plugin_installed( $slug ) ) {
  166. return false;
  167. }
  168. $data = self::get_extension_base_data( $slug );
  169. $data['icon'] = plugins_url( 'images/marketing/google.svg', WC_ADMIN_PLUGIN_FILE );
  170. if ( 'activated' === $data['status'] && function_exists( 'woogle_get_container' ) && class_exists( '\Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\MerchantCenterService' ) ) {
  171. $merchant_center = woogle_get_container()->get( \Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\MerchantCenterService::class );
  172. if ( $merchant_center->is_setup_complete() ) {
  173. $data['status'] = 'configured';
  174. $data['settingsUrl'] = admin_url( 'admin.php?page=wc-admin&path=/google/settings' );
  175. } else {
  176. $data['settingsUrl'] = admin_url( 'admin.php?page=wc-admin&path=/google/start' );
  177. }
  178. $data['docsUrl'] = 'https://woocommerce.com/document/google-listings-and-ads/?utm_medium=product';
  179. }
  180. return $data;
  181. }
  182. /**
  183. * Get Hubspot extension data.
  184. *
  185. * @return array|bool
  186. */
  187. protected static function get_hubspot_extension_data() {
  188. $slug = 'hubspot-for-woocommerce';
  189. if ( ! PluginsHelper::is_plugin_installed( $slug ) ) {
  190. return false;
  191. }
  192. $data = self::get_extension_base_data( $slug );
  193. $data['icon'] = plugins_url( 'images/marketing/hubspot.svg', WC_ADMIN_PLUGIN_FILE );
  194. if ( 'activated' === $data['status'] && class_exists( '\Hubwoo' ) ) {
  195. // Use same check as HubWoo admin.
  196. if ( \Hubwoo::is_setup_completed() ) {
  197. $data['status'] = 'configured';
  198. }
  199. $data['settingsUrl'] = admin_url( 'admin.php?page=hubwoo' );
  200. $data['docsUrl'] = 'https://docs.makewebbetter.com/hubspot-integration-for-woocommerce/';
  201. }
  202. return $data;
  203. }
  204. /**
  205. * Get Amazon / Ebay extension data.
  206. *
  207. * @return array|bool
  208. */
  209. protected static function get_amazon_ebay_extension_data() {
  210. $slug = 'woocommerce-amazon-ebay-integration';
  211. if ( ! PluginsHelper::is_plugin_installed( $slug ) ) {
  212. return false;
  213. }
  214. $data = self::get_extension_base_data( $slug );
  215. $data['icon'] = plugins_url( 'images/marketing/amazon-ebay.svg', WC_ADMIN_PLUGIN_FILE );
  216. if ( 'activated' === $data['status'] && class_exists( '\CodistoConnect' ) ) {
  217. $codisto_merchantid = get_option( 'codisto_merchantid' );
  218. // Use same check as codisto admin tabs.
  219. if ( is_numeric( $codisto_merchantid ) ) {
  220. $data['status'] = 'configured';
  221. }
  222. $data['settingsUrl'] = admin_url( 'admin.php?page=codisto-settings' );
  223. $data['docsUrl'] = 'https://woocommerce.com/document/multichannel-for-woocommerce-google-amazon-ebay-walmart-integration/?utm_medium=product';
  224. }
  225. return $data;
  226. }
  227. /**
  228. * Get MailPoet extension data.
  229. *
  230. * @return array|bool
  231. */
  232. protected static function get_mailpoet_extension_data() {
  233. $slug = 'mailpoet';
  234. if ( ! PluginsHelper::is_plugin_installed( $slug ) ) {
  235. return false;
  236. }
  237. $data = self::get_extension_base_data( $slug );
  238. $data['icon'] = plugins_url( 'images/marketing/mailpoet.svg', WC_ADMIN_PLUGIN_FILE );
  239. if ( 'activated' === $data['status'] && class_exists( '\MailPoet\API\API' ) ) {
  240. $mailpoet_api = \MailPoet\API\API::MP( 'v1' );
  241. if ( ! method_exists( $mailpoet_api, 'isSetupComplete' ) || $mailpoet_api->isSetupComplete() ) {
  242. $data['status'] = 'configured';
  243. $data['settingsUrl'] = admin_url( 'admin.php?page=mailpoet-settings' );
  244. } else {
  245. $data['settingsUrl'] = admin_url( 'admin.php?page=mailpoet-newsletters' );
  246. }
  247. $data['docsUrl'] = 'https://kb.mailpoet.com/';
  248. $data['supportUrl'] = 'https://www.mailpoet.com/support/';
  249. }
  250. return $data;
  251. }
  252. /**
  253. * Get an array of basic data for a given extension.
  254. *
  255. * @param string $slug Plugin slug.
  256. *
  257. * @return array|false
  258. */
  259. protected static function get_extension_base_data( $slug ) {
  260. $status = PluginsHelper::is_plugin_active( $slug ) ? 'activated' : 'installed';
  261. $plugin_data = PluginsHelper::get_plugin_data( $slug );
  262. if ( ! $plugin_data ) {
  263. return false;
  264. }
  265. return [
  266. 'slug' => $slug,
  267. 'status' => $status,
  268. 'name' => $plugin_data['Name'],
  269. 'description' => html_entity_decode( wp_trim_words( $plugin_data['Description'], 20 ) ),
  270. 'supportUrl' => 'https://woocommerce.com/my-account/create-a-ticket/?utm_medium=product',
  271. ];
  272. }
  273. }