PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / app / Shared / Services / PluginDependencies / SimplyBook.php

SimplyBook.php in Extendify 3.2.1, at app/Shared/Services/PluginDependencies/SimplyBook.php

83 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * SimplyBook pattern replacement.
5 */
6
7 namespace Extendify\Shared\Services\PluginDependencies;
8
9 use Extendify\Constants;
10 use Extendify\PartnerData;
11 use Extendify\Shared\Services\HttpClient;
12 use Extendify\Shared\Services\Sanitizer;
13
14 defined('ABSPATH') || die('No direct access.');
15
16 /**
17 * SimplyBook pattern replacement class.
18 */
19
20 class SimplyBook
21 {
22 /**
23 * The plugin slug.
24 *
25 * @var string
26 */
27 public static $slug = 'simplybook/simplybook.php';
28
29 /**
30 * Replace the placeholder for SimplyBook.
31 *
32 * @param mixed $code - The code data.
33 * @param string $key - The plugin key.
34 * @param string $newCode - The plugin pattern code.
35 * @return mixed
36 */
37 public static function create($code, $key, $newCode)
38 {
39 if ($key !== 'simple' || !preg_match('/\[simplybook_widget\]|wp:simplybook\/widget/m', $newCode)) {
40 return $code;
41 }
42
43 require_once ABSPATH . 'wp-admin/includes/plugin.php';
44
45 // If the plugin is already installed and active, we don't need to install it again.
46 if (!is_plugin_active(self::$slug)) {
47 $response = PluginInstaller::installPlugin('simplybook', self::$slug);
48 if (is_wp_error($response)) {
49 return $response;
50 }
51 }
52
53 return $newCode;
54 }
55
56 public static function getIndustryCode()
57 {
58 if (!empty(\get_option('extendify_simplybook_data', []))) {
59 return;
60 }
61
62 $response = HttpClient::post(Constants::AI_HOST . '/api/plugins/simplybook', [
63 'params' => [
64 'title' => \get_bloginfo('name'),
65 'wpLanguage' => \get_locale(),
66 'version' => \Extendify\Config::$version,
67 'siteProfile' => \get_option('extendify_site_profile', []),
68 'siteId' => \get_option('extendify_site_id', ''),
69 'partnerId' => PartnerData::$id,
70 'devbuild' => (bool) is_readable(EXTENDIFY_PATH . '.devbuild'),
71 ]
72 ], null, true);
73
74 if (empty($response['response'])) {
75 return;
76 }
77
78 \update_option('extendify_simplybook_data', Sanitizer::sanitizeUnknown($response['response'] ?? []), false);
79
80 return;
81 }
82 }
83